mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 05:00:20 +00:00
Renamed matrixService.assignRoomAliases into getRoomAliasAndDisplayName
This commit is contained in:
parent
722c19d033
commit
246b2a3c3e
3 changed files with 45 additions and 32 deletions
|
@ -420,34 +420,38 @@ angular.module('matrixService', [])
|
||||||
/****** Room aliases management ******/
|
/****** Room aliases management ******/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enhance data returned by rooms() and publicRooms() by adding room_alias
|
* Get the room_alias & room_display_name which are computed from data
|
||||||
* & room_display_name which are computed from data already retrieved from the server.
|
* already retrieved from the server.
|
||||||
* @param {Array} data the response of rooms() and publicRooms()
|
* @param {Room object} room one element of the array returned by the response
|
||||||
* @returns {Array} the same array with enriched objects
|
* of rooms() and publicRooms()
|
||||||
|
* @returns {Object} {room_alias: "...", room_display_name: "..."}
|
||||||
*/
|
*/
|
||||||
assignRoomAliases: function(data) {
|
getRoomAliasAndDisplayName: function(room) {
|
||||||
for (var i=0; i<data.length; i++) {
|
var result = {
|
||||||
var alias = this.getRoomIdToAliasMapping(data[i].room_id);
|
room_alias: undefined,
|
||||||
if (alias) {
|
room_display_name: undefined
|
||||||
// use the existing alias from storage
|
};
|
||||||
data[i].room_alias = alias;
|
|
||||||
data[i].room_display_name = alias;
|
var alias = this.getRoomIdToAliasMapping(room.room_id);
|
||||||
}
|
if (alias) {
|
||||||
else if (data[i].aliases && data[i].aliases[0]) {
|
// use the existing alias from storage
|
||||||
// save the mapping
|
result.room_alias = alias;
|
||||||
// TODO: select the smarter alias from the array
|
result.room_display_name = alias;
|
||||||
this.createRoomIdToAliasMapping(data[i].room_id, data[i].aliases[0]);
|
|
||||||
data[i].room_display_name = data[i].aliases[0];
|
|
||||||
}
|
|
||||||
else if (data[i].membership == "invite" && "inviter" in data[i]) {
|
|
||||||
data[i].room_display_name = data[i].inviter + "'s room"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// last resort use the room id
|
|
||||||
data[i].room_display_name = data[i].room_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return data;
|
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];
|
||||||
|
}
|
||||||
|
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) {
|
createRoomIdToAliasMapping: function(roomId, alias) {
|
||||||
|
|
|
@ -42,7 +42,13 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||||
|
|
||||||
matrixService.publicRooms().then(
|
matrixService.publicRooms().then(
|
||||||
function(response) {
|
function(response) {
|
||||||
$scope.public_rooms = matrixService.assignRoomAliases(response.data.chunk);
|
$scope.public_rooms = response.data.chunk;
|
||||||
|
for (var i = 0; i < $scope.public_rooms.length; i++) {
|
||||||
|
var room = $scope.public_rooms[i];
|
||||||
|
|
||||||
|
// Add room_alias & room_display_name members
|
||||||
|
angular.extend(room, matrixService.getRoomAliasAndDisplayName(room));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,13 +53,16 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
|
||||||
// Reset data
|
// Reset data
|
||||||
$scope.rooms = {};
|
$scope.rooms = {};
|
||||||
|
|
||||||
var data = matrixService.assignRoomAliases(response.data.rooms);
|
var rooms = response.data.rooms;
|
||||||
for (var i=0; i<data.length; i++) {
|
for (var i=0; i<rooms.length; i++) {
|
||||||
$scope.rooms[data[i].room_id] = data[i];
|
var room = rooms[i];
|
||||||
|
|
||||||
|
// Add room_alias & room_display_name members
|
||||||
|
$scope.rooms[room.room_id] = angular.extend(room, matrixService.getRoomAliasAndDisplayName(room));
|
||||||
|
|
||||||
// Create a shortcut for the last message of this room
|
// Create a shortcut for the last message of this room
|
||||||
if (data[i].messages && data[i].messages.chunk && data[i].messages.chunk[0]) {
|
if (room.messages && room.messages.chunk && room.messages.chunk[0]) {
|
||||||
$scope.rooms[data[i].room_id].lastMsg = data[i].messages.chunk[0];
|
$scope.rooms[room.room_id].lastMsg = room.messages.chunk[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue