From 678d70528ec2608edd5a14c87df661e40d473da0 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 10 Jan 2016 20:02:35 +0000 Subject: [PATCH 1/5] add a Room.getImplicitRoomName so clients can know what a room would be called if it didn't have an explicit m.room.name state event --- lib/models/room.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/models/room.js b/lib/models/room.js index 41783ce63..b4c524de2 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -190,6 +190,18 @@ Room.prototype.getAvatarUrl = function(baseUrl, width, height, resizeMethod, }); }; + /** + * Get the implicit room name (i.e. what a given user would see if the + * room had no m.room.name) + * @param {string} userId The userId from whose perspective we want + * to calculate the implicit name + * @return {string} The implicit room name + */ + Room.prototype.getImplicitRoomName = function(userId) { + return calculateRoomName(this, userId, true); + }; + + /** * Check if the given user_id has the given membership state. * @param {string} userId The user ID to check. @@ -655,14 +667,18 @@ function setEventMetadata(event, stateContext, toStartOfTimeline) { * @param {Room} room The matrix room. * @param {string} userId The client's user ID. Used to filter room members * correctly. + * @param {bool} implicit Return the implicit room name that we'd see if there + * was no m.room.name event. * @return {string} The calculated room name. */ -function calculateRoomName(room, userId) { - // check for an alias, if any. for now, assume first alias is the - // official one. - var mRoomName = room.currentState.getStateEvents("m.room.name", ""); - if (mRoomName && mRoomName.getContent() && mRoomName.getContent().name) { - return mRoomName.getContent().name; +function calculateRoomName(room, userId, implicit) { + if (!implicit) { + // check for an alias, if any. for now, assume first alias is the + // official one. + var mRoomName = room.currentState.getStateEvents("m.room.name", ""); + if (mRoomName && mRoomName.getContent() && mRoomName.getContent().name) { + return mRoomName.getContent().name; + } } var alias; From d7158b575fd643aab297e1b85ef94426b5fc61be Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 10 Jan 2016 20:05:58 +0000 Subject: [PATCH 2/5] fix trailing space --- lib/sync.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sync.js b/lib/sync.js index 8d6541677..f0d3bbc6c 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -340,7 +340,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { joinRooms.forEach(function(joinObj) { var room = joinObj.room; var stateEvents = self._mapSyncEventsFormat(joinObj.state, room, 'state'); - var timelineEvents = + var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room, 'timeline'); var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral, undefined, 'ephemeral'); From 57072bc4f415250250091bc9dc88a3912a805a50 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 11 Jan 2016 18:20:26 +0000 Subject: [PATCH 3/5] s/implicit/ignoreRoomNameEvent/ on calculateRoomName --- lib/models/room.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/models/room.js b/lib/models/room.js index b4c524de2..28eb79f16 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -667,12 +667,12 @@ function setEventMetadata(event, stateContext, toStartOfTimeline) { * @param {Room} room The matrix room. * @param {string} userId The client's user ID. Used to filter room members * correctly. - * @param {bool} implicit Return the implicit room name that we'd see if there + * @param {bool} ignoreRoomNameEvent Return the implicit room name that we'd see if there * was no m.room.name event. * @return {string} The calculated room name. */ -function calculateRoomName(room, userId, implicit) { - if (!implicit) { +function calculateRoomName(room, userId, ignoreRoomNameEvent) { + if (!ignoreRoomNameEvent) { // check for an alias, if any. for now, assume first alias is the // official one. var mRoomName = room.currentState.getStateEvents("m.room.name", ""); From 051e83582b1964db2937b626a1cb6c1b4a047dd8 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 11 Jan 2016 18:23:07 +0000 Subject: [PATCH 4/5] add a cli.getDomain() method rather than react-sdk maintaining its own (multiple) implementations --- lib/client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/client.js b/lib/client.js index 8ea601f7e..2468e2de5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -191,6 +191,14 @@ MatrixClient.prototype.getIdentityServerUrl = function() { return this.idBaseUrl; }; +/** + * Get the domain for this client's MXID + * @return {string} Domain of this MXID + */ +MatrixClient.prototype.getDomain = function() { + return this.credentials.userId.replace(/^.*:/, ''); +}; + /** * Check if the runtime environment supports VoIP calling. * @return {boolean} True if VoIP is supported. From 3ce07a020d05231d3f8e540993a194cad8442b6a Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Jan 2016 12:52:22 +0000 Subject: [PATCH 5/5] ooops - fix getDomain expression --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index 2468e2de5..66e4b6da2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -196,7 +196,7 @@ MatrixClient.prototype.getIdentityServerUrl = function() { * @return {string} Domain of this MXID */ MatrixClient.prototype.getDomain = function() { - return this.credentials.userId.replace(/^.*:/, ''); + return this.credentials.userId.split(':')[0]; }; /**