[polari/wip/raresv/userTracker] added UserTracker class
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/raresv/userTracker] added UserTracker class
- Date: Mon, 27 Jun 2016 11:13:48 +0000 (UTC)
commit c8b34b4fc1c13807920a8ca4e3a4c3a0ad69f9a8
Author: raresv <rares visalom gmail com>
Date: Mon Jun 27 14:12:46 2016 +0300
added UserTracker class
src/chatView.js | 6 ++
src/org.gnome.Polari.src.gresource.xml | 1 +
src/userTracker.js | 148 ++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+), 0 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index a789070..df513a4 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;
@@ -339,6 +340,11 @@ const ChatView = new Lang.Class({
this._roomSignals.push(room.connect(signal.name, signal.handler));
}));
this._onChannelChanged();
+
+ this._userTracker = new UserTracker.UserTracker({ room: this._room });
+ this._userTracker.connect('status-changed', Lang.bind(this, function(tracker, nick, room, status){
+ log("status-changed signal received in chatView. User " + nick + " has status: " + status);
+ }));
},
_createTags: function() {
diff --git a/src/org.gnome.Polari.src.gresource.xml b/src/org.gnome.Polari.src.gresource.xml
index 6acfd23..9a37622 100644
--- a/src/org.gnome.Polari.src.gresource.xml
+++ b/src/org.gnome.Polari.src.gresource.xml
@@ -19,5 +19,6 @@
<file>tabCompletion.js</file>
<file>userList.js</file>
<file>utils.js</file>
+ <file>userTracker.js</file>
</gresource>
</gresources>
diff --git a/src/userTracker.js b/src/userTracker.js
new file mode 100644
index 0000000..b7095ac
--- /dev/null
+++ b/src/userTracker.js
@@ -0,0 +1,148 @@
+const Polari = imports.gi.Polari;
+const Lang = imports.lang;
+const Tp = imports.gi.TelepathyGLib;
+const Signals = imports.signals;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+
+
+const UserTracker = new Lang.Class({
+ Name: 'UserTracker',
+
+ _init: function(params) {
+ if (params.room) {
+ this._room = params.room;
+ this._room.connect('notify::channel', Lang.bind(this, this._onChannelChanged));
+
+ this._onChannelChanged();
+ }
+ else {
+ //TODO: global user tracker
+ }
+ },
+
+ _onChannelChanged: function() {
+ if (this._room.channel) {
+ if (this._room.type == Tp.HandleType.ROOM) {
+ let members = this._room.channel.group_dup_members_contacts();
+
+ //this._contactMapping = this._buildMapping(members);
+ this._contactMapping = new Map();
+
+ for (var i = 0; i < members.length; i++)
+ this._trackMember(members[i]);
+
+ 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));
+ } else {
+ let members = [this._room.channel.connection.self_contact,
this._room.channel.target_contact];
+ this._buildMapping(members);
+ }
+ } else {
+ if(this._contactMapping) {
+ this._contactMapping.clear();
+
+ //this._room.disconnect('member-joined');
+ }
+ }
+ },
+
+ _buildMapping: function(members) {
+ let map = new Map();
+
+ for (var i = 0; i < members.length; i++) {
+ let currentBasenick = Polari.util_get_basenick(members[i].alias);
+ if (map.has(currentBasenick))
+ map.get(currentBasenick).push(members[i]);
+ else
+ map.set(currentBasenick, [members[i]]);
+ }
+
+ //log(map.get("raresv").length);
+
+ return map;
+ },
+
+ _onMemberRenamed: function(room, oldMember, newMember) {
+ log("rename " + oldMember.alias + " to " + newMember.alias);
+ this._untrackMember(oldMember);
+ this._trackMember(newMember);
+ },
+
+ _onMemberDisconnected: function(room, member, message) {
+ this._untrackMember(member);
+ },
+
+ _onMemberKicked: function(room, member, actor) {
+ this._untrackMember(member);
+ },
+
+ _onMemberBanned: function(room, member, actor) {
+ this._untrackMember(member);
+ },
+
+ _onMemberJoined: function(room, member) {
+ this._trackMember(member);
+ },
+
+ _onMemberLeft: function(room, member, message) {
+ this._untrackMember(member);
+ },
+
+ _trackMember: function(member) {
+ let baseNick = Polari.util_get_basenick(member.alias);
+
+ if (this._contactMapping.has(baseNick)) {
+ this._contactMapping.get(baseNick).push(member);
+ } else {
+ this._contactMapping.set(baseNick, [member]);
+ }
+
+ this._updateStatus(member);
+ },
+
+ _untrackMember: function(member) {
+ let baseNick = Polari.util_get_basenick(member.alias);
+
+ if (this._contactMapping.has(baseNick)) {
+ let indexToDelete = this._contactMapping.get(baseNick).map(c => c.alias).indexOf(member.alias);
+
+ if (indexToDelete > -1) {
+ this._contactMapping.get(baseNick).splice(indexToDelete, 1);
+
+ this._updateStatus(member);
+ }
+ }
+ },
+
+ _updateStatus: function(member) {
+ let baseNick = Polari.util_get_basenick(member.alias);
+
+ if (this._contactMapping.has(baseNick)) {
+ if (this._contactMapping.get(baseNick).length == 0) {
+ this.emit('status-changed', member.alias, this._room, Tp.ConnectionPresenceType.OFFLINE);
+ } else {
+ this.emit('status-changed', member.alias, this._room, Tp.ConnectionPresenceType.AVAILABLE);
+ }
+ }
+ },
+
+ getNickStatus: function(nickName) {
+ let baseNick = Polari.util_get_basenick(member.alias);
+
+ if (this._contactMapping.has(baseNick)) {
+ if (this._contactMapping.get(baseNick).length == 0) {
+ return Tp.ConnectionPresenceType.OFFLINE;
+ } else {
+ return Tp.ConnectionPresenceType.AVAILABLE;
+ }
+ } else {
+ return Tp.ConnectionPresenceType.OFFLINE;
+ }
+ }
+});
+Signals.addSignalMethods(UserTracker.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]