[polari] polari-room: Move room_compare() into JS



commit 5a2b48867442ace4c381822d4d855c5cf48c313b
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Jan 24 16:23:36 2016 +0100

    polari-room: Move room_compare() into JS
    
    We will soon add placeholder rows without an associated room to the
    roomList, so do the row sorting directly in JS instead of using
    a PolariRoom method.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709984

 src/lib/polari-room.c |   22 ----------------------
 src/lib/polari-room.h |    2 --
 src/roomList.js       |   14 +++++++++++++-
 3 files changed, 13 insertions(+), 25 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 3ecc541..bdd54d7 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -229,28 +229,6 @@ polari_room_remove_member (PolariRoom *room,
   }
 }
 
-int
-polari_room_compare (PolariRoom *room,
-                     PolariRoom *other)
-{
-  TpAccount *account1, *account2;
-
-  g_return_val_if_fail (POLARI_IS_ROOM (room) && POLARI_IS_ROOM (other), 0);
-  g_return_val_if_fail (room->priv->account && other->priv->account, 0);
-
-  account1 = room->priv->account;
-  account2 = other->priv->account;
-
-  if (account1 != account2)
-    return strcmp (tp_account_get_display_name (account1),
-                   tp_account_get_display_name (account2));
-
-  if (room->priv->type != other->priv->type)
-    return room->priv->type == TP_HANDLE_TYPE_ROOM ? -1 : 1;
-
-  return strcmp (room->priv->display_name, other->priv->display_name);
-}
-
 static char *
 strip_color_codes (const char *string) {
   if (G_UNLIKELY (color_code_regex == NULL))
diff --git a/src/lib/polari-room.h b/src/lib/polari-room.h
index 61b7556..d2ece55 100644
--- a/src/lib/polari-room.h
+++ b/src/lib/polari-room.h
@@ -36,8 +36,6 @@ void  polari_room_set_topic (PolariRoom *room, const char *topic);
 void  polari_room_add_member    (PolariRoom *room, TpContact *member);
 void  polari_room_remove_member (PolariRoom *room, TpContact *member);
 
-int   polari_room_compare (PolariRoom *room, PolariRoom *other);
-
 char *polari_create_room_id (TpAccount    *account,
                              const char   *name,
                              TpHandleType  type);
diff --git a/src/roomList.js b/src/roomList.js
index 587df33..caac352 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -488,6 +488,18 @@ const RoomList = new Lang.Class({
     },
 
     _sort: function(row1, row2) {
-        return row1.room.compare(row2.room);
+        let room1 = row1.room;
+        let room2 = row2.room;
+
+        let account1 = room1.account;
+        let account2 = room2.account;
+
+        if (account1 != account2)
+            return account1.display_name.localeCompare(account2.display_name);
+
+        if (room1.type != room2.type)
+            return room1.type == Tp.HandleType.ROOM ? -1 : 1;
+
+        return room1.display_name.localeCompare(room2.display_name);
     }
 });


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