[polari/wip/fmuellner/combined-gsoc: 62/136] popover update themselves, the notify button is not yet updated by the global status, status label i
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/fmuellner/combined-gsoc: 62/136] popover update themselves, the notify button is not yet updated by the global status, status label i
- Date: Tue, 26 Jul 2016 23:21:11 +0000 (UTC)
commit 2ec7cfe0aa0c8ce816a75541b311cf0ea20fba96
Author: raresv <rares visalom gmail com>
Date: Sun Jul 10 15:56:37 2016 +0300
popover update themselves, the notify button is not yet updated by the global status, status label is
still ON/OFF, notification logic moved to userTracker (to be replace with actions in the future)
src/chatView.js | 4 +-
src/chatroomManager.js | 33 ------------------------
src/userList.js | 31 ++++++++++++----------
src/userTracker.js | 65 ++++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 79 insertions(+), 54 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index e29581e..1a3026c 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1256,7 +1256,7 @@ const ChatView = new Lang.Class({
this._view.buffer.create_mark(null, iter, true));
},
- _createNickTag: function(nickName) {
+ /*_createNickTag: function(nickName) {
let nickTagName = this._getNickTagName(nickName);
let tag = new Gtk.TextTag({ name: nickTagName });
@@ -1264,7 +1264,7 @@ const ChatView = new Lang.Class({
this._updateNickTag(tag, Tp.ConnectionPresenceType.OFFLINE);
return tag;
- },
+ },*/
_onStatusChangedCallback: function(nick, status) {
log("Nick " + nick + " has local status " + status);
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 08a9548..3fe7726 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -162,8 +162,6 @@ const _ChatroomManager = new Lang.Class({
this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
this._lastActiveRoom = null;
-
- this._watchlist = [];
},
_onPrepared: function(mon, am) {
@@ -524,37 +522,6 @@ const _ChatroomManager = new Lang.Class({
get roomCount() {
return Object.keys(this._rooms).length;
- },
-
- addToWatchlist: function(user, network) {
- this._watchlist.push([user, network]);
- },
-
- isUserWatched: function (user, network) {
- for (var i = 0; i < this._watchlist.length; i++) {
- if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
- return true;
- }
- }
-
- return false;
- },
-
- popUserFromWatchlist: function (user, network) {
- let indexToDelete = -1;
- for (var i = 0; i < this._watchlist.length; i++) {
- if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
- indexToDelete = i;
- }
- }
-
- if (indexToDelete != -1)
- this._watchlist.splice(indexToDelete, 1);
- },
-
- emitWatchedUserNotification: function (notification) {
- log("notification in chatroom manager");
- this._app.send_notification('watched-user-notification', notification);
}
});
Signals.addSignalMethods(_ChatroomManager.prototype);
diff --git a/src/userList.js b/src/userList.js
index b5dd17f..2bd8dc4 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -326,8 +326,6 @@ const UserPopover = new Lang.Class({
this.parent(params);
- this._chatroomManager = ChatroomManager.getDefault();
-
this._nickLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_top: 0 });
this._statusLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_bottom: 0 });
@@ -338,7 +336,7 @@ const UserPopover = new Lang.Class({
this._hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, halign: Gtk.Align.FILL, margin:
9 });
this._hbox.add(this._headervbox);
- this._notifyButton = new Gtk.Button({ image: new Gtk.Image({ icon_name: 'alarm-symbolic' }), halign:
Gtk.Align.END, hexpand: true });
+ this._notifyButton = new Gtk.ToggleButton({ image: new Gtk.Image({ icon_name: 'alarm-symbolic' }),
halign: Gtk.Align.END, hexpand: true });
this._notifyButton.connect('clicked',
Lang.bind(this, this._onNotifyButtonClicked));
this._hbox.add(this._notifyButton);
@@ -364,7 +362,7 @@ const UserPopover = new Lang.Class({
let baseNick = Polari.util_get_basenick(nickname);
- this._userTracker.connect("status-changed::" + baseNick, Lang.bind(this, this._onNickStatusChanged));
+ this._userTracker.watchUser(this._room, this._nickname, Lang.bind(this, this._onNickStatusChanged));
this._updateContents();
},
@@ -374,7 +372,7 @@ const UserPopover = new Lang.Class({
},
_updateContents: function() {
- let bestMatchingContact = this._userTracker.getBestMatchingContact(this._nickname);
+ let bestMatchingContact = this._userTracker.getBestMatchingContactInRoom(this._room, this._nickname);
this._nickLabel.set_label(this._nickname);
this._statusLabel.set_label(bestMatchingContact ? "Online" : "Offline");
@@ -400,35 +398,40 @@ const UserPopover = new Lang.Class({
},
_onNotifyButtonClicked: function() {
- if (!this._chatroomManager.isUserWatched(this._nickname, this._room.account.get_display_name())) {
- this._chatroomManager.addToWatchlist(this._nickname, this._room.account.get_display_name());
+ if (!this._userTracker.isUserWatched(this._nickname, this._room.account.get_display_name())) {
+ this._userTracker.addToWatchlist(this._nickname, this._room.account.get_display_name());
this._updateNotifyButton();
}
},
_updateNotifyButton: function() {
- if (!this._chatroomManager.isUserWatched(this._nickname, this._room.account.get_display_name()))
+ if (!this._userTracker.isUserWatched(this._nickname, this._room.account.get_display_name()))
if (this._user) {
this._notifyButton.visible = false;
- this._notifyButton.sensitive = true;
+ //this._notifyButton.sensitive = true;
+ this._notifyButton.set_active(true);
}
else {
this._notifyButton.visible = true;
- this._notifyButton.sensitive = true;
+ //this._notifyButton.sensitive = true;
+ this._notifyButton.set_active(true);
}
else
if (this._user) {
this._notifyButton.visible = false;
- this._notifyButton.sensitive = true;
+ //this._notifyButton.sensitive = true;
+ this._notifyButton.set_active(true);
}
else {
this._notifyButton.visibile = true;
- this._notifyButton.sensitive = false;
+ //this._notifyButton.sensitive = false;
+ this._notifyButton.set_active(false);
}
},
- _onNickStatusChanged: function(tracker, nickName, status) {
- this.user = this._userTracker.getBestMatchingContact(this._nickname);
+ _onNickStatusChanged: function(nickName, status) {
+ //this.user = this._userTracker.getBestMatchingContact(this._nickname);
+ this._updateContents();
}
});
diff --git a/src/userTracker.js b/src/userTracker.js
index 7e78bbd..0c6f6d2 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -3,6 +3,9 @@ const Lang = imports.lang;
const Tp = imports.gi.TelepathyGLib;
const Signals = imports.signals;
const GObject = imports.gi.GObject;
+const Utils = imports.utils;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
const AccountsMonitor = imports.accountsMonitor;
const ChatroomManager = imports.chatroomManager;
@@ -91,9 +94,12 @@ const UserTracker = new Lang.Class({
this._globalContactMapping = new Map();
this._roomMapping = new Map();
this._handlerCounter = 0;
+ this._app = Gio.Application.get_default();
this._userStatusMonitor = getUserStatusMonitor();
+ this._watchlist = [];
+
this._chatroomManager = ChatroomManager.getDefault();
this._chatroomManager.connect('room-added', Lang.bind(this, this._onRoomAdded));
this._chatroomManager.connect('room-removed', Lang.bind(this, this._onRoomRemoved));
@@ -205,6 +211,10 @@ const UserTracker = new Lang.Class({
this._untrackMember(this._globalContactMapping, oldMember, room);
this._trackMember(this._roomMapping.get(room)._contactMapping, newMember, room);
this._trackMember(this._globalContactMapping, newMember, room);
+
+ /*TODO: is this needed here?*/
+ if (this.isUserWatched(newMember.alias, newMember.get_account().get_display_name()))
+ this.emitWatchedUserNotification(room, newMember);
},
_onMemberDisconnected: function(room, member, message) {
@@ -233,6 +243,9 @@ const UserTracker = new Lang.Class({
this._trackMember(this._roomMapping.get(room)._contactMapping, member, room);
this._trackMember(this._globalContactMapping, member, room);
+
+ if (this.isUserWatched(member.alias, member.get_account().get_display_name()))
+ this.emitWatchedUserNotification(room, member);
},
_onMemberLeft: function(room, member, message) {
@@ -253,11 +266,10 @@ const UserTracker = new Lang.Class({
//was on HEAD
/*if (this._contactMapping.get(baseNick).length == 1)
this.emit("status-changed::"+baseNick, member.alias, Tp.ConnectionPresenceType.AVAILABLE);*/
- if (map == this._globalContactMapping)log("length: " +
this._globalContactMapping.get(baseNick).length)
if (map.get(baseNick).length == 1)
if (map == this._globalContactMapping) {
- this.emit("global-status-changed::" + member.alias, Tp.ConnectionPresenceType.AVAILABLE);
+ this.emit("status-changed::" + baseNick, member.alias, Tp.ConnectionPresenceType.AVAILABLE);
log("[global status] user " + member.alias + " is globally online");
}
else
@@ -283,7 +295,7 @@ const UserTracker = new Lang.Class({
//was on HEAD
/*this.emit("status-changed::"+baseNick, member.alias, Tp.ConnectionPresenceType.OFFLINE);*/
if (map == this._globalContactMapping) {
- this.emit("global-status-changed::" + member.alias, Tp.ConnectionPresenceType.OFFLINE);
+ this.emit("status-changed::" + baseNick, member.alias,
Tp.ConnectionPresenceType.OFFLINE);
log("[global status] user " + member.alias + " is globally offline");
}
else
@@ -304,9 +316,10 @@ const UserTracker = new Lang.Class({
: Tp.ConnectionPresenceType.AVAILABLE;
},
- getBestMatchingContact: function(nickName) {
+ getBestMatchingContactInRoom: function(room, nickName) {
let baseNick = Polari.util_get_basenick(nickName);
- let contacts = this._contactMapping.get(baseNick) || [];
+ //let contacts = this._globalContactMapping.get(baseNick) || [];
+ let contacts = this._roomMapping.get(room)._contactMapping.get(baseNick) || [];
/*even possible?*/
if (contacts.length == 0)
@@ -355,5 +368,47 @@ const UserTracker = new Lang.Class({
return;
this._roomMapping.get(room)._handlerMapping.delete(handlerID);
+ },
+
+ addToWatchlist: function(user, network) {
+ this._watchlist.push([user, network]);
+ },
+
+ isUserWatched: function (user, network) {
+ for (var i = 0; i < this._watchlist.length; i++) {
+ if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ popUserFromWatchlist: function (user, network) {
+ let indexToDelete = -1;
+ for (var i = 0; i < this._watchlist.length; i++) {
+ if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
+ indexToDelete = i;
+ }
+ }
+
+ if (indexToDelete != -1)
+ this._watchlist.splice(indexToDelete, 1);
+ },
+
+ emitWatchedUserNotification: function (room, member) {
+ let notification = new Gio.Notification();
+ notification.set_title("User is online");
+ notification.set_body("User " + member.alias + " is online.");
+
+ let param = GLib.Variant.new('(ssu)',
+ [ this._account.get_object_path(),
+ room.channel_name,
+ Utils.getTpEventTime() ]);
+ notification.set_default_action_and_target('app.join-room', param);
+
+ this._app.send_notification('watched-user-notification', notification);
+
+ this.popUserFromWatchlist(member.alias, member.get_account().get_display_name());
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]