summary refs log tree commit diff
path: root/webclient
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-10-31 17:13:27 +0000
committerKegan Dougal <kegan@matrix.org>2014-10-31 17:13:27 +0000
commitf21960ec9d346d53a21369b8179cc30365654517 (patch)
tree7ae51a7880f64fe612a247395861eaa99c99ded7 /webclient
parentroom.html now displays messages from model-service. Add debugging fields. Hoo... (diff)
downloadsynapse-f21960ec9d346d53a21369b8179cc30365654517.tar.xz
Replace lots of .events.rooms[room_id] with .room
Diffstat (limited to 'webclient')
-rw-r--r--webclient/components/matrix/event-handler-service.js6
-rw-r--r--webclient/components/matrix/model-service.js2
-rw-r--r--webclient/room/room-controller.js19
-rw-r--r--webclient/room/room.html11
4 files changed, 22 insertions, 16 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index a511b394b8..f8a91ee0ac 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -289,6 +289,8 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
     };
     
     var handleRoomMember = function(event, isLiveEvent, isStateEvent) {
+        var __room = modelService.getRoom(event.room_id);
+        
         
         // add membership changes as if they were a room message if something interesting changed
         // Exception: Do not do this if the event is a room state event because such events already come
@@ -317,6 +319,9 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
                 else {
                     $rootScope.events.rooms[event.room_id].messages.unshift(event);
                 }
+                // ============
+                
+                __room.addMessageEvent(event, !isLiveEvent);
             }
         }
         
@@ -324,6 +329,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
         // Do not care of events that come when paginating back
         if (isStateEvent || isLiveEvent) {
             $rootScope.events.rooms[event.room_id].members[event.state_key] = event;
+            __room.current_room_state.members[event.state_key] = event;
         }
         
         $rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent, isStateEvent);
diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js
index d47ac6b2a9..6167a84c62 100644
--- a/webclient/components/matrix/model-service.js
+++ b/webclient/components/matrix/model-service.js
@@ -77,7 +77,7 @@ angular.module('modelService', [])
     /***** Room State Object *****/
     var RoomState = function RoomState() {
         // list of RoomMember
-        this.members = []; 
+        this.members = {}; 
         // state events, the key is a compound of event type + state_key
         this.state_events = {}; 
         this.pagination_token = ""; 
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 7125c98e02..b5f2b60419 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -64,7 +64,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
                 return;
             };
 
-            var nameEvent = $rootScope.events.rooms[$scope.room_id]['m.room.name'];
+            var nameEvent = $scope.room.current_room_state.state_events['m.room.name'];
             if (nameEvent) {
                 $scope.name.newNameText = nameEvent.content.name;
             }
@@ -105,7 +105,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
                 console.log("Warning: Already editing topic.");
                 return;
             }
-            var topicEvent = $rootScope.events.rooms[$scope.room_id]['m.room.topic'];
+            var topicEvent = $scope.room.current_room_state.state_events['m.room.topic'];
             if (topicEvent) {
                 $scope.topic.newTopicText = topicEvent.content.topic;
             }
@@ -492,7 +492,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
                             
                             var room_id = matrixService.getAliasToRoomIdMapping(room_alias);
                             console.log("joining " + room_alias + " id=" + room_id);
-                            if ($rootScope.events.rooms[room_id]) {
+                            if ($scope.room) { // TODO actually check that you = join
                                 // don't send a join event for a room you're already in.
                                 $location.url("room/" + room_alias);
                             }
@@ -629,7 +629,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
             };
 
             $('#mainInput').val('');
-            $rootScope.events.rooms[$scope.room_id].messages.push(echoMessage);
+            $scope.room.addMessageEvent(echoMessage);
             scrollToBottom();
         }
 
@@ -732,9 +732,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
                 var needsToJoin = true;
                 
                 // The room members is available in the data fetched by initialSync
-                if ($rootScope.events.rooms[$scope.room_id]) {
+                if ($scope.room) {
 
-                    var messages = $rootScope.events.rooms[$scope.room_id].messages;
+                    var messages = $scope.room.events;
 
                     if (0 === messages.length
                     || (1 === messages.length && "m.room.member" === messages[0].type && "invite" === messages[0].content.membership && $scope.state.user_id === messages[0].state_key)) {
@@ -746,7 +746,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
                         $scope.state.first_pagination = false;
                     }
 
-                    var members = $rootScope.events.rooms[$scope.room_id].members;
+                    var members = $scope.room.current_room_state.members;
 
                     // Update the member list
                     for (var i in members) {
@@ -1042,8 +1042,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
             state_key: ""
         };
 
-        var stateFilter = $filter("stateEventsFilter");
-        var stateEvents = stateFilter($scope.events.rooms[$scope.room_id]);
+        var stateEvents = $scope.room.current_room_state.state_events;
         // The modal dialog will 2-way bind this field, so we MUST make a deep
         // copy of the state events else we will be *actually adjusing our view
         // of the world* when fiddling with the JSON!! Apparently parse/stringify
@@ -1062,7 +1061,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
     console.log("Displaying modal dialog for >>>> " + JSON.stringify($scope.event_selected));
     $scope.redact = function() {
         console.log("User level = "+$scope.pow($scope.room_id, $scope.state.user_id)+
-                    " Redact level = "+$scope.events.rooms[$scope.room_id]["m.room.ops_levels"].content.redact_level);
+                    " Redact level = "+$scope.room.current_room_state.state_events["m.room.ops_levels"].content.redact_level);
         console.log("Redact event >> " + JSON.stringify($scope.event_selected));
         $modalInstance.close("redact");
     };
diff --git a/webclient/room/room.html b/webclient/room/room.html
index 8c1e45dfd4..1cec8ac70b 100644
--- a/webclient/room/room.html
+++ b/webclient/room/room.html
@@ -6,7 +6,7 @@
         </div>
         <div class="modal-footer">
             <button ng-click="redact()" type="button" class="btn btn-danger" 
-             ng-disabled="!events.rooms[room_id]['m.room.ops_levels'].content.redact_level || !pow(room_id, state.user_id) || pow(room_id, state.user_id) < events.rooms[room_id]['m.room.ops_levels'].content.redact_level"
+             ng-disabled="!room.current_room.state.state_events['m.room.ops_levels'].content.redact_level || !pow(room_id, state.user_id) || pow(room_id, state.user_id) < room.current_room.state.state_events['m.room.ops_levels'].content.redact_level"
              title="Delete this event on all home servers. This cannot be undone.">
                 Redact
             </button>        
@@ -18,7 +18,8 @@
             <table class="room-info">
             <tr ng-repeat="(key, event) in roomInfo.stateEvents" class="room-info-event">
                 <td class="room-info-event-meta" width="30%">
-                    <span class="monospace">{{ key }}</span>
+                    <span class="monospace">{{ event.type }}</span>
+                    <span ng-show="event.state_key" class="monospace"> ({{event.state_key}})</span>
                     <br/>
                     {{ (event.origin_server_ts) | date:'MMM d HH:mm' }}
                     <br/>
@@ -68,13 +69,13 @@
             </div>
 
             <div class="roomTopicSection">
-                <button ng-hide="events.rooms[room_id]['m.room.topic'].content.topic || topic.isEditing"
+                <button ng-hide="room.current_room_state.state_events['m.room.topic'].content.topic || topic.isEditing"
                     ng-click="topic.editTopic()" class="roomTopicSetNew">
                     Set Topic
                 </button>
-                <div ng-show="events.rooms[room_id]['m.room.topic'].content.topic || topic.isEditing">
+                <div ng-show="room.current_room_state.state_events['m.room.topic'].content.topic || topic.isEditing">
                     <div ng-hide="topic.isEditing" ng-dblclick="topic.editTopic()" id="roomTopic">
-                        {{ events.rooms[room_id]['m.room.topic'].content.topic | limitTo: 200}}
+                        {{ room.current_room_state.state_events['m.room.topic'].content.topic | limitTo: 200}}
                     </div>
                     <form ng-submit="topic.updateTopic()" ng-show="topic.isEditing" class="roomTopicForm">
                         <input ng-model="topic.newTopicText" ng-blur="topic.cancelEdit()" class="roomTopicInput"  placeholder="Topic"/>