When new invites come down, update the My Rooms list. Added hacks to make the display name a bit nicer (/im/sync needs to return room aliases / membership events better)

This commit is contained in:
Kegan Dougal 2014-08-15 15:40:37 +01:00
parent 1731781145
commit 02e45da895
3 changed files with 32 additions and 16 deletions

View File

@ -33,23 +33,24 @@ angular.module('eventHandlerService', [])
var PRESENCE_EVENT = "PRESENCE_EVENT"; var PRESENCE_EVENT = "PRESENCE_EVENT";
$rootScope.events = { $rootScope.events = {
rooms: {}, // will contain roomId: { messages:[], members:[] } rooms: {}, // will contain roomId: { messages:[], members:{userid1: event} }
}; };
var initRoom = function(room_id) { var initRoom = function(room_id) {
console.log("Creating new handler entry for " + room_id); if (!(room_id in $rootScope.events.rooms)) {
$rootScope.events.rooms[room_id] = {}; console.log("Creating new handler entry for " + room_id);
$rootScope.events.rooms[room_id].messages = []; $rootScope.events.rooms[room_id] = {};
$rootScope.events.rooms[room_id].members = []; $rootScope.events.rooms[room_id].messages = [];
$rootScope.events.rooms[room_id].members = {};
}
} }
var handleMessage = function(event, isLiveEvent) { var handleMessage = function(event, isLiveEvent) {
if ("membership_target" in event.content) { if ("membership_target" in event.content) {
event.user_id = event.content.membership_target; event.user_id = event.content.membership_target;
} }
if (!(event.room_id in $rootScope.events.rooms)) {
initRoom(event.room_id); initRoom(event.room_id);
}
if (isLiveEvent) { if (isLiveEvent) {
$rootScope.events.rooms[event.room_id].messages.push(event); $rootScope.events.rooms[event.room_id].messages.push(event);
@ -67,6 +68,8 @@ angular.module('eventHandlerService', [])
}; };
var handleRoomMember = function(event, isLiveEvent) { var handleRoomMember = function(event, isLiveEvent) {
initRoom(event.room_id);
$rootScope.events.rooms[event.room_id].members[event.user_id] = event;
$rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent); $rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent);
}; };

View File

@ -16,11 +16,11 @@ limitations under the License.
'use strict'; 'use strict';
angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']) angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload', 'eventHandlerService'])
.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload', .controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload', 'eventHandlerService',
function($scope, $location, matrixService, mFileUpload) { function($scope, $location, matrixService, mFileUpload, eventHandlerService) {
$scope.rooms = []; $scope.rooms = {};
$scope.public_rooms = []; $scope.public_rooms = [];
$scope.newRoomId = ""; $scope.newRoomId = "";
$scope.feedback = ""; $scope.feedback = "";
@ -52,6 +52,18 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
linkedEmailList: matrixService.config().emailList // linked email list linkedEmailList: matrixService.config().emailList // linked email list
}; };
$scope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) {
var config = matrixService.config();
if (event.target_user_id === config.user_id && event.content.membership === "invite") {
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_alias = event.user_id + "'s room";
$scope.rooms[event.room_id] = event;
}
});
var assignRoomAliases = function(data) { var assignRoomAliases = function(data) {
for (var i=0; i<data.length; i++) { for (var i=0; i<data.length; i++) {
var alias = matrixService.getRoomIdToAliasMapping(data[i].room_id); var alias = matrixService.getRoomIdToAliasMapping(data[i].room_id);
@ -73,12 +85,13 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
$scope.refresh = function() { $scope.refresh = function() {
// List all rooms joined or been invited to // List all rooms joined or been invited to
$scope.rooms = matrixService.rooms();
matrixService.rooms().then( matrixService.rooms().then(
function(response) { function(response) {
var data = assignRoomAliases(response.data); var data = assignRoomAliases(response.data);
$scope.feedback = "Success"; $scope.feedback = "Success";
$scope.rooms = data; for (var i=0; i<data.length; i++) {
$scope.rooms[data[i].room_id] = data[i];
}
}, },
function(error) { function(error) {
$scope.feedback = "Failure: " + error.data; $scope.feedback = "Failure: " + error.data;

View File

@ -61,9 +61,9 @@
<h3>My rooms</h3> <h3>My rooms</h3>
<div class="rooms" ng-repeat="room in rooms"> <div class="rooms" ng-repeat="(rm_id, room) in rooms">
<div> <div>
<a href="#/room/{{ room.room_id }}" >{{ room.room_alias }}</a> <a href="#/room/{{ rm_id }}" >{{ room.room_alias }}</a> {{room.membership === 'invite' ? ' (invited)' : ''}}
</div> </div>
</div> </div>
<br/> <br/>