[polari/wip/raresv/userTracker] saved as proof of concept, still needs some work to it
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/raresv/userTracker] saved as proof of concept, still needs some work to it
- Date: Tue, 5 Jul 2016 19:46:54 +0000 (UTC)
commit dc69d78e22e157887123f468d00fc62b5f0888c4
Author: raresv <rares visalom gmail com>
Date: Tue Jul 5 01:09:28 2016 +0300
saved as proof of concept, still needs some work to it
src/chatView.js | 2 ++
src/userTracker.js | 38 ++++++++++++++++++++++++++++++++++----
2 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 8eccfce..9bdcb69 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -14,6 +14,7 @@ const Mainloop = imports.mainloop;
const PasteManager = imports.pasteManager;
const Signals = imports.signals;
const Utils = imports.utils;
+const UserTracker = imports.userTracker;
const MAX_NICK_CHARS = 8;
const IGNORE_STATUS_TIME = 5;
@@ -287,6 +288,7 @@ const ChatView = new Lang.Class({
this._pending = {};
this._pendingLogs = [];
this._statusCount = { left: 0, joined: 0, total: 0 };
+ this._userStatusMonitor = UserTracker.getUserStatusMonitor();
this._room.account.connect('notify::nickname', Lang.bind(this,
function() {
diff --git a/src/userTracker.js b/src/userTracker.js
index 77b9e18..42432f4 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -50,6 +50,20 @@ const UserStatusMonitor = new Lang.Class({
getUserTrackerForAccount: function(account) {
if (this._userTrackersMaping.has(account))
return this._userTrackersMaping.get(account);
+ return null;
+ },
+
+ watchUser: function(room, nickName, callback) {
+ let baseNick = Polari.util_get_basenick(nickName);
+ let contactList =
this.getUserTrackerForAccount(room.account)._roomMapping.get(room)._contactMapping.get(baseNick) || [];
+
+ for (let i = 0; i < contactList.length; i++) {
+ if (nickName == contactList[i].alias) {
+ contactList[i]._onStatusChangedCallback = callback;
+
+ contactList[i]._onStatusChangedCallback(nickName, Tp.ConnectionPresenceType.AVAILABLE);
+ }
+ }
}
});
@@ -80,6 +94,8 @@ const UserTracker = new Lang.Class({
this._globalContactMapping = new Map();
this._roomMapping = new Map();
+ this._userStatusMonitor = getUserStatusMonitor();
+
this._chatroomManager = ChatroomManager.getDefault();
this._chatroomManager.connect('room-added', Lang.bind(this, this._onRoomAdded));
this._chatroomManager.connect('room-removed', Lang.bind(this, this._onRoomRemoved));
@@ -135,6 +151,8 @@ const UserTracker = new Lang.Class({
m._room = emittingRoom;
this._trackMember(this._roomMapping.get(emittingRoom)._contactMapping, m);
this._trackMember(this._globalContactMapping, m);
+
+ this._userStatusMonitor.watchUser(emittingRoom, m.alias, Lang.bind(this,
this._onLocalStatusChanged));
});
} else {
/*handle the absence of a channel for the global case*/
@@ -168,6 +186,8 @@ const UserTracker = new Lang.Class({
this._untrackMember(this._globalContactMapping, oldMember);
this._trackMember(this._roomMapping.get(room)._contactMapping, newMember);
this._trackMember(this._globalContactMapping, newMember);
+
+ this._userStatusMonitor.watchUser(room, newMember.alias, Lang.bind(this,
this._onLocalStatusChanged));
},
_onMemberDisconnected: function(room, member, message) {
@@ -196,6 +216,8 @@ const UserTracker = new Lang.Class({
this._trackMember(this._roomMapping.get(room)._contactMapping, member);
this._trackMember(this._globalContactMapping, member);
+
+ this._userStatusMonitor.watchUser(room, member.alias, Lang.bind(this, this._onLocalStatusChanged));
},
_onMemberLeft: function(room, member, message) {
@@ -215,7 +237,7 @@ const UserTracker = new Lang.Class({
if (map.get(baseNick).length == 1)
if (map == this._globalContactMapping)
- log("[Global UserTracker] User " + member.alias + " is now globally available on " +
this._account.get_display_name());
+ this.emit("global-status-changed::" + member.alias, Tp.ConnectionPresenceType.AVAILABLE);
else
log("[Local UserTracker] User " + member.alias + " is now available in room " +
member._room.channelName + " on " + this._account.get_display_name());
},
@@ -228,16 +250,24 @@ const UserTracker = new Lang.Class({
let indexToDelete = contacts.map(c => c.alias + "|" + c._room.channelName).indexOf(member.alias +
"|" + member._room.channelName);
if (indexToDelete > -1) {
- contacts.splice(indexToDelete, 1);
+ let removedMember = contacts.splice(indexToDelete, 1)[0];
if (contacts.length == 0)
if (map == this._globalContactMapping)
- log("[Global UserTracker] User " + member.alias + " is now globally offline on " +
this._account.get_display_name());
+ this.emit("global-status-changed::" + member.alias, Tp.ConnectionPresenceType.OFFLINE);
else
- log("[Local UserTracker] User " + member.alias + " is now offline in room " +
member._room.channelName + " on " + this._account.get_display_name());
+ //log("[Local UserTracker] User " + member.alias + " is now offline in room " +
member._room.channelName + " on " + this._account.get_display_name());
+ if (removedMember._onStatusChangedCallback)
+ removedMember._onStatusChangedCallback(member.alias,
Tp.ConnectionPresenceType.OFFLINE);
+ else
+ log("does not have callback");
}
},
+ _onLocalStatusChanged: function(nickName, status) {
+ log("LOCAL STATUS CHANGED FOR " + nickName + " to " + status);
+ },
+
getNickGlobalStatus: function(nickName) {
let baseNick = Polari.util_get_basenick(nickName);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]