diff options
Diffstat (limited to 'webclient/components')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 23 | ||||
-rw-r--r-- | webclient/components/matrix/event-stream-service.js | 1 | ||||
-rw-r--r-- | webclient/components/matrix/matrix-service.js | 19 |
3 files changed, 40 insertions, 3 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index ee478d2eb0..9732aedfdc 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -66,11 +66,21 @@ angular.module('eventHandlerService', []) $rootScope.$broadcast(ROOM_CREATE_EVENT, event, isLiveEvent); }; + var handleRoomAliases = function(event, isLiveEvent) { + matrixService.createRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); + }; + var handleMessage = function(event, isLiveEvent) { initRoom(event.room_id); if (isLiveEvent) { - $rootScope.events.rooms[event.room_id].messages.push(event); + if (event.user_id === matrixService.config().user_id) { + // assume we've already echoed it + // FIXME: track events by ID and ungrey the right message to show it's been delivered + } + else { + $rootScope.events.rooms[event.room_id].messages.push(event); + } } else { $rootScope.events.rooms[event.room_id].messages.unshift(event); @@ -87,6 +97,14 @@ angular.module('eventHandlerService', []) var handleRoomMember = function(event, isLiveEvent) { initRoom(event.room_id); + // if the server is stupidly re-relaying a no-op join, discard it. + if (event.prev_content && + event.content.membership === "join" && + event.content.membership === event.prev_content.membership) + { + return; + } + // add membership changes as if they were a room message if something interesting changed if (event.content.prev !== event.content.membership) { if (isLiveEvent) { @@ -144,6 +162,9 @@ angular.module('eventHandlerService', []) case "m.room.create": handleRoomCreate(event, isLiveEvent); break; + case "m.room.aliases": + handleRoomAliases(event, isLiveEvent); + break; case "m.room.message": handleMessage(event, isLiveEvent); break; diff --git a/webclient/components/matrix/event-stream-service.js b/webclient/components/matrix/event-stream-service.js index 1c0f7712b4..ed4f3b2ffc 100644 --- a/webclient/components/matrix/event-stream-service.js +++ b/webclient/components/matrix/event-stream-service.js @@ -110,6 +110,7 @@ angular.module('eventStreamService', []) var rooms = response.data.rooms; for (var i = 0; i < rooms.length; ++i) { var room = rooms[i]; + // console.log("got room: " + room.room_id); if ("state" in room) { eventHandlerService.handleEvents(room.state, false); } diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index b7e03657f0..a1b9691f05 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -36,6 +36,9 @@ angular.module('matrixService', []) */ var config; + var roomIdToAlias = {}; + var aliasToRoomId = {}; + // Current version of permanent storage var configVersion = 0; var prefixPath = "/_matrix/client/api/v1"; @@ -529,6 +532,8 @@ angular.module('matrixService', []) result.room_alias = alias; result.room_display_name = alias; } + // XXX: this only lets us learn aliases from our local HS - we should + // make the client stop returning this if we can trust m.room.aliases state events else if (room.aliases && room.aliases[0]) { // save the mapping // TODO: select the smarter alias from the array @@ -546,13 +551,23 @@ angular.module('matrixService', []) }, createRoomIdToAliasMapping: function(roomId, alias) { - localStorage.setItem(MAPPING_PREFIX+roomId, alias); + //console.log("creating mapping between " + roomId + " and " + alias); + roomIdToAlias[roomId] = alias; + aliasToRoomId[alias] = roomId; + // localStorage.setItem(MAPPING_PREFIX+roomId, alias); }, getRoomIdToAliasMapping: function(roomId) { - return localStorage.getItem(MAPPING_PREFIX+roomId); + var alias = roomIdToAlias[roomId]; // was localStorage.getItem(MAPPING_PREFIX+roomId) + //console.log("looking for alias for " + roomId + "; found: " + alias); + return alias; }, + getAliasToRoomIdMapping: function(alias) { + var roomId = aliasToRoomId[alias]; + //console.log("looking for roomId for " + alias + "; found: " + roomId); + return roomId; + }, /****** Power levels management ******/ |