mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Get left rooms
This commit is contained in:
parent
9ce866ed4f
commit
473700f016
@ -840,7 +840,7 @@ class SyncHandler(object):
|
|||||||
|
|
||||||
if since_token:
|
if since_token:
|
||||||
res = yield self._get_rooms_changed(sync_result_builder, ignored_users)
|
res = yield self._get_rooms_changed(sync_result_builder, ignored_users)
|
||||||
room_entries, invited, newly_joined_rooms = res
|
room_entries, invited, newly_joined_rooms, newly_left_rooms = res
|
||||||
|
|
||||||
tags_by_room = yield self.store.get_updated_tags(
|
tags_by_room = yield self.store.get_updated_tags(
|
||||||
user_id, since_token.account_data_key,
|
user_id, since_token.account_data_key,
|
||||||
@ -848,6 +848,7 @@ class SyncHandler(object):
|
|||||||
else:
|
else:
|
||||||
res = yield self._get_all_rooms(sync_result_builder, ignored_users)
|
res = yield self._get_all_rooms(sync_result_builder, ignored_users)
|
||||||
room_entries, invited, newly_joined_rooms = res
|
room_entries, invited, newly_joined_rooms = res
|
||||||
|
newly_left_rooms = []
|
||||||
|
|
||||||
tags_by_room = yield self.store.get_tags_for_user(user_id)
|
tags_by_room = yield self.store.get_tags_for_user(user_id)
|
||||||
|
|
||||||
@ -885,7 +886,13 @@ class SyncHandler(object):
|
|||||||
newly_left_users.add(event.state_key)
|
newly_left_users.add(event.state_key)
|
||||||
|
|
||||||
newly_left_users -= newly_joined_users
|
newly_left_users -= newly_joined_users
|
||||||
defer.returnValue((newly_joined_rooms, newly_joined_users, [], newly_left_users))
|
|
||||||
|
defer.returnValue((
|
||||||
|
newly_joined_rooms,
|
||||||
|
newly_joined_users,
|
||||||
|
newly_left_rooms,
|
||||||
|
newly_left_users,
|
||||||
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _have_rooms_changed(self, sync_result_builder):
|
def _have_rooms_changed(self, sync_result_builder):
|
||||||
@ -955,6 +962,7 @@ class SyncHandler(object):
|
|||||||
mem_change_events_by_room_id.setdefault(event.room_id, []).append(event)
|
mem_change_events_by_room_id.setdefault(event.room_id, []).append(event)
|
||||||
|
|
||||||
newly_joined_rooms = []
|
newly_joined_rooms = []
|
||||||
|
newly_left_rooms = []
|
||||||
room_entries = []
|
room_entries = []
|
||||||
invited = []
|
invited = []
|
||||||
for room_id, events in mem_change_events_by_room_id.iteritems():
|
for room_id, events in mem_change_events_by_room_id.iteritems():
|
||||||
@ -964,6 +972,7 @@ class SyncHandler(object):
|
|||||||
# We want to figure out if we joined the room at some point since
|
# We want to figure out if we joined the room at some point since
|
||||||
# the last sync (even if we have since left). This is to make sure
|
# the last sync (even if we have since left). This is to make sure
|
||||||
# we do send down the room, and with full state, where necessary
|
# we do send down the room, and with full state, where necessary
|
||||||
|
old_state_ids = None
|
||||||
if room_id in joined_room_ids or has_join:
|
if room_id in joined_room_ids or has_join:
|
||||||
old_state_ids = yield self.get_state_at(room_id, since_token)
|
old_state_ids = yield self.get_state_at(room_id, since_token)
|
||||||
old_mem_ev_id = old_state_ids.get((EventTypes.Member, user_id), None)
|
old_mem_ev_id = old_state_ids.get((EventTypes.Member, user_id), None)
|
||||||
@ -981,6 +990,26 @@ class SyncHandler(object):
|
|||||||
if not non_joins:
|
if not non_joins:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Check if we have left the room. This can either be because we were
|
||||||
|
# joined before *or* that we since joined and then left.
|
||||||
|
if events[-1].membership != Membership.JOIN:
|
||||||
|
if has_join:
|
||||||
|
newly_left_rooms.append(room_id)
|
||||||
|
else:
|
||||||
|
if not old_state_ids:
|
||||||
|
old_state_ids = yield self.get_state_at(room_id, since_token)
|
||||||
|
old_mem_ev_id = old_state_ids.get(
|
||||||
|
(EventTypes.Member, user_id),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
old_mem_ev = None
|
||||||
|
if old_mem_ev_id:
|
||||||
|
old_mem_ev = yield self.store.get_event(
|
||||||
|
old_mem_ev_id, allow_none=True
|
||||||
|
)
|
||||||
|
if old_mem_ev and old_mem_ev.membership == Membership.JOIN:
|
||||||
|
newly_left_rooms.append(room_id)
|
||||||
|
|
||||||
# Only bother if we're still currently invited
|
# Only bother if we're still currently invited
|
||||||
should_invite = non_joins[-1].membership == Membership.INVITE
|
should_invite = non_joins[-1].membership == Membership.INVITE
|
||||||
if should_invite:
|
if should_invite:
|
||||||
@ -1058,7 +1087,7 @@ class SyncHandler(object):
|
|||||||
upto_token=since_token,
|
upto_token=since_token,
|
||||||
))
|
))
|
||||||
|
|
||||||
defer.returnValue((room_entries, invited, newly_joined_rooms))
|
defer.returnValue((room_entries, invited, newly_joined_rooms, newly_left_rooms))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_all_rooms(self, sync_result_builder, ignored_users):
|
def _get_all_rooms(self, sync_result_builder, ignored_users):
|
||||||
|
Loading…
Reference in New Issue
Block a user