mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-07 15:14:58 -04:00
Move room alias/id mapping logic from matrixService to modelService.
This commit is contained in:
parent
33e9e0fb2d
commit
9d0efedaee
7 changed files with 72 additions and 74 deletions
|
@ -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;
|
||||
},
|
||||
|
||||
};
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue