Make recents[controller/filter/html] use modelService.

This breaks functionality whilst both events.rooms and modelService
are in use.
This commit is contained in:
Kegan Dougal 2014-11-03 11:44:39 +00:00
parent 53da1099d1
commit 6bc1dc4020
5 changed files with 66 additions and 25 deletions

View File

@ -86,18 +86,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
}
$rootScope.events.rooms[room_id].membership = room.membership;
}
// =========================================
var __room = modelService.getRoom(room_id);
if (room) { // /initialSync data
__room.current_room_state.storeStateEvents(room.state);
__room.current_room_state.pagination_token = room.messages.end;
__room.old_room_state.storeStateEvents(room.state);
__room.old_room_state.pagination_token = room.messages.start;
$rootScope["debug_"+room_id] = __room;
}
};
var resetRoomMessages = function(room_id) {
@ -621,12 +609,44 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
var room = rooms[i];
this.initRoom(room);
// FIXME: This is ming: the HS should be sending down the m.room.member
// event for the invite in .state but it isn't, so fudge it for now.
if (room.inviter && room.membership === "invite") {
var me = matrixService.config().user_id;
var fakeEvent = {
event_id: "__FAKE__" + room.room_id,
user_id: room.inviter,
origin_server_ts: 0,
room_id: room.room_id,
state_key: me,
type: "m.room.member",
content: {
membership: "invite"
}
};
if (!room.state) {
room.state = [];
}
room.state.push(fakeEvent);
console.log("RECV /initialSync invite >> "+JSON.stringify(fakeEvent));
}
// =========================================
var __room = modelService.getRoom(room.room_id);
__room.current_room_state.storeStateEvents(room.state);
__room.old_room_state.storeStateEvents(room.state);
if ("messages" in room) {
this.handleRoomMessages(room.room_id, room.messages, false);
__room.current_room_state.pagination_token = room.messages.end;
__room.old_room_state.pagination_token = room.messages.start;
}
if ("state" in room) {
if ("state" in room) { // TODO FIXME remove this.
this.handleEvents(room.state, false, true);
}
}

View File

@ -100,9 +100,15 @@ angular.module('modelService', [])
storeStateEvent: function storeState(event) {
this.state_events[event.type + event.state_key] = event;
if (event.type === "m.room.member") {
this.members[event.state_key] = event;
}
},
storeStateEvents: function storeState(events) {
if (!events) {
return;
}
for (var i=0; i<events.length; i++) {
this.storeStateEvent(events[i]);
}
@ -138,6 +144,10 @@ angular.module('modelService', [])
rooms[roomId] = new Room(roomId);
}
return rooms[roomId];
},
getRooms: function() {
return rooms;
}
};

View File

@ -17,11 +17,14 @@
'use strict';
angular.module('RecentsController', ['matrixService', 'matrixFilter'])
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService',
function($rootScope, $scope, eventHandlerService) {
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService',
function($rootScope, $scope, eventHandlerService, modelService) {
// Expose the service to the view
$scope.eventHandlerService = eventHandlerService;
// retrieve all rooms and expose them
$scope.rooms = modelService.getRooms();
// $rootScope of the parent where the recents component is included can override this value
// in order to highlight a specific room in the list

View File

@ -25,22 +25,30 @@ angular.module('RecentsController')
// The key, room_id, is already in value objects
var filtered = [];
angular.forEach(rooms, function(room, room_id) {
room.recent = {};
var meEvent = room.current_room_state.state("m.room.member", user_id);
// Show the room only if the user has joined it or has been invited
// (ie, do not show it if he has been banned)
var member = eventHandlerService.getMember(room_id, user_id);
room.recent.me = member;
if (member && ("invite" === member.membership || "join" === member.membership)) {
if ("invite" === member.membership) {
room.recent.inviter = member.user_id;
}
// Count users here
// TODO: Compute it directly in eventHandlerService
room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
filtered.push(room);
}
else if ("invite" === room.membership) {
else if (meEvent && "invite" === meEvent.content.membership) {
// The only information we have about the room is that the user has been invited
filtered.push(room);
}
else {
console.error("Dropping "+room.room_id);
}
});
// And time sort them

View File

@ -1,16 +1,16 @@
<div ng-controller="RecentsController">
<table class="recentsTable">
<tbody ng-repeat="(index, room) in events.rooms | orderRecents"
<tbody ng-repeat="(index, room) in rooms | orderRecents"
ng-click="goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) )"
class="recentsRoom"
ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
<tr>
<td ng-class="room['m.room.join_rules'].content.join_rule == 'public' ? 'recentsRoomName recentsPublicRoom' : 'recentsRoomName'">
<td ng-class="room.current_room_state.state('m.room.join_rules').content.join_rule == 'public' ? 'recentsRoomName recentsPublicRoom' : 'recentsRoomName'">
{{ room.room_id | mRoomName }}
</td>
<td class="recentsRoomSummaryUsersCount">
<span ng-show="undefined !== room.numUsersInRoom">
{{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }}
{{ room.recent.numUsersInRoom || '1' }} {{ room.recent.numUsersInRoom == 1 ? 'user' : 'users' }}
</span>
</td>
<td class="recentsRoomSummaryTS">
@ -27,11 +27,11 @@
<tr>
<td colspan="3" class="recentsRoomSummary">
<div ng-show="room.membership === 'invite'">
{{ room.inviter | mUserDisplayName: room.room_id }} invited you
<div ng-show="room.recent.me.membership === 'invite'">
{{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
</div>
<div ng-hide="room.membership === 'invite'" ng-switch="lastMsg.type">
<div ng-hide="room.recent.me.membership === 'invite'" ng-switch="lastMsg.type">
<div ng-switch-when="m.room.member">
<span ng-switch="lastMsg.changedKey">
<span ng-switch-when="membership">