diff options
-rw-r--r-- | webclient/app-filter.js | 39 | ||||
-rw-r--r-- | webclient/recents/recents-controller.js | 7 | ||||
-rw-r--r-- | webclient/recents/recents.html | 2 | ||||
-rw-r--r-- | webclient/room/room.html | 2 |
4 files changed, 45 insertions, 5 deletions
diff --git a/webclient/app-filter.js b/webclient/app-filter.js index b8f4ed25bc..124f4ebb48 100644 --- a/webclient/app-filter.js +++ b/webclient/app-filter.js @@ -79,4 +79,43 @@ angular.module('matrixWebClient') return function(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; + }; }]); diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index c9fd022d7f..947bd29de3 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -33,8 +33,7 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService']) console.log("Invited to room " + event.room_id); // FIXME push membership to top level key to match /im/sync 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; } }); @@ -88,7 +87,9 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService']) }; $scope.onInit = function() { - refresh(); + eventHandlerService.waitForInitialSyncCompletion().then(function() { + refresh(); + }); }; }]); diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 56fb38b02a..db3b0fb32f 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -6,7 +6,7 @@ ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}"> <tr> <td class="recentsRoomName"> - {{ room.room_display_name }} + {{ room.room_id | roomName }} </td> <td class="recentsRoomSummaryTS"> {{ (room.lastMsg.ts) | date:'MMM d HH:mm' }} diff --git a/webclient/room/room.html b/webclient/room/room.html index c4d6ccd6cc..f118461e6b 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -3,7 +3,7 @@ <div id="roomHeader"> <a href ng-click="goToPage('/')"><img src="img/logo-small.png" width="100" height="43" alt="[matrix]"/></a> <div id="roomName"> - {{ room_alias || room_id }} + {{ room_id | roomName }} </div> </div> |