mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
add _get_room_member, fix datastore methods
This commit is contained in:
parent
a0d1f5a014
commit
b30358f439
@ -78,7 +78,9 @@ class Auth(object):
|
||||
|
||||
def _check_joined_room(self, member, user_id, room_id):
|
||||
if not member or member.membership != Membership.JOIN:
|
||||
raise AuthError(403, "User %s not in room %s" % (user_id, room_id))
|
||||
raise AuthError(403, "User %s not in room %s (%s)" % (
|
||||
user_id, room_id, repr(member)
|
||||
))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def is_membership_change_allowed(self, event):
|
||||
|
@ -214,7 +214,7 @@ class FederationHandler(BaseHandler):
|
||||
|
||||
@log_function
|
||||
@defer.inlineCallbacks
|
||||
def do_invite_join(self, target_host, room_id, joinee, content):
|
||||
def do_invite_join(self, target_host, room_id, joinee, content, snapshot):
|
||||
|
||||
hosts = yield self.store.get_joined_hosts_for_room(room_id)
|
||||
if self.hs.hostname in hosts:
|
||||
@ -244,7 +244,8 @@ class FederationHandler(BaseHandler):
|
||||
|
||||
new_event.destinations = [target_host]
|
||||
|
||||
yield self.handle_new_event(new_event)
|
||||
snapshot.fill_out_prev_events(new_event)
|
||||
yield self.handle_new_event(new_event, snapshot)
|
||||
|
||||
# TODO (erikj): Time out here.
|
||||
d = defer.Deferred()
|
||||
|
@ -637,7 +637,7 @@ class RoomMemberHandler(BaseRoomHandler):
|
||||
if should_do_dance:
|
||||
handler = self.hs.get_handlers().federation_handler
|
||||
have_joined = yield handler.do_invite_join(
|
||||
room_host, room_id, event.user_id, event.content
|
||||
room_host, room_id, event.user_id, event.content, snapshot
|
||||
)
|
||||
|
||||
# We want to do the _do_update inside the room lock.
|
||||
|
@ -94,11 +94,11 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
def _persist_pdu_event_txn(self, txn, pdu=None, event=None,
|
||||
backfilled=False, stream_ordering=None):
|
||||
if pdu is not None:
|
||||
self._persist_pdu_txn(txn, pdu)
|
||||
self._persist_event_pdu_txn(txn, pdu)
|
||||
if event is not None:
|
||||
self._persist_event_txn(txn, event, backfilled, stream_ordering)
|
||||
|
||||
def _persist_pdu_txn(self, txn, pdu):
|
||||
def _persist_event_pdu_txn(self, txn, pdu):
|
||||
cols = dict(pdu.__dict__)
|
||||
unrec_keys = dict(pdu.unrecognized_keys)
|
||||
del cols["content"]
|
||||
@ -185,7 +185,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
}
|
||||
)
|
||||
|
||||
return self._get_room_events_max_id_(txn)
|
||||
return self._get_room_events_max_id_txn(txn)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_current_state(self, room_id, event_type=None, state_key=""):
|
||||
@ -232,7 +232,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
synapse.storage.Snapshot: A snapshot of the state of the room.
|
||||
"""
|
||||
def _snapshot(txn):
|
||||
membership_state = self._get_room_member(txn, user_id)
|
||||
membership_state = self._get_room_member(txn, user_id, room_id)
|
||||
prev_pdus = self._get_latest_pdus_in_context(
|
||||
txn, room_id
|
||||
)
|
||||
@ -279,7 +279,7 @@ class Snapshot(object):
|
||||
self.room_id = room_id
|
||||
self.user_id = user_id
|
||||
self.prev_pdus = prev_pdus
|
||||
self.membership_state
|
||||
self.membership_state = membership_state
|
||||
self.state_type = state_type
|
||||
self.state_key = state_key
|
||||
self.prev_state_pdu = prev_state_pdu
|
||||
@ -295,7 +295,7 @@ class Snapshot(object):
|
||||
event.prev_events = [e for e in es if e != event.event_id]
|
||||
|
||||
if self.prev_pdus:
|
||||
event.depth = max([int(v) for _, _, v in results]) + 1
|
||||
event.depth = max([int(v) for _, _, v in self.prev_pdus]) + 1
|
||||
else:
|
||||
event.depth = 0
|
||||
|
||||
|
@ -50,13 +50,13 @@ class RoomMemberStore(SQLBaseStore):
|
||||
"INSERT OR IGNORE INTO room_hosts (room_id, host) "
|
||||
"VALUES (?, ?)"
|
||||
)
|
||||
txn.execute(sql, event.room_id, domain)
|
||||
txn.execute(sql, (event.room_id, domain))
|
||||
else:
|
||||
sql = (
|
||||
"DELETE FROM room_hosts WHERE room_id = ? AND host = ?"
|
||||
)
|
||||
|
||||
txn.execute(sql, event.room_id, domain)
|
||||
txn.execute(sql, (event.room_id, domain))
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_member(self, user_id, room_id):
|
||||
@ -75,6 +75,24 @@ class RoomMemberStore(SQLBaseStore):
|
||||
|
||||
defer.returnValue(rows[0] if rows else None)
|
||||
|
||||
def _get_room_member(self, txn, user_id, room_id):
|
||||
sql = (
|
||||
"SELECT e.* FROM events as e"
|
||||
" INNER JOIN room_memberships as m"
|
||||
" ON e.event_id = m.event_id"
|
||||
" INNER JOIN current_state_events as c"
|
||||
" ON m.event_id = c.event_id"
|
||||
" WHERE m.user_id = ? and e.room_id = ?"
|
||||
" LIMIT 1"
|
||||
)
|
||||
txn.execute(sql, (user_id, room_id))
|
||||
rows = self.cursor_to_dict(txn)
|
||||
if rows:
|
||||
return self._parse_event_from_row(rows[0])
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_room_members(self, room_id, membership=None):
|
||||
"""Retrieve the current room member list for a room.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user