[polari/wip/raresv/nick-popover] work so far, part 6, added notifications (in the command line)
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/raresv/nick-popover] work so far, part 6, added notifications (in the command line)
- Date: Thu, 23 Jun 2016 13:14:00 +0000 (UTC)
commit a4d5fc1efd9dc3459126afcbbbbe9b34258a190c
Author: raresv <rares visalom gmail com>
Date: Thu Jun 23 16:13:42 2016 +0300
work so far, part 6, added notifications (in the command line)
src/chatView.js | 33 ++++++++++++++++----
src/chatroomManager.js | 33 ++++++++++++++++++++
src/userList.js | 77 +++++++++++++++++++++++++++++++++++++++++------
3 files changed, 126 insertions(+), 17 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index be67395..fb502e8 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -15,6 +15,7 @@ const PasteManager = imports.pasteManager;
const Signals = imports.signals;
const Utils = imports.utils;
const UserList = imports.userList;
+const ChatroomManager = imports.chatroomManager;
const MAX_NICK_CHARS = 8;
const IGNORE_STATUS_TIME = 5;
@@ -288,6 +289,7 @@ const ChatView = new Lang.Class({
this._pending = {};
this._pendingLogs = [];
this._statusCount = { left: 0, joined: 0, total: 0 };
+ this._chatroomManager = ChatroomManager.getDefault();
this._room.account.connect('notify::nickname', Lang.bind(this,
function() {
@@ -791,6 +793,23 @@ const ChatView = new Lang.Class({
if (nickTag._popover.fallbackNick == contact.alias)
nickTag._popover.user = contact;
+ if (this._chatroomManager.isUserWatched(contact.alias, this._room.account.get_display_name())) {
+ this._chatroomManager.popUserFromWatchlist(contact.alias, this._room.account.get_display_name());
+
+ let notification = new Gio.Notification();
+ notification.set_title("User is online");
+ notification.set_body("User " + contact.alias + " logged in.");
+
+ let param = GLib.Variant.new('(ssu)',
+ [ this._room.account.get_object_path(),
+ this._room.channel_name,
+ Utils.getTpEventTime() ]);
+ notification.set_default_action_and_target('app.join-room', param);
+ //this._app.send_notification('watched-user-notification', notification);
+
+ this._chatroomManager.emitWatchedUserNotification(notification);
+ }
+
this._updateTagStatus(nickTag);
},
@@ -804,12 +823,12 @@ const ChatView = new Lang.Class({
if (indexToDelete > -1) {
nickTag._contacts.splice(indexToDelete, 1);
- if (nickTag._popover.fallbackNick == contact.alias) {
- if (nickTag._contacts[0])
- nickTag._popover.user = nickTag._contacts[0];
- else
- nickTag._popober.user = null;
- }
+ if (nickTag._popover.fallbackNick == contact.alias) {
+ if (nickTag._contacts[0])
+ nickTag._popover.user = nickTag._contacts[0];
+ else
+ nickTag._popover.user = null;
+ }
this._updateTagStatus(nickTag);
}
@@ -1283,7 +1302,7 @@ const ChatView = new Lang.Class({
_createNickTag: function(name) {
let tag = new ButtonTag({ name: name });
- tag._popover = new UserList.UserPopover({ relative_to: this._view, margin: 0 });
+ tag._popover = new UserList.UserPopover({ relative_to: this._view, margin: 0, room: this._room });
tag.connect('clicked', Lang.bind(this, this._onNickTagClicked));
return tag;
},
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 1f295df..b21519c 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -162,6 +162,8 @@ const _ChatroomManager = new Lang.Class({
this._settings = new Gio.Settings({ schema_id: 'org.gnome.Polari' });
this._lastActiveRoom = null;
+
+ this._watchlist = [];
},
_onPrepared: function(mon, am) {
@@ -509,6 +511,37 @@ 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 d11b8bc..174a150 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -319,10 +319,29 @@ const UserPopover = new Lang.Class({
Extends: Gtk.Popover,
_init: function(params) {
+ this._room = params.room;
+ delete params.room;
+
this.parent(params);
- this._nickLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_left: 9 });
- this._statusLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_left: 9, margin_bottom: 3 });
+ 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 });
+
+ this._headervbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, halign: Gtk.Align.FILL });
+ this._headervbox.add(this._nickLabel);
+ this._headervbox.add(this._statusLabel);
+
+ 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.connect('clicked',
+ Lang.bind(this, this._onNotifyButtonClicked));
+ this._hbox.add(this._notifyButton);
+
+
this._userDetails = new UserDetails();
this.bind_property('visible', this._userDetails, 'expanded', 0);
@@ -331,8 +350,9 @@ const UserPopover = new Lang.Class({
//context.save();
this._vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
- this._vbox.add(this._nickLabel);
- this._vbox.add(this._statusLabel);
+ //this._vbox.add(this._nickLabel);
+ //this._vbox.add(this._statusLabel);
+ this._vbox.add(this._hbox);
this._vbox.add(this._userDetails);
this.add(this._vbox);
@@ -365,23 +385,60 @@ const UserPopover = new Lang.Class({
this._statusLabel.set_label(this._user ? "Online" : "Offline");
if (this._user) {
+ this._userDetails.user = this._user;
+
let context = this._statusLabel.get_style_context();
context.set_state(Gtk.StateFlags.LINK);
context.save();
+
this._statusLabel.sensitive = true;
+ //this._notifyButton.visible = false;
+ //this._updateNotifyButton();
}
else {
+ this._userDetails.clearPrevUserAndDetails();
+
this._statusLabel.sensitive = false;
- }
- if (this._user) {
- this._userDetails.user = this._user;
- }
- else {
- this._userDetails.clearPrevUserAndDetails();
+ /*if (!this._chatroomManager.isUserWatched(this._fallbackNick,
this._room.account.get_display_name()))
+ this._notifyButton.visible = true;
+ else
+ this._notifyButton.sensitive = false;*/
+ //this._updateNotifyButton();
}
+ this._updateNotifyButton();
+
this._userDetails.fallbackNick = this._fallbackNick;
+ },
+
+ _onNotifyButtonClicked: function() {
+ if (!this._chatroomManager.isUserWatched(this._fallbackNick, this._room.account.get_display_name()))
{
+ this._chatroomManager.addToWatchlist(this._fallbackNick, this._room.account.get_display_name());
+ //this._notifyButton.sensitive = false;
+ this._updateNotifyButton();
+ }
+ },
+
+ _updateNotifyButton: function() {
+ if (!this._chatroomManager.isUserWatched(this._fallbackNick, this._room.account.get_display_name()))
+ if (this._user) {
+ this._notifyButton.visible = false;
+ this._notifyButton.sensitive = true;
+ }
+ else {
+ this._notifyButton.visible = true;
+ this._notifyButton.sensitive = true;
+ }
+ else
+ if (this._user) {
+ this._notifyButton.visible = false;
+ this._notifyButton.sensitive = true;
+ }
+ else {
+ this._notifyButton.visibile = true;
+ this._notifyButton.sensitive = false;
+ }
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]