Skip to content
Snippets Groups Projects
Commit 246b2a3c authored by Emmanuel ROHEE's avatar Emmanuel ROHEE
Browse files

Renamed matrixService.assignRoomAliases into getRoomAliasAndDisplayName

parent 722c19d0
Branches
Tags
No related merge requests found
...@@ -420,34 +420,38 @@ angular.module('matrixService', []) ...@@ -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 (room.aliases && room.aliases[0]) {
} // save the mapping
else if (data[i].membership == "invite" && "inviter" in data[i]) { // TODO: select the smarter alias from the array
data[i].room_display_name = data[i].inviter + "'s room" this.createRoomIdToAliasMapping(room.room_id, room.aliases[0]);
} result.room_display_name = room.aliases[0];
else { }
// last resort use the room id else if (room.membership === "invite" && "inviter" in room) {
data[i].room_display_name = data[i].room_id; result.room_display_name = room.inviter + "'s room";
} }
else {
// last resort use the room id
result.room_display_name = room.room_id;
} }
return data; return result;
}, },
createRoomIdToAliasMapping: function(roomId, alias) { createRoomIdToAliasMapping: function(roomId, alias) {
......
...@@ -42,7 +42,13 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen ...@@ -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']) ...@@ -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];
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment