You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Merge pull request #805 from matrix-org/travis/custom-status
Support custom status messages
This commit is contained in:
@@ -2262,6 +2262,27 @@ MatrixClient.prototype.mxcUrlToHttp =
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new status message for the user. The message may be null/falsey
|
||||||
|
* to clear the message.
|
||||||
|
* @param {string} newMessage The new message to set.
|
||||||
|
* @return {module:client.Promise} Resolves: to nothing
|
||||||
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
|
*/
|
||||||
|
MatrixClient.prototype._unstable_setStatusMessage = function(newMessage) {
|
||||||
|
return Promise.all(this.getRooms().map((room) => {
|
||||||
|
const isJoined = room.getMyMembership() === "join";
|
||||||
|
const looksLikeDm = room.getInvitedAndJoinedMemberCount() === 2;
|
||||||
|
if (isJoined && looksLikeDm) {
|
||||||
|
return this.sendStateEvent(room.roomId, "im.vector.user_status", {
|
||||||
|
status: newMessage,
|
||||||
|
}, this.getUserId());
|
||||||
|
} else {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} opts Options to apply
|
* @param {Object} opts Options to apply
|
||||||
* @param {string} opts.presence One of "online", "offline" or "unavailable"
|
* @param {string} opts.presence One of "online", "offline" or "unavailable"
|
||||||
|
|||||||
@@ -154,6 +154,16 @@ RoomState.prototype.getMembers = function() {
|
|||||||
return utils.values(this.members);
|
return utils.values(this.members);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all RoomMembers in this room, excluding the user IDs provided.
|
||||||
|
* @param {Array<string>} excludedIds The user IDs to exclude.
|
||||||
|
* @return {Array<RoomMember>} A list of RoomMembers.
|
||||||
|
*/
|
||||||
|
RoomState.prototype.getMembersExcept = function(excludedIds) {
|
||||||
|
return utils.values(this.members)
|
||||||
|
.filter((m) => !excludedIds.includes(m.userId));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a room member by their user ID.
|
* Get a room member by their user ID.
|
||||||
* @param {string} userId The room member's user ID.
|
* @param {string} userId The room member's user ID.
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ limitations under the License.
|
|||||||
* when a user was last active.
|
* when a user was last active.
|
||||||
* @prop {Boolean} currentlyActive Whether we should consider lastActiveAgo to be
|
* @prop {Boolean} currentlyActive Whether we should consider lastActiveAgo to be
|
||||||
* an approximation and that the user should be seen as active 'now'
|
* an approximation and that the user should be seen as active 'now'
|
||||||
|
* @prop {string} _unstable_statusMessage The status message for the user, if known. This is
|
||||||
|
* different from the presenceStatusMsg in that this is not tied to
|
||||||
|
* the user's presence, and should be represented differently.
|
||||||
* @prop {Object} events The events describing this user.
|
* @prop {Object} events The events describing this user.
|
||||||
* @prop {MatrixEvent} events.presence The m.presence event for this user.
|
* @prop {MatrixEvent} events.presence The m.presence event for this user.
|
||||||
*/
|
*/
|
||||||
@@ -46,6 +49,7 @@ function User(userId) {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.presence = "offline";
|
this.presence = "offline";
|
||||||
this.presenceStatusMsg = null;
|
this.presenceStatusMsg = null;
|
||||||
|
this._unstable_statusMessage = "";
|
||||||
this.displayName = userId;
|
this.displayName = userId;
|
||||||
this.rawDisplayName = userId;
|
this.rawDisplayName = userId;
|
||||||
this.avatarUrl = null;
|
this.avatarUrl = null;
|
||||||
@@ -179,6 +183,16 @@ User.prototype.getLastActiveTs = function() {
|
|||||||
return this.lastPresenceTs - this.lastActiveAgo;
|
return this.lastPresenceTs - this.lastActiveAgo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manually set the user's status message.
|
||||||
|
* @param {MatrixEvent} event The <code>im.vector.user_status</code> event.
|
||||||
|
*/
|
||||||
|
User.prototype._unstable_updateStatusMessage = function(event) {
|
||||||
|
if (!event.getContent()) this._unstable_statusMessage = "";
|
||||||
|
else this._unstable_statusMessage = event.getContent()["status"];
|
||||||
|
this._updateModifiedTime();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User class.
|
* The User class.
|
||||||
*/
|
*/
|
||||||
|
|||||||
10
src/sync.js
10
src/sync.js
@@ -1172,6 +1172,16 @@ SyncApi.prototype._processSyncResponse = async function(
|
|||||||
if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) {
|
if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) {
|
||||||
await self.opts.crypto.onCryptoEvent(e);
|
await self.opts.crypto.onCryptoEvent(e);
|
||||||
}
|
}
|
||||||
|
if (e.isState() && e.getType() === "im.vector.user_status") {
|
||||||
|
let user = client.store.getUser(e.getStateKey());
|
||||||
|
if (user) {
|
||||||
|
user._unstable_updateStatusMessage(e);
|
||||||
|
} else {
|
||||||
|
user = createNewUser(client, e.getStateKey());
|
||||||
|
user._unstable_updateStatusMessage(e);
|
||||||
|
client.store.storeUser(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.mapSeries(stateEvents, processRoomEvent);
|
await Promise.mapSeries(stateEvents, processRoomEvent);
|
||||||
|
|||||||
Reference in New Issue
Block a user