summary refs log tree commit diff
path: root/webclient/components
diff options
context:
space:
mode:
Diffstat (limited to 'webclient/components')
-rw-r--r--webclient/components/matrix/event-handler-service.js74
-rw-r--r--webclient/components/matrix/matrix-filter.js6
2 files changed, 42 insertions, 38 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index 5aabc899b8..1f32289bdf 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -60,7 +60,7 @@ angular.module('eventHandlerService', [])
             // Pagination information
             $rootScope.events.rooms[room_id].pagination = {
                 earliest_token: "END"   // how far back we've paginated
-            }
+            };
         }
     };
 
@@ -70,6 +70,36 @@ angular.module('eventHandlerService', [])
         }
     };
     
+    // Generic method to handle events data
+    var handleRoomDateEvent = function(event, isLiveEvent, addToRoomMessages) {
+        // Add topic changes as if they were a room message
+        if (addToRoomMessages) {
+            if (isLiveEvent) {
+                $rootScope.events.rooms[event.room_id].messages.push(event);
+            }
+            else {
+                $rootScope.events.rooms[event.room_id].messages.unshift(event);
+            }
+        }
+
+        // live events always update, but non-live events only update if the
+        // ts is later.
+        var latestData = true;
+        if (!isLiveEvent) {
+            var eventTs = event.ts;
+            var storedEvent = $rootScope.events.rooms[event.room_id][event.type];
+            if (storedEvent) {
+                if (storedEvent.ts > eventTs) {
+                    // ignore it, we have a newer one already.
+                    latestData = false;
+                }
+            }
+        }
+        if (latestData) {
+            $rootScope.events.rooms[event.room_id][event.type] = event;         
+        }
+    };
+    
     var handleRoomCreate = function(event, isLiveEvent) {
         // For now, we do not use the event data. Simply signal it to the app controllers
         $rootScope.$broadcast(ROOM_CREATE_EVENT, event, isLiveEvent);
@@ -153,44 +183,16 @@ angular.module('eventHandlerService', [])
         }
     };
 
-    var handleRoomName = function(event, isLiveEvent) {
-        console.log("handleRoomName " + isLiveEvent);
-
-        $rootScope.events.rooms[event.room_id][event.type] = event;
+    var handleRoomName = function(event, isLiveEvent, isStateEvent) {
+        console.log("handleRoomName room_id: " + event.room_id + " - isLiveEvent: " + isLiveEvent + " - name: " + event.content.name);
+        handleRoomDateEvent(event, isLiveEvent, !isStateEvent);
         $rootScope.$broadcast(NAME_EVENT, event, isLiveEvent);
     };
     
-    // TODO: Can this just be a generic "I am a room state event, can haz store?"
-    var handleRoomTopic = function(event, isLiveEvent, isStateEvent) {
-        console.log("handleRoomTopic live="+isLiveEvent);
-
-        // Add topic changes as if they were a room message
-        if (!isStateEvent) {
-            if (isLiveEvent) {
-                $rootScope.events.rooms[event.room_id].messages.push(event);
-            }
-            else {
-                $rootScope.events.rooms[event.room_id].messages.unshift(event);
-            }
-        }
-
-        // live events always update, but non-live events only update if the
-        // ts is later.
-        var latestData = true;
-        if (!isLiveEvent) {
-            var eventTs = event.ts;
-            var storedEvent = $rootScope.events.rooms[event.room_id][event.type];
-            if (storedEvent) {
-                if (storedEvent.ts > eventTs) {
-                    // ignore it, we have a newer one already.
-                    latestData = false;
-                }
-            }
-        }
-        if (latestData) {
-            $rootScope.events.rooms[event.room_id][event.type] = event;         
-        }
 
+    var handleRoomTopic = function(event, isLiveEvent, isStateEvent) {
+        console.log("handleRoomTopic room_id: " + event.room_id + " - isLiveEvent: " + isLiveEvent + " - topic: " + event.content.topic);
+        handleRoomDateEvent(event, isLiveEvent, !isStateEvent);
         $rootScope.$broadcast(TOPIC_EVENT, event, isLiveEvent);
     };
 
@@ -286,7 +288,7 @@ angular.module('eventHandlerService', [])
                         handlePowerLevels(event, isLiveEvent);
                         break;
                     case 'm.room.name':
-                        handleRoomName(event, isLiveEvent);
+                        handleRoomName(event, isLiveEvent, isStateEvent);
                         break;
                     case 'm.room.topic':
                         handleRoomTopic(event, isLiveEvent, isStateEvent);
diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js
index 260e0827df..015a88bcad 100644
--- a/webclient/components/matrix/matrix-filter.js
+++ b/webclient/components/matrix/matrix-filter.js
@@ -31,15 +31,17 @@ angular.module('matrixFilter', [])
         }
 
         if (undefined === roomName) {
-            // Else, build the name from its users
+
             var room = $rootScope.events.rooms[room_id];
             if (room) {
+                // Get name from room state date
                 var room_name_event = room["m.room.name"];
-
                 if (room_name_event) {
                     roomName = room_name_event.content.name;
                 }
                 else if (room.members) {
+                    // Else, build the name from its users
+                    // FIXME: Is it still required?
                     // Limit the room renaming to 1:1 room
                     if (2 === Object.keys(room.members).length) {
                         for (var i in room.members) {