[polari] Use new PolariRoom properties



commit e890b3224796eefcb432354e1e619506cad74109
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Dec 5 16:43:10 2013 +0000

    Use new PolariRoom properties
    
    In preparation of supporting offline rooms, replace simple accesses
    to PolariRoom:channel with the newly added :account, :type and
    :channel-name properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710271

 src/application.js    |    5 ++---
 src/chatView.js       |   11 +++++------
 src/entryArea.js      |    2 +-
 src/ircParser.js      |   11 ++++-------
 src/lib/polari-room.c |   43 ++++++++++---------------------------------
 src/roomList.js       |    2 +-
 src/userList.js       |    2 +-
 7 files changed, 24 insertions(+), 52 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ae418a2..88f660b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -190,7 +190,7 @@ const Application = new Lang.Class({
 
     _updateUserListAction: function(action) {
         let room = this._chatroomManager.getActiveRoom();
-        action.enabled = room && room.channel.handle_type == Tp.HandleType.ROOM;
+        action.enabled = room && room.type == Tp.HandleType.ROOM;
     },
 
     _userListCreateHook: function(action) {
@@ -368,8 +368,7 @@ const Application = new Lang.Class({
                     logError(e, 'Failed to leave channel');
                 }
             }));
-        this._removeSavedChannel(room.channel.connection.get_account(),
-                                 room.channel.identifier);
+        this._removeSavedChannel(room.account, room.channel_name);
     },
 
     _onLeaveCurrentRoom: function() {
diff --git a/src/chatView.js b/src/chatView.js
index 5d530ab..c59ae85 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -92,14 +92,13 @@ const ChatView = new Lang.Class({
         this._pending = {};
         this._pendingLogs = [];
 
-        let isRoom = room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP);
-        let account = room.channel.connection.get_account();
+        let isRoom = room.type == Tp.HandleType.ROOM;
         let target = new Tpl.Entity({ type: isRoom ? Tpl.EntityType.ROOM
                                                    : Tpl.EntityType.CONTACT,
-                                      identifier: room.channel.identifier });
+                                      identifier: room.channel_name });
         let logManager = Tpl.LogManager.dup_singleton();
         this._logWalker =
-            logManager.walk_filtered_events(account, target,
+            logManager.walk_filtered_events(room.account, target,
                                             Tpl.EventTypeMask.TEXT, null);
 
         this._fetchingBacklog = true;
@@ -576,10 +575,10 @@ const ChatView = new Lang.Class({
             let summary = '%s %s'.format(this._room.display_name, message.nick);
             let notification = new Notify.Notification(summary, message.text);
 
-            let account = this._room.channel.connection.get_account();
+            let account = this._room.account;
             let param = GLib.Variant.new('(ssu)',
                                          [ account.get_object_path(),
-                                           this._room.channel.identifier,
+                                           this._room.channel_name,
                                            TP_CURRENT_TIME ]);
             notification.addAction('default', 'default');
             notification.connect('action-invoked', function() {
diff --git a/src/entryArea.js b/src/entryArea.js
index d160d26..afe3705 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -131,7 +131,7 @@ const EntryArea = new Lang.Class({
         this._nickEntry.width_chars = Math.max(nick.length, ChatView.MAX_NICK_CHARS)
         this._nickEntry.placeholder_text = nick;
 
-        let account = this._room.channel.connection.get_account();
+        let account = this._room.account;
         account.set_nickname_async(nick, Lang.bind(this,
             function(a, res) {
                 try {
diff --git a/src/ircParser.js b/src/ircParser.js
index 63bba71..88631e6 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -137,8 +137,7 @@ const IrcParser = new Lang.Class({
                 if (argv.length)
                     log('Excess arguments to JOIN command: ' + argv);
 
-                let account = this._room.channel.connection.get_account();
-
+                let account = this._room.account;
                 let app = Gio.Application.get_default();
                 let action = app.lookup_action('join-room');
                 action.activate(GLib.Variant.new('(ssu)',
@@ -194,8 +193,7 @@ const IrcParser = new Lang.Class({
                 if (argv.length)
                     log('Excess arguments to NICK command: ' + argv);
 
-                let account = this._room.channel.connection.get_account();
-                account.set_nickname_async(nick, Lang.bind(this,
+                this._room.account.set_nickname_async(nick, Lang.bind(this,
                     function(a, res) {
                         try {
                             a.set_nickname_finish(res);
@@ -228,7 +226,7 @@ const IrcParser = new Lang.Class({
                     break;
                 }
 
-                let account = this._room.channel.connection.get_account();
+                let account = this._room.account;
 
                 let app = Gio.Application.get_default();
                 let action = app.lookup_action('message-user');
@@ -239,10 +237,9 @@ const IrcParser = new Lang.Class({
                 break;
             }
             case 'QUIT': {
-                let account = this._room.channel.connection.get_account();
                 let presence = Tp.ConnectionPresenceType.OFFLINE;
                 let message = stripCommand(text);
-                account.request_presence_async(presence, '', message,
+                this._room.account.request_presence_async(presence, '', message,
                     Lang.bind(this, function(a, res) {
                         try {
                             a.request_presence_finish(res);
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index d2ae5d9..a1da14a 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -35,7 +35,6 @@ struct _PolariRoomPrivate {
   TpHandleType type;
 
   guint self_contact_notify_id;
-  guint identifier_notify_id;
   guint group_contacts_changed_id;
 
   TpProxySignalConnection *properties_changed_id;
@@ -176,27 +175,19 @@ polari_room_compare (PolariRoom *room,
                      PolariRoom *other)
 {
   TpAccount *account1, *account2;
-  TpHandleType type1, type2;
-  TpConnection *conn;
 
   g_return_val_if_fail (POLARI_IS_ROOM (room) && POLARI_IS_ROOM (other), 0);
-  g_return_val_if_fail (room->priv->channel && other->priv->channel, 0);
-
-  conn = tp_channel_get_connection (room->priv->channel);
-  account1 = tp_connection_get_account (conn);
+  g_return_val_if_fail (room->priv->account && other->priv->account, 0);
 
-  conn = tp_channel_get_connection (other->priv->channel);
-  account2 = tp_connection_get_account (conn);
+  account1 = room->priv->account;
+  account2 = other->priv->account;
 
   if (account1 != account2)
     return strcmp (tp_account_get_display_name (account1),
                    tp_account_get_display_name (account2));
 
-  tp_channel_get_handle (room->priv->channel, &type1);
-  tp_channel_get_handle (other->priv->channel, &type2);
-
-  if (type1 != type2)
-    return type1 == TP_HANDLE_TYPE_ROOM ? -1 : 1;
+  if (room->priv->type != other->priv->type)
+    return room->priv->type == TP_HANDLE_TYPE_ROOM ? -1 : 1;
 
   return strcmp (room->priv->display_name, other->priv->display_name);
 }
@@ -238,14 +229,11 @@ static void
 update_identifier (PolariRoom *room)
 {
   PolariRoomPrivate *priv = room->priv;
-  const char *id = NULL;
-
-  if (priv->channel)
-    id = tp_channel_get_identifier (priv->channel);
 
   g_clear_pointer (&priv->display_name, g_free);
-  if (id)
-    priv->display_name = g_strdup (id + (id[0] == '#' ? 1 : 0));
+  if (priv->channel_name)
+    priv->display_name = g_strdup (priv->channel_name +
+                                   (priv->channel_name[0] == '#' ? 1 : 0));
 
   g_object_notify_by_pspec (G_OBJECT (room), props[PROP_DISPLAY_NAME]);
 }
@@ -274,14 +262,6 @@ on_self_contact_notify (GObject    *object,
 }
 
 static void
-on_identifier_notify (GObject    *object,
-                      GParamSpec *pspec,
-                      gpointer    user_data)
-{
-  update_identifier (POLARI_ROOM (user_data));
-}
-
-static void
 on_group_contacts_changed (TpChannel  *channel,
                            GPtrArray  *added,
                            GPtrArray  *removed,
@@ -435,6 +415,8 @@ polari_room_set_channel_name (PolariRoom *room,
     g_free (priv->channel_name);
   priv->channel_name = g_strdup (channel_name);
 
+  update_identifier (room);
+
   g_object_notify_by_pspec (G_OBJECT (room), props[PROP_CHANNEL_NAME]);
 }
 
@@ -454,7 +436,6 @@ polari_room_set_channel (PolariRoom *room,
 
   if (priv->channel)
     {
-      g_signal_handler_disconnect (priv->channel, priv->identifier_notify_id);
       g_signal_handler_disconnect (priv->channel, priv->group_contacts_changed_id);
       g_signal_handler_disconnect (tp_channel_get_connection (priv->channel),
                                    priv->self_contact_notify_id);
@@ -489,9 +470,6 @@ polari_room_set_channel (PolariRoom *room,
         g_signal_connect (tp_channel_get_connection (channel),
                           "notify::self-contact",
                           G_CALLBACK (on_self_contact_notify), room);
-      priv->identifier_notify_id =
-        g_signal_connect (channel, "notify::identifier",
-                          G_CALLBACK (on_identifier_notify), room);
       priv->group_contacts_changed_id =
         g_signal_connect (channel, "group-contacts-changed",
                           G_CALLBACK (on_group_contacts_changed), room);
@@ -511,7 +489,6 @@ polari_room_set_channel (PolariRoom *room,
   g_object_freeze_notify (G_OBJECT (room));
 
   update_self_nick (room);
-  update_identifier (room);
   update_icon (room);
 
   g_object_notify_by_pspec (G_OBJECT (room), props[PROP_CHANNEL]);
diff --git a/src/roomList.js b/src/roomList.js
index d6ee11d..c5c841d 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -308,7 +308,7 @@ const RoomList = new Lang.Class({
 
     _updateHeader: function(row, before) {
         let getAccount = function(row) {
-            return row ? row.room.channel.connection.get_account() : null;
+            return row ? row.room.account : null;
         };
         let beforeAccount = getAccount(before);
         let account = getAccount(row);
diff --git a/src/userList.js b/src/userList.js
index a002fef..a6a259a 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -62,7 +62,7 @@ const UserListSidebar = new Lang.Class({
     },
 
     _roomAdded: function(roomManager, room) {
-        if (room.channel.handle_type != Tp.HandleType.ROOM)
+        if (room.type != Tp.HandleType.ROOM)
             return;
 
         let userList = new UserList(room);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]