[polari/wip/fmuellner/combined-gsoc: 57/136] work so far, part 6, added notifications (in the command line)



commit 3d9593a47123278451d2bc7b90aeadd413b120cc
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        |    4 ++-
 src/chatroomManager.js |   33 ++++++++++++++++++++
 src/userList.js        |   77 +++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 103 insertions(+), 11 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index d7118ec..345040f 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -17,6 +17,7 @@ const Signals = imports.signals;
 const Utils = imports.utils;
 const UserTracker = imports.userTracker;
 const UserList = imports.userList;
+const ChatroomManager = imports.chatroomManager;
 
 const MAX_NICK_CHARS = 8;
 const IGNORE_STATUS_TIME = 5;
@@ -304,6 +305,7 @@ const ChatView = new Lang.Class({
         this._pendingLogs = [];
         this._initialPending = [];
         this._statusCount = { left: 0, joined: 0, total: 0 };
+        this._chatroomManager = ChatroomManager.getDefault();
         this._logWalker = null;
 
         this._userTracker = new UserTracker.UserTracker(this._room);
@@ -1260,7 +1262,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 3fe7726..08a9548 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) {
@@ -522,6 +524,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 02d60d2..dc57631 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]