Added roomName, a directive to compute a room name based on its alias (not aliases for now) and its users displaynames or ids

This commit is contained in:
Emmanuel ROHEE 2014-09-01 18:50:39 +02:00
parent 99ce820cc8
commit 7d99cee3ef
4 changed files with 45 additions and 5 deletions

View File

@ -79,4 +79,43 @@ angular.module('matrixWebClient')
return function(text) { return function(text) {
return $sce.trustAsHtml(text); return $sce.trustAsHtml(text);
}; };
}])
// Compute the room name according to information we have
.filter('roomName', ['$rootScope', 'matrixService', function($rootScope, matrixService) {
return function(room_id) {
var roomName;
// If there is an alias, use it
// TODO: only one alias is managed for now
var alias = matrixService.getRoomIdToAliasMapping(room_id);
if (alias) {
roomName = alias;
}
if (undefined === roomName) {
// Else, build the name from its users
var room = $rootScope.events.rooms[room_id];
if (room) {
if (room.members) {
// Limit the room renaming to 1:1 room
if (2 === Object.keys(room.members).length) {
for (var i in room.members) {
var member = room.members[i];
if (member.user_id !== matrixService.config().user_id) {
roomName = member.content.displayname ? member.content.displayname : member.user_id;
}
}
}
}
}
}
if (undefined === roomName) {
// By default, use the room ID
roomName = room_id;
}
return roomName;
};
}]); }]);

View File

@ -33,8 +33,7 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
console.log("Invited to room " + event.room_id); console.log("Invited to room " + event.room_id);
// FIXME push membership to top level key to match /im/sync // FIXME push membership to top level key to match /im/sync
event.membership = event.content.membership; event.membership = event.content.membership;
// FIXME bodge a nicer name than the room ID for this invite.
event.room_display_name = event.user_id + "'s room";
$scope.rooms[event.room_id] = event; $scope.rooms[event.room_id] = event;
} }
}); });
@ -88,7 +87,9 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
}; };
$scope.onInit = function() { $scope.onInit = function() {
eventHandlerService.waitForInitialSyncCompletion().then(function() {
refresh(); refresh();
});
}; };
}]); }]);

View File

@ -6,7 +6,7 @@
ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}"> ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
<tr> <tr>
<td class="recentsRoomName"> <td class="recentsRoomName">
{{ room.room_display_name }} {{ room.room_id | roomName }}
</td> </td>
<td class="recentsRoomSummaryTS"> <td class="recentsRoomSummaryTS">
{{ (room.lastMsg.ts) | date:'MMM d HH:mm' }} {{ (room.lastMsg.ts) | date:'MMM d HH:mm' }}

View File

@ -3,7 +3,7 @@
<div id="roomHeader"> <div id="roomHeader">
<a href ng-click="goToPage('/')"><img src="img/logo-small.png" width="100" height="43" alt="[matrix]"/></a> <a href ng-click="goToPage('/')"><img src="img/logo-small.png" width="100" height="43" alt="[matrix]"/></a>
<div id="roomName"> <div id="roomName">
{{ room_alias || room_id }} {{ room_id | roomName }}
</div> </div>
</div> </div>