Skip to content

Commit

Permalink
Use RoomEvent.MyMembership in auto-join example (#4130)
Browse files Browse the repository at this point in the history
This seems easier / more efficient than listening to all membership events and then filtering by user ID.
  • Loading branch information
Johennes authored Mar 25, 2024
1 parent d5a35f8 commit 63d4195
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ const matrixClient = sdk.createClient({
### Automatically join rooms when invited

```javascript
matrixClient.on(RoomMemberEvent.Membership, function (event, member) {
if (member.membership === KnownMembership.Invite && member.userId === myUserId) {
matrixClient.joinRoom(member.roomId).then(function () {
console.log("Auto-joined %s", member.roomId);
matrixClient.on(RoomEvent.MyMembership, function (room, membership, prevMembership) {
if (membership === KnownMembership.Invite) {
matrixClient.joinRoom(room.roomId).then(function () {
console.log("Auto-joined %s", room.roomId);
});
}
});
Expand Down

0 comments on commit 63d4195

Please sign in to comment.