summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-11-04 10:18:46 +0000
committerKegan Dougal <kegan@matrix.org>2014-11-04 10:18:46 +0000
commit1c86ec5b8dcdfaf72259b63d2c588014707c70de (patch)
treee9ff65395af9216a17c3f83aaf54b543e2536b57
parentRejig order of checks/state updates/message insertions for m.room.member. Mar... (diff)
downloadsynapse-1c86ec5b8dcdfaf72259b63d2c588014707c70de.tar.xz
Rejig display names when paginating to lie less.
Diffstat (limited to '')
-rw-r--r--webclient/components/matrix/event-handler-service.js11
-rw-r--r--webclient/components/matrix/model-service.js9
-rw-r--r--webclient/room/room.html17
3 files changed, 24 insertions, 13 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index bba24cfaa9..226db0798b 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -218,14 +218,19 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
         else if (!isLiveEvent) {
             // mutate the old room state
             var oldEvent = angular.copy(event);
+            oldEvent.cnt = event.content;
             if (event.prev_content) {
                 // 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
                 // names/etc, hence the clobber here.
-                // FIXME TODO: We can't be doing this, we should have separate keys for
-                //             avatar_url and displayname.
-                event.content = event.prev_content;
+                oldEvent.cnt = 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);
         }
         
diff --git a/webclient/components/matrix/model-service.js b/webclient/components/matrix/model-service.js
index d5acd7eda9..7277ae347b 100644
--- a/webclient/components/matrix/model-service.js
+++ b/webclient/components/matrix/model-service.js
@@ -45,12 +45,17 @@ angular.module('modelService', [])
         addMessageEvent: function addMessageEvent(event, toFront) {
             // every message must reference the RoomMember which made it *at
             // 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) {
-                event.room_member = this.old_room_state.getStateEvent("m.room.member", event.user_id);
                 this.events.unshift(event);
             }
             else {
-                event.room_member = this.current_room_state.getStateEvent("m.room.member", event.user_id);
                 this.events.push(event);
             }
         },
diff --git a/webclient/room/room.html b/webclient/room/room.html
index 60b875f17b..332a9928d1 100644
--- a/webclient/room/room.html
+++ b/webclient/room/room.html
@@ -127,7 +127,7 @@
             <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>
                 <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"
                          ng-class="msg.echo_msg_state">
                         {{ (msg.origin_server_ts) | date:'MMM d HH:mm' }}
@@ -135,22 +135,23 @@
                 </td>
                 <td class="avatar">
                     <!-- 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"/>
                 </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'">
                     <div class="bubble" ng-click="openJson(msg)">
                         <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 ng-if="'leave' === msg.content.membership && msg.changedKey === 'membership'">
                             <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 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] }}
-                                {{ 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">
                                     : {{ msg.content.reason }}
                                 </span>
@@ -158,9 +159,9 @@
                         </span>
                         <span ng-if="'invite' === 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] }}
-                            {{ 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">
                                 : {{ msg.content.reason }}
                             </span>