[polari] ChatroomManager: don't use two simple clients



commit be9295f43d850ed4a398e9ce68da52b556ee50ef
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Feb 2 01:15:05 2014 +0100

    ChatroomManager: don't use two simple clients
    
    What we want is one client that is both an observer and a handler.
    We can't obtain that result with the simple classes, but we can
    easily subclass TpBaseClient from gjs and implement both virtual functions.
    This way, we only claim one name on the bus, and we only expose
    one client path, which helps mission-control in routing messages
    appropriately.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723440

 src/chatroomManager.js |   45 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 32 insertions(+), 13 deletions(-)
---
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 8a2b0ca..3f82d50 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -14,6 +14,30 @@ function getDefault() {
     return _singleton;
 }
 
+const Client = new Lang.Class({
+    Name: 'Client',
+    GTypeName: 'PolariTpClient',
+    Extends: Tp.BaseClient,
+
+    _init: function(am, manager) {
+        this.parent({ account_manager: am,
+                      name: 'Polari',
+                      uniquify_name: false });
+        this.set_handler_bypass_approval(false);
+        this.set_observer_recover(true);
+
+        this._manager = manager;
+    },
+
+    vfunc_observe_channels: function() {
+        this._manager.observeChannels.apply(this._manager, arguments);
+    },
+
+    vfunc_handle_channels: function() {
+        this._manager.handleChannels.apply(this._manager, arguments);
+    }
+});
+
 const _ChatroomManager = new Lang.Class({
     Name: '_ChatroomManager',
 
@@ -51,11 +75,7 @@ const _ChatroomManager = new Lang.Class({
         let leaveAction = this._app.lookup_action('leave-room');
         leaveAction.connect('activate', Lang.bind(this, this._onLeaveActivated));
 
-        this._observer = Tp.SimpleObserver.new_with_am(am, true,
-            'Polari', true, Lang.bind(this, this._observeChannels));
-
-        this._handler = Tp.SimpleHandler.new_with_am(am, false,
-            false, 'Polari', false, Lang.bind(this, this._handleChannels));
+        this._client = new Client(am, this);
 
         let filters = [];
 
@@ -71,11 +91,10 @@ const _ChatroomManager = new Lang.Class({
 
         filters.forEach(Lang.bind(this,
             function(f) {
-                this._handler.add_handler_filter(f);
-                this._observer.add_observer_filter(f);
+                this._client.add_handler_filter(f);
+                this._client.add_observer_filter(f);
             }));
-        this._handler.register();
-        this._observer.register();
+        this._client.register();
 
         am.connect('account-enabled',
                    Lang.bind(this, this._restoreSavedChannels));
@@ -186,8 +205,8 @@ const _ChatroomManager = new Lang.Class({
         context.accept();
     },
 
-    _observeChannels: function() {
-        let [observer, account, connection,
+    observeChannels: function() {
+        let [account, connection,
              channels, op, requests, context] = arguments;
 
         this._processRequest(context, connection, channels, Lang.bind(this,
@@ -206,8 +225,8 @@ const _ChatroomManager = new Lang.Class({
             }));
     },
 
-    _handleChannels: function() {
-        let [handler, account, connection,
+    handleChannels: function() {
+        let [account, connection,
              channels, satisfied, userTime, context] = arguments;
 
         let [present, time] = Tp.user_action_time_should_present(userTime);


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