0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 13:03:50 +01:00

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";
$rootScope.events = {
rooms: {}, // will contain roomId: { messages:[], members:[] }
rooms: {}, // will contain roomId: { messages:[], members:{userid1: event} }
};
var initRoom = function(room_id) {
console.log("Creating new handler entry for " + room_id);
$rootScope.events.rooms[room_id] = {};
$rootScope.events.rooms[room_id].messages = [];
$rootScope.events.rooms[room_id].members = [];
if (!(room_id in $rootScope.events.rooms)) {
console.log("Creating new handler entry for " + room_id);
$rootScope.events.rooms[room_id] = {};
$rootScope.events.rooms[room_id].messages = [];
$rootScope.events.rooms[room_id].members = {};
}
}
var handleMessage = function(event, isLiveEvent) {
if ("membership_target" in event.content) {
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) {
$rootScope.events.rooms[event.room_id].messages.push(event);
@ -67,6 +68,8 @@ angular.module('eventHandlerService', [])
};
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);
};

View file

@ -16,11 +16,11 @@ limitations under the License.
'use strict';
angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload'])
.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload',
function($scope, $location, matrixService, mFileUpload) {
angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload', 'eventHandlerService'])
.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload', 'eventHandlerService',
function($scope, $location, matrixService, mFileUpload, eventHandlerService) {
$scope.rooms = [];
$scope.rooms = {};
$scope.public_rooms = [];
$scope.newRoomId = "";
$scope.feedback = "";
@ -52,6 +52,18 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
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) {
for (var i=0; i<data.length; i++) {
var alias = matrixService.getRoomIdToAliasMapping(data[i].room_id);
@ -73,12 +85,13 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']
$scope.refresh = function() {
// List all rooms joined or been invited to
$scope.rooms = matrixService.rooms();
matrixService.rooms().then(
function(response) {
var data = assignRoomAliases(response.data);
$scope.feedback = "Success";
$scope.rooms = data;
for (var i=0; i<data.length; i++) {
$scope.rooms[data[i].room_id] = data[i];
}
},
function(error) {
$scope.feedback = "Failure: " + error.data;

View file

@ -61,9 +61,9 @@
<h3>My rooms</h3>
<div class="rooms" ng-repeat="room in rooms">
<div class="rooms" ng-repeat="(rm_id, room) in rooms">
<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>
<br/>