diff options
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 46 | ||||
-rw-r--r-- | webclient/components/matrix/model-service.js | 10 | ||||
-rw-r--r-- | webclient/recents/recents-controller.js | 7 | ||||
-rw-r--r-- | webclient/recents/recents-filter.js | 16 | ||||
-rw-r--r-- | webclient/recents/recents.html | 12 |
5 files changed, 66 insertions, 25 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index dc00d83f33..9d33b6715e 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -86,18 +86,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } $rootScope.events.rooms[room_id].membership = room.membership; } - - // ========================================= - var __room = modelService.getRoom(room_id); - if (room) { // /initialSync data - __room.current_room_state.storeStateEvents(room.state); - __room.current_room_state.pagination_token = room.messages.end; - - __room.old_room_state.storeStateEvents(room.state); - __room.old_room_state.pagination_token = room.messages.start; - - $rootScope["debug_"+room_id] = __room; - } }; var resetRoomMessages = function(room_id) { @@ -621,12 +609,44 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var room = rooms[i]; this.initRoom(room); + + // FIXME: This is ming: the HS should be sending down the m.room.member + // event for the invite in .state but it isn't, so fudge it for now. + if (room.inviter && room.membership === "invite") { + var me = matrixService.config().user_id; + var fakeEvent = { + event_id: "__FAKE__" + room.room_id, + user_id: room.inviter, + origin_server_ts: 0, + room_id: room.room_id, + state_key: me, + type: "m.room.member", + content: { + membership: "invite" + } + }; + if (!room.state) { + room.state = []; + } + room.state.push(fakeEvent); + console.log("RECV /initialSync invite >> "+JSON.stringify(fakeEvent)); + } + + // ========================================= + var __room = modelService.getRoom(room.room_id); + __room.current_room_state.storeStateEvents(room.state); + __room.old_room_state.storeStateEvents(room.state); + + + if ("messages" in room) { this.handleRoomMessages(room.room_id, room.messages, false); + __room.current_room_state.pagination_token = room.messages.end; + __room.old_room_state.pagination_token = room.messages.start; } - if ("state" in room) { + if ("state" in room) { // TODO FIXME remove this. this.handleEvents(room.state, false, true); } } diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js index 26349f1461..ff6abfe422 100644 --- a/webclient/components/matrix/model-service.js +++ b/webclient/components/matrix/model-service.js @@ -100,9 +100,15 @@ angular.module('modelService', []) storeStateEvent: function storeState(event) { this.state_events[event.type + event.state_key] = event; + if (event.type === "m.room.member") { + this.members[event.state_key] = event; + } }, storeStateEvents: function storeState(events) { + if (!events) { + return; + } for (var i=0; i<events.length; i++) { this.storeStateEvent(events[i]); } @@ -138,6 +144,10 @@ angular.module('modelService', []) rooms[roomId] = new Room(roomId); } return rooms[roomId]; + }, + + getRooms: function() { + return rooms; } }; diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index ee8a41c366..6f0be18f1a 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -17,11 +17,14 @@ 'use strict'; angular.module('RecentsController', ['matrixService', 'matrixFilter']) -.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', - function($rootScope, $scope, eventHandlerService) { +.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', + function($rootScope, $scope, eventHandlerService, modelService) { // Expose the service to the view $scope.eventHandlerService = eventHandlerService; + + // retrieve all rooms and expose them + $scope.rooms = modelService.getRooms(); // $rootScope of the parent where the recents component is included can override this value // in order to highlight a specific room in the list diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index ef8d9897f7..cf0f53f37d 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -25,22 +25,30 @@ angular.module('RecentsController') // The key, room_id, is already in value objects var filtered = []; angular.forEach(rooms, function(room, room_id) { - + room.recent = {}; + var meEvent = room.current_room_state.state("m.room.member", user_id); // Show the room only if the user has joined it or has been invited // (ie, do not show it if he has been banned) var member = eventHandlerService.getMember(room_id, user_id); + room.recent.me = member; if (member && ("invite" === member.membership || "join" === member.membership)) { - + if ("invite" === member.membership) { + room.recent.inviter = member.user_id; + } // Count users here // TODO: Compute it directly in eventHandlerService - room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id); + room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id); filtered.push(room); } - else if ("invite" === room.membership) { + else if (meEvent && "invite" === meEvent.content.membership) { // The only information we have about the room is that the user has been invited filtered.push(room); } + else { + console.error("Dropping "+room.room_id); + } + }); // And time sort them diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index a52b215c7e..2a633ebe24 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -1,16 +1,16 @@ <div ng-controller="RecentsController"> <table class="recentsTable"> - <tbody ng-repeat="(index, room) in events.rooms | orderRecents" + <tbody ng-repeat="(index, room) in rooms | orderRecents" ng-click="goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) )" class="recentsRoom" ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}"> <tr> - <td ng-class="room['m.room.join_rules'].content.join_rule == 'public' ? 'recentsRoomName recentsPublicRoom' : 'recentsRoomName'"> + <td ng-class="room.current_room_state.state('m.room.join_rules').content.join_rule == 'public' ? 'recentsRoomName recentsPublicRoom' : 'recentsRoomName'"> {{ room.room_id | mRoomName }} </td> <td class="recentsRoomSummaryUsersCount"> <span ng-show="undefined !== room.numUsersInRoom"> - {{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }} + {{ room.recent.numUsersInRoom || '1' }} {{ room.recent.numUsersInRoom == 1 ? 'user' : 'users' }} </span> </td> <td class="recentsRoomSummaryTS"> @@ -27,11 +27,11 @@ <tr> <td colspan="3" class="recentsRoomSummary"> - <div ng-show="room.membership === 'invite'"> - {{ room.inviter | mUserDisplayName: room.room_id }} invited you + <div ng-show="room.recent.me.membership === 'invite'"> + {{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you </div> - <div ng-hide="room.membership === 'invite'" ng-switch="lastMsg.type"> + <div ng-hide="room.recent.me.membership === 'invite'" ng-switch="lastMsg.type"> <div ng-switch-when="m.room.member"> <span ng-switch="lastMsg.changedKey"> <span ng-switch-when="membership"> |