[polari/gnome-3-20] roomList: Minor clean up



commit dd1330959be3aff5db51e8474ffb49d4beb3567e
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jul 15 17:59:22 2016 +0200

    roomList: Minor clean up
    
    Split out a helper function to get rid of nested ifs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768909

 src/roomList.js |   41 ++++++++++++++++++++---------------------
 1 files changed, 20 insertions(+), 21 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index cd79d68..2fa6c88 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -70,30 +70,29 @@ const RoomRow = new Lang.Class({
             this._updatePending();
     },
 
+    _getNumPending: function() {
+        if (!this._room.channel)
+            return [0, 0];
+
+        let pending = this._room.channel.dup_pending_messages();
+        let nPending = pending.length;
+        if (!this._room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP))
+            return [nPending, nPending];
+
+        let highlights = pending.filter(m => {
+            return this._room.should_highlight_message(m);
+        });
+        return [nPending, highlights.length];
+    },
+
     _updatePending: function() {
-        let room = this._room;
-
-        let pending;
-        let numPendingHighlights;
-
-        if (room.channel) {
-            pending = room.channel.dup_pending_messages();
-            if (room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP))
-                numPendingHighlights = pending.filter(function(m) {
-                    return room.should_highlight_message(m);
-                }).length;
-            else
-                numPendingHighlights = pending.length;
-        } else {
-            pending = [];
-            numPendingHighlights = 0;
-        }
+        let [nPending, nHighlights] = this._getNumPending();
 
-        this._counter.label = numPendingHighlights.toString();
-        this._counter.opacity = numPendingHighlights > 0 ? 1. : 0.;
+        this._counter.label = nHighlights.toString();
+        this._counter.opacity = nHighlights > 0 ? 1. : 0.;
 
         let context = this.get_style_context();
-        if (pending.length == 0)
+        if (nPending == 0)
             context.add_class('inactive');
         else
             context.remove_class('inactive');


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