diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-11-12 11:14:19 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-11-12 11:14:19 +0000 |
commit | 9d0efedaee1e522e0fbc1300aee0c27e3ebf3eae (patch) | |
tree | c31d39a5c4f1f8a44693514a061f2028623bc6fb /syweb/webclient/components | |
parent | move model/ into matrix-doc/drafts (diff) | |
download | synapse-9d0efedaee1e522e0fbc1300aee0c27e3ebf3eae.tar.xz |
Move room alias/id mapping logic from matrixService to modelService.
Diffstat (limited to 'syweb/webclient/components')
4 files changed, 61 insertions, 63 deletions
diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js index f51031f4cd..7b2a75507d 100644 --- a/syweb/webclient/components/matrix/event-handler-service.js +++ b/syweb/webclient/components/matrix/event-handler-service.js @@ -92,7 +92,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati }; var handleRoomAliases = function(event, isLiveEvent) { - matrixService.createRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); + modelService.createRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); }; var displayNotification = function(event) { diff --git a/syweb/webclient/components/matrix/matrix-filter.js b/syweb/webclient/components/matrix/matrix-filter.js index 69de97b055..20a29c4ab1 100644 --- a/syweb/webclient/components/matrix/matrix-filter.js +++ b/syweb/webclient/components/matrix/matrix-filter.js @@ -28,7 +28,7 @@ function($rootScope, matrixService, eventHandlerService, modelService) { // If there is an alias, use it // TODO: only one alias is managed for now - var alias = matrixService.getRoomIdToAliasMapping(room_id); + var alias = modelService.getRoomIdToAliasMapping(room_id); var room = modelService.getRoom(room_id).current_room_state; var room_name_event = room.state("m.room.name"); diff --git a/syweb/webclient/components/matrix/matrix-service.js b/syweb/webclient/components/matrix/matrix-service.js index 63051c4f47..70747155f9 100644 --- a/syweb/webclient/components/matrix/matrix-service.js +++ b/syweb/webclient/components/matrix/matrix-service.js @@ -36,9 +36,6 @@ angular.module('matrixService', []) */ var config; - var roomIdToAlias = {}; - var aliasToRoomId = {}; - // Current version of permanent storage var configVersion = 0; var prefixPath = "/_matrix/client/api/v1"; @@ -671,63 +668,6 @@ angular.module('matrixService', []) config.version = configVersion; localStorage.setItem("config", JSON.stringify(config)); }, - - - /****** Room aliases management ******/ - - /** - * Get the room_alias & room_display_name which are computed from data - * already retrieved from the server. - * @param {Room object} room one element of the array returned by the response - * of rooms() and publicRooms() - * @returns {Object} {room_alias: "...", room_display_name: "..."} - */ - getRoomAliasAndDisplayName: function(room) { - var result = { - room_alias: undefined, - room_display_name: undefined - }; - var alias = this.getRoomIdToAliasMapping(room.room_id); - if (alias) { - // use the existing alias from storage - 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 - this.createRoomIdToAliasMapping(room.room_id, room.aliases[0]); - result.room_display_name = room.aliases[0]; - result.room_alias = room.aliases[0]; - } - else if (room.membership === "invite" && "inviter" in room) { - result.room_display_name = room.inviter + "'s room"; - } - else { - // last resort use the room id - result.room_display_name = room.room_id; - } - return result; - }, - - createRoomIdToAliasMapping: function(roomId, alias) { - roomIdToAlias[roomId] = alias; - aliasToRoomId[alias] = roomId; - }, - - getRoomIdToAliasMapping: function(roomId) { - var alias = roomIdToAlias[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; - }, /** * Change or reset the power level of a user diff --git a/syweb/webclient/components/matrix/model-service.js b/syweb/webclient/components/matrix/model-service.js index 8e0ce8d1a9..c6f0defb61 100644 --- a/syweb/webclient/components/matrix/model-service.js +++ b/syweb/webclient/components/matrix/model-service.js @@ -27,6 +27,10 @@ dependency. // $rootScope. angular.module('modelService', []) .factory('modelService', ['matrixService', function(matrixService) { + + // alias / id lookups + var roomIdToAlias = {}; + var aliasToRoomId = {}; /***** Room Object *****/ var Room = function Room(room_id) { @@ -166,7 +170,61 @@ angular.module('modelService', []) getMember: function(room_id, user_id) { var room = this.getRoom(room_id); return room.current_room_state.members[user_id]; - } + }, + + /** + * Get the room_alias & room_display_name which are computed from data + * already retrieved from the server. + * @param {Room object} room one element of the array returned by the response + * of rooms() and publicRooms() + * @returns {Object} {room_alias: "...", room_display_name: "..."} + */ + getRoomAliasAndDisplayName: function(room) { + var result = { + room_alias: undefined, + room_display_name: undefined + }; + var alias = this.getRoomIdToAliasMapping(room.room_id); + if (alias) { + // use the existing alias from storage + 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 + this.createRoomIdToAliasMapping(room.room_id, room.aliases[0]); + result.room_display_name = room.aliases[0]; + result.room_alias = room.aliases[0]; + } + else if (room.membership === "invite" && "inviter" in room) { + result.room_display_name = room.inviter + "'s room"; + } + else { + // last resort use the room id + result.room_display_name = room.room_id; + } + return result; + }, + + createRoomIdToAliasMapping: function(roomId, alias) { + roomIdToAlias[roomId] = alias; + aliasToRoomId[alias] = roomId; + }, + + getRoomIdToAliasMapping: function(roomId) { + var alias = roomIdToAlias[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; + }, }; }]); |