mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Renamed matrixService.assignRoomAliases into getRoomAliasAndDisplayName
This commit is contained in:
parent
722c19d033
commit
246b2a3c3e
@ -420,34 +420,38 @@ angular.module('matrixService', [])
|
||||
/****** Room aliases management ******/
|
||||
|
||||
/**
|
||||
* Enhance data returned by rooms() and publicRooms() by adding room_alias
|
||||
* & room_display_name which are computed from data already retrieved from the server.
|
||||
* @param {Array} data the response of rooms() and publicRooms()
|
||||
* @returns {Array} the same array with enriched objects
|
||||
* 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: "..."}
|
||||
*/
|
||||
assignRoomAliases: function(data) {
|
||||
for (var i=0; i<data.length; i++) {
|
||||
var alias = this.getRoomIdToAliasMapping(data[i].room_id);
|
||||
if (alias) {
|
||||
// use the existing alias from storage
|
||||
data[i].room_alias = alias;
|
||||
data[i].room_display_name = alias;
|
||||
}
|
||||
else if (data[i].aliases && data[i].aliases[0]) {
|
||||
// save the mapping
|
||||
// TODO: select the smarter alias from the array
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
|
@ -42,7 +42,13 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||
|
||||
matrixService.publicRooms().then(
|
||||
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
|
||||
$scope.rooms = {};
|
||||
|
||||
var data = matrixService.assignRoomAliases(response.data.rooms);
|
||||
for (var i=0; i<data.length; i++) {
|
||||
$scope.rooms[data[i].room_id] = data[i];
|
||||
var rooms = response.data.rooms;
|
||||
for (var i=0; i<rooms.length; 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
|
||||
if (data[i].messages && data[i].messages.chunk && data[i].messages.chunk[0]) {
|
||||
$scope.rooms[data[i].room_id].lastMsg = data[i].messages.chunk[0];
|
||||
if (room.messages && room.messages.chunk && room.messages.chunk[0]) {
|
||||
$scope.rooms[room.room_id].lastMsg = room.messages.chunk[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user