Make recents[controller/filter/html] use modelService.
This breaks functionality whilst both events.rooms and modelService are in use.
This commit is contained in:
parent
53da1099d1
commit
6bc1dc4020
|
@ -86,18 +86,6 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
|
||||||
}
|
}
|
||||||
$rootScope.events.rooms[room_id].membership = room.membership;
|
$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) {
|
var resetRoomMessages = function(room_id) {
|
||||||
|
@ -622,11 +610,43 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
|
||||||
|
|
||||||
this.initRoom(room);
|
this.initRoom(room);
|
||||||
|
|
||||||
if ("messages" in room) {
|
// FIXME: This is ming: the HS should be sending down the m.room.member
|
||||||
this.handleRoomMessages(room.room_id, room.messages, false);
|
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("state" in room) {
|
// =========================================
|
||||||
|
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) { // TODO FIXME remove this.
|
||||||
this.handleEvents(room.state, false, true);
|
this.handleEvents(room.state, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,15 @@ angular.module('modelService', [])
|
||||||
|
|
||||||
storeStateEvent: function storeState(event) {
|
storeStateEvent: function storeState(event) {
|
||||||
this.state_events[event.type + event.state_key] = 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) {
|
storeStateEvents: function storeState(events) {
|
||||||
|
if (!events) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (var i=0; i<events.length; i++) {
|
for (var i=0; i<events.length; i++) {
|
||||||
this.storeStateEvent(events[i]);
|
this.storeStateEvent(events[i]);
|
||||||
}
|
}
|
||||||
|
@ -138,6 +144,10 @@ angular.module('modelService', [])
|
||||||
rooms[roomId] = new Room(roomId);
|
rooms[roomId] = new Room(roomId);
|
||||||
}
|
}
|
||||||
return rooms[roomId];
|
return rooms[roomId];
|
||||||
|
},
|
||||||
|
|
||||||
|
getRooms: function() {
|
||||||
|
return rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,12 +17,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('RecentsController', ['matrixService', 'matrixFilter'])
|
angular.module('RecentsController', ['matrixService', 'matrixFilter'])
|
||||||
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService',
|
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService',
|
||||||
function($rootScope, $scope, eventHandlerService) {
|
function($rootScope, $scope, eventHandlerService, modelService) {
|
||||||
|
|
||||||
// Expose the service to the view
|
// Expose the service to the view
|
||||||
$scope.eventHandlerService = eventHandlerService;
|
$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
|
// $rootScope of the parent where the recents component is included can override this value
|
||||||
// in order to highlight a specific room in the list
|
// in order to highlight a specific room in the list
|
||||||
$rootScope.recentsSelectedRoomID;
|
$rootScope.recentsSelectedRoomID;
|
||||||
|
|
|
@ -25,22 +25,30 @@ angular.module('RecentsController')
|
||||||
// The key, room_id, is already in value objects
|
// The key, room_id, is already in value objects
|
||||||
var filtered = [];
|
var filtered = [];
|
||||||
angular.forEach(rooms, function(room, room_id) {
|
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
|
// Show the room only if the user has joined it or has been invited
|
||||||
// (ie, do not show it if he has been banned)
|
// (ie, do not show it if he has been banned)
|
||||||
var member = eventHandlerService.getMember(room_id, user_id);
|
var member = eventHandlerService.getMember(room_id, user_id);
|
||||||
|
room.recent.me = member;
|
||||||
if (member && ("invite" === member.membership || "join" === member.membership)) {
|
if (member && ("invite" === member.membership || "join" === member.membership)) {
|
||||||
|
if ("invite" === member.membership) {
|
||||||
|
room.recent.inviter = member.user_id;
|
||||||
|
}
|
||||||
// Count users here
|
// Count users here
|
||||||
// TODO: Compute it directly in eventHandlerService
|
// TODO: Compute it directly in eventHandlerService
|
||||||
room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
|
room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
|
||||||
|
|
||||||
filtered.push(room);
|
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
|
// The only information we have about the room is that the user has been invited
|
||||||
filtered.push(room);
|
filtered.push(room);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.error("Dropping "+room.room_id);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// And time sort them
|
// And time sort them
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
<div ng-controller="RecentsController">
|
<div ng-controller="RecentsController">
|
||||||
<table class="recentsTable">
|
<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) )"
|
ng-click="goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) )"
|
||||||
class="recentsRoom"
|
class="recentsRoom"
|
||||||
ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
|
ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
|
||||||
<tr>
|
<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 }}
|
{{ room.room_id | mRoomName }}
|
||||||
</td>
|
</td>
|
||||||
<td class="recentsRoomSummaryUsersCount">
|
<td class="recentsRoomSummaryUsersCount">
|
||||||
<span ng-show="undefined !== room.numUsersInRoom">
|
<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>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="recentsRoomSummaryTS">
|
<td class="recentsRoomSummaryTS">
|
||||||
|
@ -27,11 +27,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3" class="recentsRoomSummary">
|
<td colspan="3" class="recentsRoomSummary">
|
||||||
|
|
||||||
<div ng-show="room.membership === 'invite'">
|
<div ng-show="room.recent.me.membership === 'invite'">
|
||||||
{{ room.inviter | mUserDisplayName: room.room_id }} invited you
|
{{ room.recent.inviter | mUserDisplayName: room.room_id }} invited you
|
||||||
</div>
|
</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">
|
<div ng-switch-when="m.room.member">
|
||||||
<span ng-switch="lastMsg.changedKey">
|
<span ng-switch="lastMsg.changedKey">
|
||||||
<span ng-switch-when="membership">
|
<span ng-switch-when="membership">
|
||||||
|
|
Loading…
Reference in New Issue