Reference the room_member key on messages which adjusts for current vs old_room_state. This displays names for historical users correctly, but is off by one (referencing content not prev_content).

This commit is contained in:
Kegan Dougal 2014-11-03 17:44:14 +00:00
parent f3dbcdc7b3
commit 4b3f743885
2 changed files with 18 additions and 8 deletions

View File

@ -193,6 +193,17 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
var handleRoomMember = function(event, isLiveEvent, isStateEvent) { var handleRoomMember = function(event, isLiveEvent, isStateEvent) {
var room = modelService.getRoom(event.room_id); var room = modelService.getRoom(event.room_id);
// modify state before adding the message so it points to the right thing.
// The events are copied to avoid referencing the same event when adding
// the message (circular json structures)
if (isStateEvent || isLiveEvent) {
room.current_room_state.storeStateEvent(angular.copy(event));
}
else if (!isLiveEvent) {
// mutate the old room state
room.old_room_state.storeStateEvent(angular.copy(event));
}
// add membership changes as if they were a room message if something interesting changed // add membership changes as if they were a room message if something interesting changed
// Exception: Do not do this if the event is a room state event because such events already come // Exception: Do not do this if the event is a room state event because such events already come
@ -220,11 +231,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
} }
} }
// Use data from state event or the latest data from the stream.
// Do not care of events that come when paginating back
if (isStateEvent || isLiveEvent) {
room.current_room_state.members[event.state_key] = event;
}
$rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent, isStateEvent); $rootScope.$broadcast(MEMBER_EVENT, event, isLiveEvent, isStateEvent);
}; };
@ -439,7 +446,8 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
} }
else { else {
// InitialSync returns messages in chronological order // InitialSync returns messages in chronological order, so invert
// it to get most recent > oldest
for (var i=events.length - 1; i>=0; i--) { for (var i=events.length - 1; i>=0; i--) {
this.handleEvent(events[i], isLiveEvents, isLiveEvents); this.handleEvent(events[i], isLiveEvents, isLiveEvents);
} }
@ -482,6 +490,8 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
newRoom.current_room_state.storeStateEvents(room.state); newRoom.current_room_state.storeStateEvents(room.state);
newRoom.old_room_state.storeStateEvents(room.state); newRoom.old_room_state.storeStateEvents(room.state);
// this should be done AFTER storing state events since these
// messages may make the old_room_state diverge.
if ("messages" in room) { if ("messages" in room) {
this.handleRoomMessages(room.room_id, room.messages, false); this.handleRoomMessages(room.room_id, room.messages, false);
newRoom.current_room_state.pagination_token = room.messages.end; newRoom.current_room_state.pagination_token = room.messages.end;

View File

@ -127,14 +127,14 @@
<tr ng-repeat="msg in room.events" <tr ng-repeat="msg in room.events"
ng-class="(room.events[$index + 1].user_id !== msg.user_id ? 'differentUser' : '') + (msg.user_id === state.user_id ? ' mine' : '')" scroll-item> ng-class="(room.events[$index + 1].user_id !== msg.user_id ? 'differentUser' : '') + (msg.user_id === state.user_id ? ' mine' : '')" scroll-item>
<td class="leftBlock"> <td class="leftBlock">
<div class="sender" ng-hide="room.events[$index - 1].user_id === msg.user_id"> {{ msg.user_id | mUserDisplayName: room_id }}</div> <div class="sender" ng-hide="room.events[$index - 1].user_id === msg.user_id"> {{ msg.room_member.content.displayname || msg.user_id | mUserDisplayName: room_id }}</div>
<div class="timestamp" <div class="timestamp"
ng-class="msg.echo_msg_state"> ng-class="msg.echo_msg_state">
{{ (msg.origin_server_ts) | date:'MMM d HH:mm' }} {{ (msg.origin_server_ts) | date:'MMM d HH:mm' }}
</div> </div>
</td> </td>
<td class="avatar"> <td class="avatar">
<img class="avatarImage" ng-src="{{ members[msg.user_id].avatar_url || 'img/default-profile.png' }}" width="32" height="32" title="{{msg.user_id}}" <img class="avatarImage" ng-src="{{ msg.room_member.content.avatar_url || 'img/default-profile.png' }}" width="32" height="32" title="{{msg.user_id}}"
ng-hide="room.events[$index - 1].user_id === msg.user_id || msg.user_id === state.user_id"/> ng-hide="room.events[$index - 1].user_id === msg.user_id || msg.user_id === state.user_id"/>
</td> </td>
<td ng-class="(!msg.content.membership && ('m.room.topic' !== msg.type && 'm.room.name' !== msg.type))? (msg.content.msgtype === 'm.emote' ? 'emote text' : 'text') : 'membership text'"> <td ng-class="(!msg.content.membership && ('m.room.topic' !== msg.type && 'm.room.name' !== msg.type))? (msg.content.msgtype === 'm.emote' ? 'emote text' : 'text') : 'membership text'">