Skip to content

Commit

Permalink
Account for encryption in maySendMessage() (#2159)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBrandner authored Feb 7, 2022
1 parent 2d23330 commit 12afcd3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/unit/room.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ describe("Room", function() {
describe("maySendMessage", function() {
it("should return false if synced membership not join",
function() {
const room = new Room(roomId, null, userA);
const room = new Room(roomId, { isRoomEncrypted: () => false }, userA);
room.updateMyMembership("invite");
expect(room.maySendMessage()).toEqual(false);
room.updateMyMembership("leave");
Expand Down
5 changes: 3 additions & 2 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2199,8 +2199,9 @@ export class Room extends EventEmitter {
* message events into the room.
*/
public maySendMessage(): boolean {
return this.getMyMembership() === 'join' &&
this.currentState.maySendEvent(EventType.RoomMessage, this.myUserId);
return this.getMyMembership() === 'join' && (this.client.isRoomEncrypted(this.roomId)
? this.currentState.maySendEvent(EventType.RoomMessageEncrypted, this.myUserId)
: this.currentState.maySendEvent(EventType.RoomMessage, this.myUserId));
}

/**
Expand Down

0 comments on commit 12afcd3

Please sign in to comment.