[polari/wip/raresv/userTracker] does this work? userTracker part 6
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/raresv/userTracker] does this work? userTracker part 6
- Date: Thu, 30 Jun 2016 12:48:29 +0000 (UTC)
commit 403bad7ea8931613b3022e9a0af1cd991be14b8c
Author: raresv <rares visalom gmail com>
Date: Thu Jun 30 15:48:08 2016 +0300
does this work? userTracker part 6
src/application.js | 7 ++++++
src/userTracker.js | 56 ++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 51 insertions(+), 12 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index a7dbd0d..ccc6641 100644
--- a/src/application.js
+++ b/src/application.js
@@ -13,6 +13,7 @@ const MainWindow = imports.mainWindow;
const PasteManager = imports.pasteManager;
const Utils = imports.utils;
const NetworksManager = imports.networksManager;
+const UserTracker = imports.userTracker;
const MAX_RETRIES = 3;
@@ -48,6 +49,12 @@ const Application = new Lang.Class({
this._accountsMonitor = AccountsMonitor.getDefault();
this._networkMonitor = Gio.NetworkMonitor.get_default();
this._networksManager = NetworksManager.getDefault();
+ /*created here as i couldn't make it work if it was created in the chatroomManager
+ (it didn't receive the room-added signal for the channels restored from the previous session)*/
+ this._globalUserTracker = new UserTracker.UserTracker(null);
+ this._globalUserTracker.connect('status-changed', Lang.bind(this, function(tracker, nick, status){
+ log("[Application] nick " + nick + " global status changed to " + status );
+ }));
this._accountsMonitor.connect('account-removed', Lang.bind(this,
function(am, account) {
diff --git a/src/userTracker.js b/src/userTracker.js
index 258a3a8..42dfe89 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -2,27 +2,59 @@ const Polari = imports.gi.Polari;
const Lang = imports.lang;
const Tp = imports.gi.TelepathyGLib;
const Signals = imports.signals;
+const ChatroomManager = imports.chatroomManager;
const UserTracker = new Lang.Class({
Name: 'UserTracker',
_init: function(room) {
- if (!room)
- throw new Error('UserTracker instance has no specified room!');
-
- this._contactMapping = new Map();
- this._room = room;
-
- this._room.connect('notify::channel', Lang.bind(this, this._onChannelChanged));
- this._room.connect('member-renamed', Lang.bind(this, this._onMemberRenamed));
- this._room.connect('member-disconnected', Lang.bind(this, this._onMemberDisconnected));
- this._room.connect('member-kicked', Lang.bind(this, this._onMemberKicked));
- this._room.connect('member-banned', Lang.bind(this, this._onMemberBanned));
- this._room.connect('member-joined', Lang.bind(this, this._onMemberJoined));
- this._room.connect('member-left', Lang.bind(this, this._onMemberLeft));
+ /*is this 'split' ok?*/
+ if (room == null) {
+ //throw new Error('UserTracker instance has no specified room!');
+ //global case
+ log("global user tracker created");
+ this._contactMapping = new Map();
+ this._chatroomManager = ChatroomManager.getDefault();
+
+ /*room-removed was not yet implemented*/
+ this._chatroomManager.connect('room-added', Lang.bind(this, this._onRoomAdded));
+ } else {
+ this._contactMapping = new Map();
+ this._room = room;
+
+ this._room.connect('notify::channel', Lang.bind(this, this._onChannelChanged));
+ this._room.connect('member-renamed', Lang.bind(this, this._onMemberRenamed));
+ this._room.connect('member-disconnected', Lang.bind(this, this._onMemberDisconnected));
+ this._room.connect('member-kicked', Lang.bind(this, this._onMemberKicked));
+ this._room.connect('member-banned', Lang.bind(this, this._onMemberBanned));
+ this._room.connect('member-joined', Lang.bind(this, this._onMemberJoined));
+ this._room.connect('member-left', Lang.bind(this, this._onMemberLeft));
+
+ this._onChannelChanged();
+ }
+ },
- this._onChannelChanged();
+ _onRoomAdded: function(roomManager , room) {
+ log("[UserTracker] global room added signal handled for room " + room.channelName);
+
+ room.connect('notify::channel', Lang.bind(this, function(){
+ log("[UserTracker] globally tracked room channel changed for room " + room.channelName);
+
+ /*different handler for the notify::channel signal*/
+ room.connect('notify::channel', Lang.bind(this, function(){
+ log("[UserTracker] channel changed for globally tracker room " + room.channelName);
+ }));
+
+ /*here we use the same handlers for both local and global UserTracker
+ is it safe?*/
+ room.connect('member-renamed', Lang.bind(this, this._onMemberRenamed));
+ room.connect('member-disconnected', Lang.bind(this, this._onMemberDisconnected));
+ room.connect('member-kicked', Lang.bind(this, this._onMemberKicked));
+ room.connect('member-banned', Lang.bind(this, this._onMemberBanned));
+ room.connect('member-joined', Lang.bind(this, this._onMemberJoined));
+ room.connect('member-left', Lang.bind(this, this._onMemberLeft));
+ }));
},
_onChannelChanged: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]