Rejig display names when paginating to lie less.

This commit is contained in:
Kegan Dougal 2014-11-04 10:18:46 +00:00
parent 43e7ad1b1c
commit 1c86ec5b8d
3 changed files with 24 additions and 13 deletions

View File

@ -218,14 +218,19 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
else if (!isLiveEvent) { else if (!isLiveEvent) {
// mutate the old room state // mutate the old room state
var oldEvent = angular.copy(event); var oldEvent = angular.copy(event);
oldEvent.cnt = event.content;
if (event.prev_content) { if (event.prev_content) {
// the m.room.member event we are handling is the NEW event. When // the m.room.member event we are handling is the NEW event. When
// we keep going back in time, we want the PREVIOUS value for displaying // we keep going back in time, we want the PREVIOUS value for displaying
// names/etc, hence the clobber here. // names/etc, hence the clobber here.
// FIXME TODO: We can't be doing this, we should have separate keys for oldEvent.cnt = event.prev_content;
// avatar_url and displayname.
event.content = event.prev_content;
} }
if (event.changedKey === "membership" && event.content.membership === "join") {
// join has a prev_content but it doesn't contain all the info unlike the join, so use that.
oldEvent.cnt = event.content;
}
room.old_room_state.storeStateEvent(oldEvent); room.old_room_state.storeStateEvent(oldEvent);
} }

View File

@ -45,12 +45,17 @@ angular.module('modelService', [])
addMessageEvent: function addMessageEvent(event, toFront) { addMessageEvent: function addMessageEvent(event, toFront) {
// every message must reference the RoomMember which made it *at // every message must reference the RoomMember which made it *at
// that time* so things like display names display correctly. // that time* so things like display names display correctly.
var stateAtTheTime = toFront ? this.old_room_state : this.current_room_state;
event.room_member = stateAtTheTime.getStateEvent("m.room.member", event.user_id);
if (event.type === "m.room.member" && event.content.membership === "invite") {
// give information on both the inviter and invitee
event.__target_room_member = stateAtTheTime.getStateEvent("m.room.member", event.state_key);
}
if (toFront) { if (toFront) {
event.room_member = this.old_room_state.getStateEvent("m.room.member", event.user_id);
this.events.unshift(event); this.events.unshift(event);
} }
else { else {
event.room_member = this.current_room_state.getStateEvent("m.room.member", event.user_id);
this.events.push(event); this.events.push(event);
} }
}, },

View File

@ -127,7 +127,7 @@
<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.room_member.content.displayname || msg.user_id | mUserDisplayName: room_id }}</div> <div class="sender" ng-hide="room.events[$index - 1].user_id === msg.user_id"> {{ msg.room_member.cnt.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' }}
@ -135,22 +135,23 @@
</td> </td>
<td class="avatar"> <td class="avatar">
<!-- msg.room_member.avatar_url is just backwards compat, and can be removed in the future. --> <!-- msg.room_member.avatar_url is just backwards compat, and can be removed in the future. -->
<img class="avatarImage" ng-src="{{ msg.room_member.content.avatar_url || msg.room_member.avatar_url || 'img/default-profile.png' }}" width="32" height="32" title="{{msg.user_id}}" <img class="avatarImage" ng-src="{{ msg.room_member.cnt.avatar_url || msg.room_member.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'">
<div class="bubble" ng-click="openJson(msg)"> <div class="bubble" ng-click="openJson(msg)">
<span ng-if="'join' === msg.content.membership && msg.changedKey === 'membership'"> <span ng-if="'join' === msg.content.membership && msg.changedKey === 'membership'">
{{ members[msg.state_key].displayname || msg.state_key }} joined {{ msg.content.displayname || members[msg.state_key].displayname || msg.state_key }} joined
</span> </span>
<span ng-if="'leave' === msg.content.membership && msg.changedKey === 'membership'"> <span ng-if="'leave' === msg.content.membership && msg.changedKey === 'membership'">
<span ng-if="msg.user_id === msg.state_key"> <span ng-if="msg.user_id === msg.state_key">
{{ members[msg.state_key].displayname || msg.state_key }} left <!-- FIXME: This seems like a synapse bug that the 'leave' content doesn't give the displayname... -->
{{ msg.room_member.cnt.displayname || members[msg.state_key].displayname || msg.state_key }} left
</span> </span>
<span ng-if="msg.user_id !== msg.state_key && msg.prev_content"> <span ng-if="msg.user_id !== msg.state_key && msg.prev_content">
{{ members[msg.user_id].displayname || msg.user_id }} {{ msg.content.displayname || members[msg.user_id].displayname || msg.user_id }}
{{ {"invite": "kicked", "join": "kicked", "ban": "unbanned"}[msg.prev_content.membership] }} {{ {"invite": "kicked", "join": "kicked", "ban": "unbanned"}[msg.prev_content.membership] }}
{{ members[msg.state_key].displayname || msg.state_key }} {{ msg.__target_room_member.content.displayname || msg.state_key }}
<span ng-if="'join' === msg.prev_content.membership && msg.content.reason"> <span ng-if="'join' === msg.prev_content.membership && msg.content.reason">
: {{ msg.content.reason }} : {{ msg.content.reason }}
</span> </span>
@ -158,9 +159,9 @@
</span> </span>
<span ng-if="'invite' === msg.content.membership && msg.changedKey === 'membership' || <span ng-if="'invite' === msg.content.membership && msg.changedKey === 'membership' ||
'ban' === msg.content.membership && msg.changedKey === 'membership'"> 'ban' === msg.content.membership && msg.changedKey === 'membership'">
{{ members[msg.user_id].displayname || msg.user_id }} {{ msg.content.displayname || members[msg.user_id].displayname || msg.user_id }}
{{ {"invite": "invited", "ban": "banned"}[msg.content.membership] }} {{ {"invite": "invited", "ban": "banned"}[msg.content.membership] }}
{{ members[msg.state_key].displayname || msg.state_key }} {{ msg.__target_room_member.displayname || msg.state_key }}
<span ng-if="msg.prev_content && 'ban' === msg.prev_content.membership && msg.content.reason"> <span ng-if="msg.prev_content && 'ban' === msg.prev_content.membership && msg.content.reason">
: {{ msg.content.reason }} : {{ msg.content.reason }}
</span> </span>