Bug 1347535 - Display names of Matrix participants instead of IDs. r=pmorris
authorPatrick Cloke <clokep@gmail.com>
Tue, 29 Oct 2019 13:11:16 -0400
changeset 36514 ad8a9f5244f8c6e2028342d899d0f06ff13e339a
parent 36513 5f93ed1690ab1ca2af7dd435d9db1d4310ba77ad
child 36515 a2c9e5e752b1cace9489be659bdfbddfb57598ea
push id2534
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:52:51 +0000
treeherdercomm-beta@055c50840778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmorris
bugs1347535
Bug 1347535 - Display names of Matrix participants instead of IDs. r=pmorris
chat/protocols/matrix/matrix.js
--- a/chat/protocols/matrix/matrix.js
+++ b/chat/protocols/matrix/matrix.js
@@ -18,25 +18,27 @@ XPCOMUtils.defineLazyGetter(this, "_", (
 
 ChromeUtils.defineModuleGetter(
   this,
   "MatrixSDK",
   "resource:///modules/matrix-sdk.jsm"
 );
 
 function MatrixParticipant(aRoomMember) {
-  // FIXME: Should probably use aRoomMember.name, but it's not unique id?
-  this._name = aRoomMember.userId;
+  this._id = aRoomMember.userId;
   this._roomMember = aRoomMember;
 }
 MatrixParticipant.prototype = {
   __proto__: GenericConvChatBuddyPrototype,
   get alias() {
     return this._roomMember.name;
   },
+  get name() {
+    return this._roomMember.name;
+  },
 
   // See https://matrix.org/docs/spec/client_server/r0.5.0#m-room-power-levels
   get voiced() {
     return this._roomMember.powerLevelNorm >= 10;
   },
   get halfOp() {
     return this._roomMember.powerLevelNorm >= 25;
   },
@@ -190,45 +192,49 @@ MatrixAccount.prototype = {
         } else {
           body = JSON.stringify(event.getContent());
         }
         this._roomList[room.roomId].writeMessage(event.getSender(), body, {
           incoming: true,
         });
       }
     });
-    this._client.on("RoomMember.powerLevel", (event, member) => {
-      if (member.roomId in this._roomList) {
-        let conv = this._roomList[member.roomId];
-        let participant = conv._participants.get(member.userId);
-        // A participant might not exist (for example, this happens if the user
-        // has only been invited, but has not yet joined).
-        if (participant) {
-          participant._roomMember = member;
-          conv.notifyObservers(participant, "chat-buddy-update");
-        }
-      }
-    });
+    // Update the chat participant information.
+    this._client.on("RoomMember.name", this.updateRoomMember);
+    this._client.on("RoomMember.powerLevel", this.updateRoomMember);
 
     // TODO Other events to handle:
     //  Room.accountData
     //  Room.localEchoUpdated
     //  Room.name
     //  Room.tags
     //  Room
-    //  RoomMember.name
     //  RoomMember.typing
     //  Session.logged_out
     //  User.avatarUrl
     //  User.currentlyActive
     //  User.displayName
     //  User.presence
 
     this._client.startClient();
   },
+
+  updateRoomMember(event, member) {
+    if (member.roomId in this._roomList) {
+      let conv = this._roomList[member.roomId];
+      let participant = conv._participants.get(member.userId);
+      // A participant might not exist (for example, this happens if the user
+      // has only been invited, but has not yet joined).
+      if (participant) {
+        participant._roomMember = member;
+        conv.notifyObservers(participant, "chat-buddy-update");
+      }
+    }
+  },
+
   disconnect() {
     if (this._client) {
       this._client.stopClient();
     }
   },
 
   get canJoinChat() {
     return true;