From 6bc1dc40208fd1c49591dbc8cb2b9a341b96f576 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 3 Nov 2014 11:44:39 +0000 Subject: Make recents[controller/filter/html] use modelService. This breaks functionality whilst both events.rooms and modelService are in use. --- webclient/recents/recents-controller.js | 7 +++++-- webclient/recents/recents-filter.js | 16 ++++++++++++---- webclient/recents/recents.html | 12 ++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'webclient/recents') 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 @@
- - -- cgit 1.5.1 From 92e2ff49853922a5e81ac67ccf1a95f2278d5415 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 3 Nov 2014 13:48:08 +0000 Subject: Fix bug which prevented room name invites appearing correctly. --- .../components/matrix/event-handler-service.js | 4 +- webclient/components/matrix/matrix-filter.js | 127 +++++++-------------- webclient/recents/recents.html | 2 +- 3 files changed, 47 insertions(+), 86 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 953ce839ea..a872e3f435 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -408,7 +408,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } } console.log("Unable to handle event type " + event.type); - console.log(JSON.stringify(event, undefined, 4)); + // console.log(JSON.stringify(event, undefined, 4)); break; } } @@ -475,7 +475,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService room.state = []; } room.state.push(fakeEvent); - console.log("RECV /initialSync invite >> "+JSON.stringify(fakeEvent)); + console.log("RECV /initialSync invite >> "+room.room_id); } // ========================================= diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js index e4b42a2edb..4d264e93f3 100644 --- a/webclient/components/matrix/matrix-filter.js +++ b/webclient/components/matrix/matrix-filter.js @@ -19,6 +19,8 @@ angular.module('matrixFilter', []) // Compute the room name according to information we have +// TODO: It would be nice if this was stateless and had no dependencies. That would +// make the business logic here a lot easier to see. .filter('mRoomName', ['$rootScope', 'matrixService', 'eventHandlerService', 'modelService', function($rootScope, matrixService, eventHandlerService, modelService) { return function(room_id) { @@ -29,93 +31,60 @@ function($rootScope, matrixService, eventHandlerService, modelService) { var alias = matrixService.getRoomIdToAliasMapping(room_id); var room = modelService.getRoom(room_id).current_room_state; - if (room) { - // Get name from room state date - var room_name_event = room.state("m.room.name"); + var room_name_event = room.state("m.room.name"); - // Determine if it is a public room - var isPublicRoom = false; - if (room.state("m.room.join_rules") && room.state("m.room.join_rules").content) { - isPublicRoom = ("public" === room.state("m.room.join_rules").content.join_rule); - } + // Determine if it is a public room + var isPublicRoom = false; + if (room.state("m.room.join_rules") && room.state("m.room.join_rules").content) { + isPublicRoom = ("public" === room.state("m.room.join_rules").content.join_rule); + } - if (room_name_event) { - roomName = room_name_event.content.name; - } - else if (alias) { - roomName = alias; - } - else if (room.members.length > 0 && !isPublicRoom) { // Do not rename public room + if (room_name_event) { + roomName = room_name_event.content.name; + } + else if (alias) { + roomName = alias; + } + else if (Object.keys(room.members).length > 0 && !isPublicRoom) { // Do not rename public room + var user_id = matrixService.config().user_id; - var user_id = matrixService.config().user_id; - // Else, build the name from its users - // Limit the room renaming to 1:1 room - if (2 === Object.keys(room.members).length) { - for (var i in room.members) { - if (!room.members.hasOwnProperty(i)) continue; - - var member = room.members[i]; - if (member.state_key !== user_id) { - roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key); - break; - } + // this is a "one to one" room and should have the name of the other user. + if (Object.keys(room.members).length === 2) { + for (var i in room.members) { + if (!room.members.hasOwnProperty(i)) continue; + + var member = room.members[i]; + if (member.state_key !== user_id) { + roomName = eventHandlerService.getUserDisplayName(room_id, member.state_key); + break; } } - else if (Object.keys(room.members).length <= 1) { - - var otherUserId; - - if (Object.keys(room.members)[0]) { - otherUserId = Object.keys(room.members)[0]; - // this could be an invite event (from event stream) - if (otherUserId === user_id && - room.members[user_id].content.membership === "invite") { - // this is us being invited to this room, so the - // *user_id* is the other user ID and not the state - // key. - otherUserId = room.members[user_id].user_id; - } + } + else if (Object.keys(room.members).length === 1) { + // this could be just us (self-chat) or could be the other person + // in a room if they have invited us to the room. Find out which. + var otherUserId = Object.keys(room.members)[0]; + if (otherUserId === user_id) { + // it's us, we may have been invited to this room or it could + // be a self chat. + if (room.members[otherUserId].content.membership === "invite") { + // someone invited us, use the right ID. + roomName = eventHandlerService.getUserDisplayName(room_id, room.members[otherUserId].user_id); } else { - // it's got to be an invite, or failing that a self-chat; - otherUserId = room.inviter || user_id; -/* - // XXX: This should all be unnecessary now thanks to using the /rooms//roomid API - - // The other member may be in the invite list, get all invited users - var invitedUserIDs = []; - - // XXX: *SURELY* we shouldn't have to trawl through the whole messages list to - // find invite - surely the other user should be in room.members with state invited? :/ --Matthew - for (var i in room.messages) { - var message = room.messages[i]; - if ("m.room.member" === message.type && "invite" === message.content.membership) { - // Filter out the current user - var member_id = message.state_key; - if (member_id === user_id) { - member_id = message.user_id; - } - if (member_id !== user_id) { - // Make sure there is no duplicate user - if (-1 === invitedUserIDs.indexOf(member_id)) { - invitedUserIDs.push(member_id); - } - } - } - } - - // For now, only 1:1 room needs to be renamed. It means only 1 invited user - if (1 === invitedUserIDs.length) { - otherUserId = invitedUserIDs[0]; - } -*/ + roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId); } - - // Get the user display name + } + else { // it isn't us, so use their name if we know it. roomName = eventHandlerService.getUserDisplayName(room_id, otherUserId); } } + else if (Object.keys(room.members).length === 0) { + // this shouldn't be possible + console.error("0 members in room >> " + room_id); + } } + // Always show the alias in the room displayed name if (roomName && alias && alias !== roomName) { @@ -125,14 +94,6 @@ function($rootScope, matrixService, eventHandlerService, modelService) { if (undefined === roomName) { // By default, use the room ID roomName = room_id; - - // XXX: this is *INCREDIBLY* heavy logging for a function that calls every single - // time any kind of digest runs which refreshes a room name... - // commenting it out for now. - - // Log some information that lead to this leak - // console.log("Room ID leak for " + room_id); - // console.log("room object: " + JSON.stringify(room, undefined, 4)); } return roomName; diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index a11e6be532..7297e23703 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -27,7 +27,7 @@
+ {{ room.room_id | mRoomName }} - {{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }} + {{ room.recent.numUsersInRoom || '1' }} {{ room.recent.numUsersInRoom == 1 ? 'user' : 'users' }} @@ -27,11 +27,11 @@
-
- {{ room.inviter | mUserDisplayName: room.room_id }} invited you +
+ {{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
-
+
-- cgit 1.5.1 From fd535183eed4b2262109f90a9f29fe9e49b4b9a0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 3 Nov 2014 12:18:22 +0000 Subject: Remove events.rooms[room_id] entirely from event-handler-service. Everything now uses modelService, but there are still one or two minor teething problems to fix. --- .../components/matrix/event-handler-service.js | 275 ++++----------------- webclient/components/matrix/model-service.js | 11 + webclient/home/home-controller.js | 1 - webclient/recents/recents-filter.js | 4 +- 4 files changed, 59 insertions(+), 232 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 9d33b6715e..00e3edf184 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -50,57 +50,28 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var reset = function() { initialSyncDeferred = $q.defer(); - - $rootScope.events = { - rooms: {} // will contain roomId: { messages:[], members:{userid1: event} } - }; - + $rootScope.presence = {}; eventMap = {}; }; reset(); - var initRoom = function(room_id, room) { - if (!(room_id in $rootScope.events.rooms)) { - console.log("Creating new rooms entry for " + room_id); - $rootScope.events.rooms[room_id] = { - room_id: room_id, - messages: [], - members: {}, - // Pagination information - pagination: { - earliest_token: "END" // how far back we've paginated - } - }; - } - - if (room) { // we got an existing room object from initialsync, seemingly. - // Report all other metadata of the room object (membership, inviter, visibility, ...) - for (var field in room) { - if (!room.hasOwnProperty(field)) continue; - - if (-1 === ["room_id", "messages", "state"].indexOf(field)) { // why indexOf - why not ===? --Matthew - $rootScope.events.rooms[room_id][field] = room[field]; - } - } - $rootScope.events.rooms[room_id].membership = room.membership; - } - }; - var resetRoomMessages = function(room_id) { - if ($rootScope.events.rooms[room_id]) { - $rootScope.events.rooms[room_id].messages = []; - } + var room = modelService.getRoom(room_id); + room.events = []; }; // Generic method to handle events data - var handleRoomDateEvent = function(event, isLiveEvent, addToRoomMessages) { + var handleRoomStateEvent = function(event, isLiveEvent, addToRoomMessages) { var __room = modelService.getRoom(event.room_id); if (addToRoomMessages) { + // some state events are displayed as messages, so add them. __room.addMessageEvent(event, !isLiveEvent); } + if (isLiveEvent) { + // update the current room state with the latest state __room.current_room_state.storeStateEvent(event); } else { @@ -113,39 +84,10 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } } } - - // ===================================== - - // 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.origin_server_ts; - var storedEvent = $rootScope.events.rooms[event.room_id][event.type]; - if (storedEvent) { - if (storedEvent.origin_server_ts > eventTs) { - // ignore it, we have a newer one already. - latestData = false; - } - } - } - if (latestData) { - $rootScope.events.rooms[event.room_id][event.type] = event; - } + // TODO: handle old_room_state }; 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); }; @@ -183,7 +125,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService if (shouldBing && isIdle) { console.log("Displaying notification for "+JSON.stringify(event)); - var member = getMember(event.room_id, event.user_id); + var member = modelService.getMember(event.room_id, event.user_id); var displayname = getUserDisplayName(event.room_id, event.user_id); var message = event.content.body; @@ -195,9 +137,9 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } var roomTitle = matrixService.getRoomIdToAliasMapping(event.room_id); - var theRoom = $rootScope.events.rooms[event.room_id]; - if (!roomTitle && theRoom && theRoom["m.room.name"] && theRoom["m.room.name"].content) { - roomTitle = theRoom["m.room.name"].content.name; + var theRoom = modelService.getRoom(event.room_id); + if (!roomTitle && theRoom.current_room_state.state("m.room.name") && theRoom.current_room_state.state("m.room.name").content) { + roomTitle = theRoom.current_room_state.state("m.room.name").content.name; } if (!roomTitle) { @@ -235,6 +177,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService if (event.user_id !== matrixService.config().user_id) { __room.addMessageEvent(event, !isLiveEvent); + displayNotification(event); } else { // we may have locally echoed this, so we should replace the event @@ -242,37 +185,8 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService __room.addOrReplaceMessageEvent(event, !isLiveEvent); } - // ======================= - - if (isLiveEvent) { - if (event.user_id === matrixService.config().user_id && - (event.content.msgtype === "m.text" || event.content.msgtype === "m.emote") ) { - // Assume we've already echoed it. So, there is a fake event in the messages list of the room - // Replace this fake event by the true one - var index = getRoomEventIndex(event.room_id, event.event_id); - if (index) { - $rootScope.events.rooms[event.room_id].messages[index] = event; - } - else { - $rootScope.events.rooms[event.room_id].messages.push(event); - } - } - else { - $rootScope.events.rooms[event.room_id].messages.push(event); - displayNotification(event); - } - - - } - else { - $rootScope.events.rooms[event.room_id].messages.unshift(event); - } - // TODO send delivery receipt if isLiveEvent - // $broadcast this, as controllers may want to do funky things such as - // scroll to the bottom, etc which cannot be expressed via simple $scope - // updates. $rootScope.$broadcast(MSG_EVENT, event, isLiveEvent); }; @@ -284,6 +198,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // Exception: Do not do this if the event is a room state event because such events already come // as room messages events. Moreover, when they come as room messages events, they are relatively ordered // with other other room messages + // FIXME this isn't true anymore, work out what this is doing. if (!isStateEvent) { // could be a membership change, display name change, etc. // Find out which one. @@ -301,14 +216,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // If there was a change we want to display, dump it in the message // list. if (memberChanges) { - if (isLiveEvent) { - $rootScope.events.rooms[event.room_id].messages.push(event); - } - else { - $rootScope.events.rooms[event.room_id].messages.unshift(event); - } - // ============ - __room.addMessageEvent(event, !isLiveEvent); } } @@ -316,7 +223,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // Use data from state event or the latest data from the stream. // 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; } @@ -329,30 +235,28 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService }; var handlePowerLevels = function(event, isLiveEvent) { - // Keep the latest data. Do not care of events that come when paginating back - if (!$rootScope.events.rooms[event.room_id][event.type] || isLiveEvent) { - $rootScope.events.rooms[event.room_id][event.type] = event; - $rootScope.$broadcast(POWERLEVEL_EVENT, event, isLiveEvent); - } + handleRoomStateEvent(event, isLiveEvent); + $rootScope.$broadcast(POWERLEVEL_EVENT, event, isLiveEvent); }; var handleRoomName = function(event, isLiveEvent, isStateEvent) { console.log("handleRoomName room_id: " + event.room_id + " - isLiveEvent: " + isLiveEvent + " - name: " + event.content.name); - handleRoomDateEvent(event, isLiveEvent, !isStateEvent); + handleRoomStateEvent(event, isLiveEvent, !isStateEvent); $rootScope.$broadcast(NAME_EVENT, event, isLiveEvent); }; var handleRoomTopic = function(event, isLiveEvent, isStateEvent) { console.log("handleRoomTopic room_id: " + event.room_id + " - isLiveEvent: " + isLiveEvent + " - topic: " + event.content.topic); - handleRoomDateEvent(event, isLiveEvent, !isStateEvent); + handleRoomStateEvent(event, isLiveEvent, !isStateEvent); $rootScope.$broadcast(TOPIC_EVENT, event, isLiveEvent); }; var handleCallEvent = function(event, isLiveEvent) { $rootScope.$broadcast(CALL_EVENT, event, isLiveEvent); if (event.type === 'm.call.invite') { - $rootScope.events.rooms[event.room_id].messages.push(event); + var __room = modelService.getRoom(event.room_id); + __room.addMessageEvent(event, !isLiveEvent); } }; @@ -366,8 +270,9 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // we need to remove something possibly: do we know the redacted // event ID? if (eventMap[event.redacts]) { + var __room = modelService.getRoom(event.room_id); // remove event from list of messages in this room. - var eventList = $rootScope.events.rooms[event.room_id].messages; + var eventList = __room.events; for (var i=0; i 0; i--) { - var message = room.messages[i]; - if (event_id === message.event_id) { - index = i; - break; - } - } - } - return index; - }; - - /** - * Get the member object of a room member - * @param {String} room_id the room id - * @param {String} user_id the id of the user - * @returns {undefined | Object} the member object of this user in this room if he is part of the room - */ - var getMember = function(room_id, user_id) { - var member; - - var room = $rootScope.events.rooms[room_id]; - if (room) { - member = room.members[user_id]; - } - return member; - }; /** * Return the display name of an user acccording to data already downloaded @@ -431,17 +295,17 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var displayName; // Get the user display name from the member list of the room - var member = getMember(room_id, user_id); + var member = modelService.getMember(room_id, user_id); if (member && member.content.displayname) { // Do not consider null displayname displayName = member.content.displayname; // Disambiguate users who have the same displayname in the room if (user_id !== matrixService.config().user_id) { - var room = $rootScope.events.rooms[room_id]; + var room = modelService.getRoom(room_id); - for (var member_id in room.members) { - if (room.members.hasOwnProperty(member_id) && member_id !== user_id) { - var member2 = room.members[member_id]; + for (var member_id in room.current_room_state.members) { + if (room.current_room_state.members.hasOwnProperty(member_id) && member_id !== user_id) { + var member2 = room.current_room_state.members[member_id]; if (member2.content.displayname && member2.content.displayname === displayName) { displayName = displayName + " (" + user_id + ")"; break; @@ -479,19 +343,9 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService reset(); $rootScope.$broadcast(RESET_EVENT); }, - - initRoom: function(room) { - initRoom(room.room_id, room); - }, handleEvent: function(event, isLiveEvent, isStateEvent) { - // FIXME: /initialSync on a particular room is not yet available - // So initRoom on a new room is not called. Make sure the room data is initialised here - if (event.room_id) { - initRoom(event.room_id); - } - // Avoid duplicated events // Needed for rooms where initialSync has not been done. // In this case, we do not know where to start pagination. So, it starts from the END @@ -550,7 +404,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // displays on the Room Info screen. if (typeof(event.state_key) === "string") { // incls. 0-len strings if (event.room_id) { - handleRoomDateEvent(event, isLiveEvent, false); + handleRoomStateEvent(event, isLiveEvent, false); } } console.log("Unable to handle event type " + event.type); @@ -570,8 +424,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // Handle messages from /initialSync or /messages handleRoomMessages: function(room_id, messages, isLiveEvents, dir) { - initRoom(room_id); - var events = messages.chunk; // Handles messages according to their time order @@ -582,8 +434,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService } // Store how far back we've paginated - $rootScope.events.rooms[room_id].pagination.earliest_token = messages.end; - var __room = modelService.getRoom(room_id); __room.old_room_state.pagination_token = messages.end; @@ -594,8 +444,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService this.handleEvent(events[i], isLiveEvents, isLiveEvents); } // Store where to start pagination - $rootScope.events.rooms[room_id].pagination.earliest_token = messages.start; - var __room = modelService.getRoom(room_id); __room.old_room_state.pagination_token = messages.start; } @@ -607,8 +455,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var rooms = response.data.rooms; for (var i = 0; i < rooms.length; ++i) { 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. @@ -636,9 +482,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService 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); @@ -674,15 +517,13 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService getLastMessage: function(room_id, filterEcho) { var lastMessage; - var room = $rootScope.events.rooms[room_id]; - if (room) { - for (var i = room.messages.length - 1; i >= 0; i--) { - var message = room.messages[i]; + var events = modelService.getRoom(room_id).events; + for (var i = events.length - 1; i >= 0; i--) { + var message = events[i]; - if (!filterEcho || undefined === message.echo_msg_state) { - lastMessage = message; - break; - } + if (!filterEcho || undefined === message.echo_msg_state) { + lastMessage = message; + break; } } @@ -697,34 +538,22 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService getUsersCountInRoom: function(room_id) { var memberCount; - var room = $rootScope.events.rooms[room_id]; - if (room) { - memberCount = 0; + var room = modelService.getRoom(room_id); + memberCount = 0; - for (var i in room.members) { - if (!room.members.hasOwnProperty(i)) continue; + for (var i in room.current_room_state.members) { + if (!room.current_room_state.members.hasOwnProperty(i)) continue; - var member = room.members[i]; + var member = room.current_room_state.members[i]; - if ("join" === member.membership) { - memberCount = memberCount + 1; - } + if ("join" === member.membership) { + memberCount = memberCount + 1; } } return memberCount; }, - /** - * Get the member object of a room member - * @param {String} room_id the room id - * @param {String} user_id the id of the user - * @returns {undefined | Object} the member object of this user in this room if he is part of the room - */ - getMember: function(room_id, user_id) { - return getMember(room_id, user_id); - }, - /** * Return the power level of an user in a particular room * @param {String} room_id the room id @@ -733,14 +562,14 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService */ getUserPowerLevel: function(room_id, user_id) { var powerLevel = 0; - var room = $rootScope.events.rooms[room_id]; - if (room && room["m.room.power_levels"]) { - if (user_id in room["m.room.power_levels"].content) { - powerLevel = room["m.room.power_levels"].content[user_id]; + var room = modelService.getRoom(room_id).current_room_state; + if (room.state("m.room.power_levels")) { + if (user_id in room.state("m.room.power_levels").content) { + powerLevel = room.state("m.room.power_levels").content[user_id]; } else { // Use the room default user power - powerLevel = room["m.room.power_levels"].content["default"]; + powerLevel = room.state("m.room.power_levels").content["default"]; } } return powerLevel; @@ -754,18 +583,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService */ getUserDisplayName: function(room_id, user_id) { return getUserDisplayName(room_id, user_id); - }, - - setRoomVisibility: function(room_id, visible) { - if (!visible) { - return; - } - initRoom(room_id); - - var room = $rootScope.events.rooms[room_id]; - if (room) { - room.visibility = visible; - } } }; }]); diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js index ff6abfe422..d5acd7eda9 100644 --- a/webclient/components/matrix/model-service.js +++ b/webclient/components/matrix/model-service.js @@ -148,6 +148,17 @@ angular.module('modelService', []) getRooms: function() { return rooms; + }, + + /** + * Get the member object of a room member + * @param {String} room_id the room id + * @param {String} user_id the id of the user + * @returns {undefined | Object} the member object of this user in this room if he is part of the room + */ + getMember: function(room_id, user_id) { + var room = this.getRoom(room_id); + return room.current_room_state.members[user_id]; } }; diff --git a/webclient/home/home-controller.js b/webclient/home/home-controller.js index f1295560ef..3a48e64ab4 100644 --- a/webclient/home/home-controller.js +++ b/webclient/home/home-controller.js @@ -58,7 +58,6 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen // Add room_alias & room_display_name members angular.extend(room, matrixService.getRoomAliasAndDisplayName(room)); - eventHandlerService.setRoomVisibility(room.room_id, "public"); } } ); diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index cf0f53f37d..acd9f86ece 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -17,7 +17,7 @@ 'use strict'; angular.module('RecentsController') -.filter('orderRecents', ["matrixService", "eventHandlerService", function(matrixService, eventHandlerService) { +.filter('orderRecents', ["matrixService", "eventHandlerService", "modelService", function(matrixService, eventHandlerService, modelService) { return function(rooms) { var user_id = matrixService.config().user_id; @@ -29,7 +29,7 @@ angular.module('RecentsController') 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); + var member = modelService.getMember(room_id, user_id); room.recent.me = member; if (member && ("invite" === member.membership || "join" === member.membership)) { if ("invite" === member.membership) { -- cgit 1.5.1 From 9b1ca64a75160b44106d5a7b4ddc96a009f56012 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 3 Nov 2014 13:26:50 +0000 Subject: Fix bug which prevented the number of users being visible on the recents view. --- webclient/components/matrix/event-handler-service.js | 3 +-- webclient/recents/recents-filter.js | 4 ++-- webclient/recents/recents.html | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 00e3edf184..953ce839ea 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -540,13 +540,12 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var room = modelService.getRoom(room_id); memberCount = 0; - for (var i in room.current_room_state.members) { if (!room.current_room_state.members.hasOwnProperty(i)) continue; var member = room.current_room_state.members[i]; - if ("join" === member.membership) { + if ("join" === member.content.membership) { memberCount = memberCount + 1; } } diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index acd9f86ece..db7fc5e4ee 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -31,8 +31,8 @@ angular.module('RecentsController') // (ie, do not show it if he has been banned) var member = modelService.getMember(room_id, user_id); room.recent.me = member; - if (member && ("invite" === member.membership || "join" === member.membership)) { - if ("invite" === member.membership) { + if (member && ("invite" === member.content.membership || "join" === member.content.membership)) { + if ("invite" === member.content.membership) { room.recent.inviter = member.user_id; } // Count users here diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 2a633ebe24..a11e6be532 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -9,7 +9,7 @@ {{ room.room_id | mRoomName }}
- + {{ room.recent.numUsersInRoom || '1' }} {{ room.recent.numUsersInRoom == 1 ? 'user' : 'users' }}
-
+
{{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
-- cgit 1.5.1 From f3dbcdc7b31f693096407f9bfad0f7c2aa9b66c5 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 3 Nov 2014 15:17:32 +0000 Subject: Variable renaming, general cleanup. Don't feed state events from /initialSync twice. --- .../components/matrix/event-handler-service.js | 61 ++++++++++------------ webclient/recents/recents-filter.js | 6 +-- 2 files changed, 29 insertions(+), 38 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index a872e3f435..7f53429754 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -22,9 +22,8 @@ not care where the event came from, it only needs enough context to be able to process them. Events may be coming from the event stream, the REST API (via direct GETs or via a pagination stream API), etc. -Typically, this service will store events or broadcast them to any listeners -(e.g. controllers) via $broadcast. Alternatively, it may update the $rootScope -if typically all the $on method would do is update its own $scope. +Typically, this service will store events and broadcast them to any listeners +(e.g. controllers) via $broadcast. */ angular.module('eventHandlerService', []) .factory('eventHandlerService', ['matrixService', '$rootScope', '$q', '$timeout', 'mPresence', 'notificationService', 'modelService', @@ -44,6 +43,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // of the app, given we never try to reap memory yet) var eventMap = {}; + // TODO: Remove this and replace with modelService.User objects. $rootScope.presence = {}; var initialSyncDeferred; @@ -64,23 +64,23 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // Generic method to handle events data var handleRoomStateEvent = function(event, isLiveEvent, addToRoomMessages) { - var __room = modelService.getRoom(event.room_id); + var room = modelService.getRoom(event.room_id); if (addToRoomMessages) { // some state events are displayed as messages, so add them. - __room.addMessageEvent(event, !isLiveEvent); + room.addMessageEvent(event, !isLiveEvent); } if (isLiveEvent) { // update the current room state with the latest state - __room.current_room_state.storeStateEvent(event); + room.current_room_state.storeStateEvent(event); } else { var eventTs = event.origin_server_ts; - var storedEvent = __room.current_room_state.getStateEvent(event.type, event.state_key); + var storedEvent = room.current_room_state.getStateEvent(event.type, event.state_key); if (storedEvent) { if (storedEvent.origin_server_ts < eventTs) { // the incoming event is newer, use it. - __room.current_room_state.storeStateEvent(event); + room.current_room_state.storeStateEvent(event); } } } @@ -173,16 +173,16 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // ======================= - var __room = modelService.getRoom(event.room_id); + var room = modelService.getRoom(event.room_id); if (event.user_id !== matrixService.config().user_id) { - __room.addMessageEvent(event, !isLiveEvent); + room.addMessageEvent(event, !isLiveEvent); displayNotification(event); } else { // we may have locally echoed this, so we should replace the event // instead of just adding. - __room.addOrReplaceMessageEvent(event, !isLiveEvent); + room.addOrReplaceMessageEvent(event, !isLiveEvent); } // TODO send delivery receipt if isLiveEvent @@ -191,7 +191,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService }; var handleRoomMember = function(event, isLiveEvent, isStateEvent) { - var __room = modelService.getRoom(event.room_id); + var room = modelService.getRoom(event.room_id); // add membership changes as if they were a room message if something interesting changed @@ -216,14 +216,14 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // If there was a change we want to display, dump it in the message // list. if (memberChanges) { - __room.addMessageEvent(event, !isLiveEvent); + room.addMessageEvent(event, !isLiveEvent); } } // Use data from state event or the latest data from the stream. // Do not care of events that come when paginating back if (isStateEvent || isLiveEvent) { - __room.current_room_state.members[event.state_key] = event; + room.current_room_state.members[event.state_key] = event; } $rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent, isStateEvent); @@ -255,8 +255,8 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService var handleCallEvent = function(event, isLiveEvent) { $rootScope.$broadcast(CALL_EVENT, event, isLiveEvent); if (event.type === 'm.call.invite') { - var __room = modelService.getRoom(event.room_id); - __room.addMessageEvent(event, !isLiveEvent); + var room = modelService.getRoom(event.room_id); + room.addMessageEvent(event, !isLiveEvent); } }; @@ -270,9 +270,9 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService // we need to remove something possibly: do we know the redacted // event ID? if (eventMap[event.redacts]) { - var __room = modelService.getRoom(event.room_id); + var room = modelService.getRoom(event.room_id); // remove event from list of messages in this room. - var eventList = __room.events; + var eventList = room.events; for (var i=0; i> "+room.room_id); } - // ========================================= - var __room = modelService.getRoom(room.room_id); - __room.current_room_state.storeStateEvents(room.state); - __room.old_room_state.storeStateEvents(room.state); + var newRoom = modelService.getRoom(room.room_id); + newRoom.current_room_state.storeStateEvents(room.state); + newRoom.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) { // TODO FIXME remove this. - this.handleEvents(room.state, false, true); + newRoom.current_room_state.pagination_token = room.messages.end; + newRoom.old_room_state.pagination_token = room.messages.start; } } var presence = response.data.presence; diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index db7fc5e4ee..39c2359967 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -45,14 +45,10 @@ angular.module('RecentsController') // 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 - // The room with the lastest message at first + // The room with the latest message at first filtered.sort(function (roomA, roomB) { var lastMsgRoomA = eventHandlerService.getLastMessage(roomA.room_id, true); -- cgit 1.5.1