diff options
author | Erik Johnston <erik@matrix.org> | 2016-03-30 15:55:24 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-03-30 15:55:24 +0100 |
commit | 178c9fb200a059d9a6bee667a11c558f1dabac0c (patch) | |
tree | b16077c97956a6634f8f548ec7cd8420f555d838 /synapse/handlers | |
parent | Merge branch 'master' of github.com:matrix-org/synapse into develop (diff) | |
parent | Only forget room if you were in the room (diff) | |
download | synapse-178c9fb200a059d9a6bee667a11c558f1dabac0c.tar.xz |
Merge pull request #673 from matrix-org/erikj/forget
Require user to have left room to forget room
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/room.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 133183a257..71f7ab3d22 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -416,8 +416,6 @@ class RoomMemberHandler(BaseHandler): effective_membership_state = action if action in ["kick", "unban"]: effective_membership_state = "leave" - elif action == "forget": - effective_membership_state = "leave" if third_party_signed is not None: replication = self.hs.get_replication_layer() @@ -473,9 +471,6 @@ class RoomMemberHandler(BaseHandler): remote_room_hosts=remote_room_hosts, ) - if action == "forget": - yield self.forget(requester.user, room_id) - @defer.inlineCallbacks def send_membership_event( self, @@ -935,8 +930,24 @@ class RoomMemberHandler(BaseHandler): display_name = data["display_name"] defer.returnValue((token, public_keys, fallback_public_key, display_name)) + @defer.inlineCallbacks def forget(self, user, room_id): - return self.store.forget(user.to_string(), room_id) + user_id = user.to_string() + + member = yield self.state_handler.get_current_state( + room_id=room_id, + event_type=EventTypes.Member, + state_key=user_id + ) + membership = member.membership if member else None + + if membership is not None and membership != Membership.LEAVE: + raise SynapseError(400, "User %s in room %s" % ( + user_id, room_id + )) + + if membership: + yield self.store.forget(user_id, room_id) class RoomListHandler(BaseHandler): |