diff --git a/lib/client.js b/lib/client.js index df0f88ec5..7bbb99f9b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -191,6 +191,17 @@ 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() { + if (this.credentials && this.credentials.userId) { + return this.credentials.userId.split(':')[0]; + } + return null; +}; + /** * Get the access token associated with this account. * @return {?String} The access_token or null @@ -201,7 +212,7 @@ MatrixClient.prototype.getAccessToken = function() { /** * Get the local part of the current user ID e.g. "foo" in "@foo:bar". - * @return {?String} The user ID localpart or null. + * @return {?string} The user ID localpart or null. */ MatrixClient.prototype.getUserIdLocalpart = function() { if (this.credentials && this.credentials.userId) { diff --git a/lib/models/room.js b/lib/models/room.js index 52f4d2241..1f120fe1c 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -189,6 +189,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. @@ -657,14 +669,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} 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) { - // 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, 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", ""); + if (mRoomName && mRoomName.getContent() && mRoomName.getContent().name) { + return mRoomName.getContent().name; + } } var alias;