summary refs log tree commit diff
path: root/webclient/recents
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-08-28 16:38:00 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-08-28 16:38:16 +0200
commitb09e531159c56a8f08c5ead81dbba40f923db822 (patch)
tree8c44b071a488b6bea6e799b8c9fe5b76da714d48 /webclient/recents
parentFlesh out m.room.message msgtypes (diff)
downloadsynapse-b09e531159c56a8f08c5ead81dbba40f923db822.tar.xz
Do a smart update of the recents from the events stream rather than hammering initialSync each time
Diffstat (limited to '')
-rw-r--r--webclient/recents/recents-controller.js28
1 files changed, 21 insertions, 7 deletions
diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js
index e182a3ad23..803ab420f9 100644
--- a/webclient/recents/recents-controller.js
+++ b/webclient/recents/recents-controller.js
@@ -25,13 +25,24 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
     // in order to highlight a specific room in the list
     $scope.recentsSelectedRoomID;
 
-    // Refresh the list on matrix invitation and message event
-    $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
-        refresh();
-    });
-    $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
-        refresh();
-    });
+    var listenToEventStream = function() {
+        // Refresh the list on matrix invitation and message event
+        $scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
+            var config = matrixService.config();
+            if (event.state_key === config.user_id && event.content.membership === "invite") {
+                console.log("Invited to room " + event.room_id);
+                // FIXME push membership to top level key to match /im/sync
+                event.membership = event.content.membership;
+                // FIXME bodge a nicer name than the room ID for this invite.
+                event.room_display_name = event.user_id + "'s room";
+                $scope.rooms[event.room_id] = event;
+            }
+        });
+        $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
+            $scope.rooms[event.room_id].lastMsg = event;
+        });
+    };
+
     
     var refresh = function() {
         // List all rooms joined or been invited to
@@ -56,6 +67,9 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
                 for (var i = 0; i < presence.length; ++i) {
                     eventHandlerService.handleEvent(presence[i], false);
                 }
+
+                // From now, update recents from the stream
+                listenToEventStream();
             },
             function(error) {
                 $scope.feedback = "Failure: " + error.data;