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

Ensure we have power to set custom status

If we're in a non-DM room of 2 people, we may not have power to set state events
like custom status.  Ensure that we do before sending.
This commit is contained in:
J. Ryan Stinnett
2019-01-11 19:03:20 -06:00
parent c979ff6696
commit 2563abda11

View File

@@ -2280,16 +2280,21 @@ MatrixClient.prototype.mxcUrlToHttp =
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype._unstable_setStatusMessage = function(newMessage) {
const type = "im.vector.user_status";
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 {
if (!isJoined || !looksLikeDm) {
return Promise.resolve();
}
// Check power level separately as it's a bit more expensive.
const maySend = room.currentState.mayClientSendStateEvent(type, this);
if (!maySend) {
return Promise.resolve();
}
return this.sendStateEvent(room.roomId, type, {
status: newMessage,
}, this.getUserId());
}));
};