1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Merge pull request #62 from matrix-org/matthew/roomsettings2

Room.getImplicitRoomName
This commit is contained in:
Matthew Hodgson
2016-01-13 12:58:52 +00:00
2 changed files with 34 additions and 7 deletions

View File

@@ -191,6 +191,17 @@ MatrixClient.prototype.getIdentityServerUrl = function() {
return this.idBaseUrl; 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. * Get the access token associated with this account.
* @return {?String} The access_token or null * @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". * 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() { MatrixClient.prototype.getUserIdLocalpart = function() {
if (this.credentials && this.credentials.userId) { if (this.credentials && this.credentials.userId) {

View File

@@ -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. * Check if the given user_id has the given membership state.
* @param {string} userId The user ID to check. * @param {string} userId The user ID to check.
@@ -657,15 +669,19 @@ function setEventMetadata(event, stateContext, toStartOfTimeline) {
* @param {Room} room The matrix room. * @param {Room} room The matrix room.
* @param {string} userId The client's user ID. Used to filter room members * @param {string} userId The client's user ID. Used to filter room members
* correctly. * 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. * @return {string} The calculated room name.
*/ */
function calculateRoomName(room, userId) { function calculateRoomName(room, userId, ignoreRoomNameEvent) {
if (!ignoreRoomNameEvent) {
// check for an alias, if any. for now, assume first alias is the // check for an alias, if any. for now, assume first alias is the
// official one. // official one.
var mRoomName = room.currentState.getStateEvents("m.room.name", ""); var mRoomName = room.currentState.getStateEvents("m.room.name", "");
if (mRoomName && mRoomName.getContent() && mRoomName.getContent().name) { if (mRoomName && mRoomName.getContent() && mRoomName.getContent().name) {
return mRoomName.getContent().name; return mRoomName.getContent().name;
} }
}
var alias; var alias;
var canonicalAlias = room.currentState.getStateEvents("m.room.canonical_alias", ""); var canonicalAlias = room.currentState.getStateEvents("m.room.canonical_alias", "");