From fb65c7f4bab0ad3764657b3f4c67ab93093343f6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 12 Dec 2018 13:21:13 -0700 Subject: [PATCH] Support setting status message in rooms that look like 1:1s Part of https://github.com/vector-im/riot-web/issues/1528 --- src/client.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/client.js b/src/client.js index 22cae3e87..9b5726f2f 100644 --- a/src/client.js +++ b/src/client.js @@ -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.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 {string} opts.presence One of "online", "offline" or "unavailable"