[polari/wip/bastianilso/status-hiding] kind-of-review



commit 3d97b9c5734de6e9533797a1bc74b2d4877ec005
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Dec 3 18:45:08 2015 +0100

    kind-of-review

 src/chatView.js |  156 ++++++++++++++++++++-----------------------------------
 1 files changed, 57 insertions(+), 99 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 9680078..9d5ba13 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -694,11 +694,7 @@ const ChatView = new Lang.Class({
     _onMemberRenamed: function(room, oldMember, newMember) {
         let time = GLib.DateTime.new_now_utc().to_unix();
         let text = _("%s is now known as %s").format(oldMember.alias, newMember.alias);
-        if (this._shouldShowStatus(oldMember.alias)) {
-            this._insertStatus(text);
-        } else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD) {
-            this._insertStatusCompressed(text, 'renamed');
-        }
+        this._insertStatus(text, oldMember.alias, 'renamed');
         this._setNickStatus(oldMember.alias, Tp.ConnectionPresenceType.OFFLINE);
         this._setNickStatus(newMember.alias, Tp.ConnectionPresenceType.AVAILABLE);
     },
@@ -708,11 +704,7 @@ const ChatView = new Lang.Class({
         let text = _("%s has disconnected").format(member.alias);
         if (message)
             text += ' (%s)'.format(message);
-        if (this._shouldShowStatus(member.alias)) {
-            this._insertStatus(text);
-        } else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD) {
-            this._insertStatusCompressed(text, 'left');
-        }
+        this._insertStatus(text, member.alias, 'left');
         this._setNickStatus(member.alias, Tp.ConnectionPresenceType.OFFLINE);
     },
 
@@ -722,11 +714,7 @@ const ChatView = new Lang.Class({
             actor ? _("%s has been kicked by %s").format(member.alias,
                                                          actor.alias)
                   : _("%s has been kicked").format(member.alias);
-        if (this._shouldShowStatus(member.alias)) {
-            this._insertStatus(message);
-        } else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD) {
-            this._insertStatusCompressed(message, 'left');
-        }
+        this._insertStatus(message, member.alias, 'left');
         this._setNickStatus(member.alias, Tp.ConnectionPresenceType.OFFLINE);
     },
 
@@ -736,22 +724,14 @@ const ChatView = new Lang.Class({
             actor ? _("%s has been banned by %s").format(member.alias,
                                                          actor.alias)
                   : _("%s has been banned").format(member.alias)
-        if (this._shouldShowStatus(member.alias)) {
-            this._insertStatus(message);
-        } else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD) {
-            this._insertStatusCompressed(message, 'left');
-        }
+        this._insertStatus(message, member.alias, 'left');
         this._setNickStatus(member.alias, Tp.ConnectionPresenceType.OFFLINE);
     },
 
     _onMemberJoined: function(room, member) {
         let time = GLib.DateTime.new_now_utc().to_unix();
         let text = _("%s joined").format(member.alias);
-        if (this._shouldShowStatus(member.alias)) {
-            this._insertStatus(text);
-        } else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD) {
-            this._insertStatusCompressed(text, 'joined');
-        }
+        this._insertStatus(text, member.alias, 'joined');
         this._setNickStatus(member.alias, Tp.ConnectionPresenceType.AVAILABLE);
     },
 
@@ -762,11 +742,7 @@ const ChatView = new Lang.Class({
         if (message)
             text += ' (%s)'.format(message);
 
-        if (this._shouldShowStatus(member.alias))
-            this._insertStatus(text);
-        else if (time - this._state.lastTimestamp > INACTIVITY_THRESHOLD)
-            this._insertStatusCompressed(text, 'left');
-
+        this._insertStatus(text, member.alias, 'left');
         this._setNickStatus(member.alias, Tp.ConnectionPresenceType.OFFLINE);
     },
 
@@ -805,85 +781,63 @@ const ChatView = new Lang.Class({
         return time - nickTag._lastActivity < INACTIVITY_THRESHOLD;
     },
 
-/*
-    _insertStatus: function( The status message, time ? ) {
+    _updateStatusHeader: function() {
+        let buffer = this._view.buffer;
+        let headerMark = buffer.get_mark('idle-status-start');
+        let tagName = 'status-compressed' + this._state.lastStatusGroup;
+        let headerTag;
+        if (!headerMark) {
+            buffer.create_mark('idle-status-start', buffer.get_end_iter(), true);
+            headerTag = new Gtk.TextTag({ name: tagName });
+            buffer.tag_table.add(headerTag);
+            this._ensureNewLine([headerTag]);
+        } else {
+            let start = buffer.get_iter_at_mark(headerMark);
+            let end = start.copy();
+            end.forward_line();
+            buffer.delete(start, end);
 
-        // Should the status be grouped?
-            // YES: Is there a group which exists already?
-                // YES: Then insert into the group
-                // NO: Then create a new group
+            headerTag = this._lookupTag(tagName);
+        }
 
-        // Should the status be shown at all? If not, then we return
+        headerTag.invisible = this._statusCount.total < STATUS_NOISE_MAXIMUM;
+
+        let stats = [];
+        if (this._statusCount.joined > 0)
+            stats.push(Gettext.ngettext("%d user joined",
+                                        "%d users joined", 
this._statusCount.joined).format(this._statusCount.joined));
+        if (this._statusCount.left > 0)
+            stats.push(Gettext.ngettext("%d user left",
+                                        "%d users left", 
this._statusCount.left).format(this._statusCount.left));
+        this._insertWithTags(buffer.get_iter_at_mark(headerMark),
+                             stats.join(", ") + ' (\u2026)\n',
+                             [this._lookupTag('status'), headerTag]);
     },
 
-*/
-
-
-
-
-    _insertStatusCompressed: function(statusText, status) {
+    _insertStatus: function(text, member, type) {
         let time = GLib.DateTime.new_now_utc().to_unix();
         if (time - this._joinTime < IGNORE_STATUS_TIME)
             return;
 
-        this._state.lastNick = null;
-
-        if (this._statusCount.total == 0)
-            this._ensureNewLine();
-
-        if (status == 'left')
-            this._statusCount.left++;
-        else if (status == 'joined')
-            this._statusCount.joined++;
-        this._statusCount.total++;
-
-        let buffer = this._view.buffer;
-        let markStart = buffer.get_mark('idle-status-start');
-        if (!markStart) {
-            let iter = buffer.get_end_iter();
-            markStart = buffer.create_mark('idle-status-start', iter, true);
-        }
-
-        let statusGroupNumber = this._state.lastStatusGroup;
-        let statusGroupTag = this._lookupTag('status' + statusGroupNumber);
-        if (!statusGroupTag) {
-            statusGroupTag = new Gtk.TextTag({ name: 'status' + statusGroupNumber });
-            buffer.tag_table.add(statusGroupTag);
-        }
-
-        let statusTag = this._lookupTag('status');
-        let endIter = buffer.get_end_iter();
-        this._insertWithTags(endIter, statusText + '\n', [statusGroupTag, statusTag]);
-
-        if (this._statusCount.total > STATUS_NOISE_MAXIMUM) {
-            let statusCompressedTag = this._lookupTag('status-compressed' + statusGroupNumber);
-            if (!statusCompressedTag) {
-                statusCompressedTag = new Gtk.TextTag({ name: 'status-compressed' + statusGroupNumber });
-                buffer.tag_table.add(statusCompressedTag);
-                statusGroupTag.invisible = true;
-            }
-
-            let compressedText = this._statusCount.joined + " users joined, "
-                                 + this._statusCount.left + " users left. ";
+        let grouped = time - this._state.lastTimestamp > ACTIVITY_DURATION;
+        if (!grouped && !this._shouldShowStatus(member))
+            return;
 
-            let markStartIter = buffer.get_iter_at_mark(markStart);
-            let markEndIter = markStartIter.copy();
-            markEndIter.forward_line();
-            buffer.delete(markStartIter, markEndIter);
+        this._state.lastNick = null;
 
-            markStartIter = buffer.get_iter_at_mark(markStart);
-            this._insertWithTags(markStartIter, compressedText + ' (\u2026) \n' , [statusTag, 
statusCompressedTag]);
+        let tags = ['status'];
+        if (grouped) {
+            if (this._statusCount.hasOwnProperty(type))
+                this._statusCount[type]++;
+            this._updateStatusHeader();
+            tags.push('status' + this._state.lastStatusGroup);
+        } else {
+            this._resetStatusCompressed();
         }
-    },
 
-    _insertStatus: function(text) {
-        let time = GLib.DateTime.new_now_utc().to_unix();
-        if (time - this._joinTime < IGNORE_STATUS_TIME)
-            return;
-        this._state.lastNick = null;
-        this._ensureNewLine();
+        this._ensureNewLine(tags);
         let iter = this._view.buffer.get_end_iter();
-        this._insertWithTagName(iter, text, 'status');
+        this._insertWithTags(iter, text, tags);
     },
 
     _formatTimestamp: function(timestamp) {
@@ -1104,11 +1058,15 @@ const ChatView = new Lang.Class({
         this._insertWithTags(iter, text.substr(pos), tags);
     },
 
-    _ensureNewLine: function() {
+    _ensureNewLine: function(tags) {
         let buffer = this._view.get_buffer();
         let iter = buffer.get_end_iter();
-        if (iter.get_line_offset() != 0)
-            buffer.insert(iter, '\n', -1);
+        if (iter.get_line_offset() != 0) {
+            if (tags)
+                this._insertWithTags(iter, '\n', tags);
+            else
+                buffer.insert(iter, '\n', -1);
+        }
     },
 
     _getLineIters: function(iter) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]