diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-11 18:52:35 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-11 18:52:35 +0100 |
commit | 249e8f227799c2b5f1adcd17a471ff9773b43f14 (patch) | |
tree | d8053510a222295e850002a0b966fb4f5435baf5 /synapse | |
parent | Rename _store_room_member_txn to _store_room_member_from_event_txn so we can ... (diff) | |
download | synapse-249e8f227799c2b5f1adcd17a471ff9773b43f14.tar.xz |
Add a better _store_room_member_txn() method that takes separated fields instead of an event object; also add FIXME comment about a big bug in the logic
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/roommember.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index 437ff03a73..b357dc3058 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -27,36 +27,49 @@ logger = logging.getLogger(__name__) class RoomMemberStore(SQLBaseStore): def _store_room_member_from_event_txn(self, txn, event): + self._store_room_member_txn(txn, + target_user_id=event.state_key, + sender_user_id=event.user_id, + room_id=event.room_id, + event_id=event.event_id, + membership=event.membership, + ) + + def _store_room_member_txn(self, txn, target_user_id, sender_user_id, + room_id, event_id, membership): """Store a room member in the database. """ - target_user_id = event.state_key domain = self.hs.parse_userid(target_user_id).domain self._simple_insert_txn( txn, "room_memberships", { - "event_id": event.event_id, + "event_id": event_id, "user_id": target_user_id, - "sender": event.user_id, - "room_id": event.room_id, - "membership": event.membership, + "sender": sender_user_id, + "room_id": room_id, + "membership": membership, } ) # Update room hosts table - if event.membership == Membership.JOIN: + # TODO(paul): This code is massively broken currently as it doesn't + # count users per room - meaning it'll delete on the FIRST user to + # have a membership other than JOIN - say, LEAVE, or even INVITE. + # FIXME + if membership == Membership.JOIN: sql = ( "INSERT OR IGNORE INTO room_hosts (room_id, host) " "VALUES (?, ?)" ) - txn.execute(sql, (event.room_id, domain)) + txn.execute(sql, (room_id, domain)) else: sql = ( "DELETE FROM room_hosts WHERE room_id = ? AND host = ?" ) - txn.execute(sql, (event.room_id, domain)) + txn.execute(sql, (room_id, domain)) @defer.inlineCallbacks def get_room_member(self, user_id, room_id): |