mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #321 from matrix-org/markjh/v2_sync_typing
Include typing events in initial v2 sync
This commit is contained in:
commit
13a6e9beaf
@ -164,6 +164,10 @@ class SyncHandler(BaseHandler):
|
|||||||
"""
|
"""
|
||||||
now_token = yield self.event_sources.get_current_token()
|
now_token = yield self.event_sources.get_current_token()
|
||||||
|
|
||||||
|
now_token, typing_by_room = yield self.typing_by_room(
|
||||||
|
sync_config, now_token
|
||||||
|
)
|
||||||
|
|
||||||
presence_stream = self.event_sources.sources["presence"]
|
presence_stream = self.event_sources.sources["presence"]
|
||||||
# TODO (mjark): This looks wrong, shouldn't we be getting the presence
|
# TODO (mjark): This looks wrong, shouldn't we be getting the presence
|
||||||
# UP to the present rather than after the present?
|
# UP to the present rather than after the present?
|
||||||
@ -189,7 +193,7 @@ class SyncHandler(BaseHandler):
|
|||||||
for event in room_list:
|
for event in room_list:
|
||||||
if event.membership == Membership.JOIN:
|
if event.membership == Membership.JOIN:
|
||||||
room_sync = yield self.initial_sync_for_joined_room(
|
room_sync = yield self.initial_sync_for_joined_room(
|
||||||
event.room_id, sync_config, now_token,
|
event.room_id, sync_config, now_token, typing_by_room
|
||||||
)
|
)
|
||||||
joined.append(room_sync)
|
joined.append(room_sync)
|
||||||
elif event.membership == Membership.INVITE:
|
elif event.membership == Membership.INVITE:
|
||||||
@ -219,7 +223,8 @@ class SyncHandler(BaseHandler):
|
|||||||
))
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def initial_sync_for_joined_room(self, room_id, sync_config, now_token):
|
def initial_sync_for_joined_room(self, room_id, sync_config, now_token,
|
||||||
|
typing_by_room):
|
||||||
"""Sync a room for a client which is starting without any state
|
"""Sync a room for a client which is starting without any state
|
||||||
Returns:
|
Returns:
|
||||||
A Deferred JoinedSyncResult.
|
A Deferred JoinedSyncResult.
|
||||||
@ -238,9 +243,40 @@ class SyncHandler(BaseHandler):
|
|||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=current_state_events,
|
state=current_state_events,
|
||||||
ephemeral=[],
|
ephemeral=typing_by_room.get(room_id, []),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def typing_by_room(self, sync_config, now_token, since_token=None):
|
||||||
|
"""Get the typing events for each room the user is in
|
||||||
|
Args:
|
||||||
|
sync_config (SyncConfig): The flags, filters and user for the sync.
|
||||||
|
now_token (StreamToken): Where the server is currently up to.
|
||||||
|
since_token (StreamToken): Where the server was when the client
|
||||||
|
last synced.
|
||||||
|
Returns:
|
||||||
|
A tuple of the now StreamToken, updated to reflect the which typing
|
||||||
|
events are included, and a dict mapping from room_id to a list of
|
||||||
|
typing events for that room.
|
||||||
|
"""
|
||||||
|
|
||||||
|
typing_key = since_token.typing_key if since_token else "0"
|
||||||
|
|
||||||
|
typing_source = self.event_sources.sources["typing"]
|
||||||
|
typing, typing_key = yield typing_source.get_new_events_for_user(
|
||||||
|
user=sync_config.user,
|
||||||
|
from_key=typing_key,
|
||||||
|
limit=sync_config.filter.ephemeral_limit(),
|
||||||
|
)
|
||||||
|
now_token = now_token.copy_and_replace("typing_key", typing_key)
|
||||||
|
|
||||||
|
typing_by_room = {event["room_id"]: [event] for event in typing}
|
||||||
|
for event in typing:
|
||||||
|
event.pop("room_id")
|
||||||
|
logger.debug("Typing %r", typing_by_room)
|
||||||
|
|
||||||
|
defer.returnValue((now_token, typing_by_room))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def initial_sync_for_archived_room(self, room_id, sync_config,
|
def initial_sync_for_archived_room(self, room_id, sync_config,
|
||||||
leave_event_id, leave_token):
|
leave_event_id, leave_token):
|
||||||
@ -280,18 +316,9 @@ class SyncHandler(BaseHandler):
|
|||||||
)
|
)
|
||||||
now_token = now_token.copy_and_replace("presence_key", presence_key)
|
now_token = now_token.copy_and_replace("presence_key", presence_key)
|
||||||
|
|
||||||
typing_source = self.event_sources.sources["typing"]
|
now_token, typing_by_room = yield self.typing_by_room(
|
||||||
typing, typing_key = yield typing_source.get_new_events_for_user(
|
sync_config, now_token, since_token
|
||||||
user=sync_config.user,
|
|
||||||
from_key=since_token.typing_key,
|
|
||||||
limit=sync_config.filter.ephemeral_limit(),
|
|
||||||
)
|
)
|
||||||
now_token = now_token.copy_and_replace("typing_key", typing_key)
|
|
||||||
|
|
||||||
typing_by_room = {event["room_id"]: [event] for event in typing}
|
|
||||||
for event in typing:
|
|
||||||
event.pop("room_id")
|
|
||||||
logger.debug("Typing %r", typing_by_room)
|
|
||||||
|
|
||||||
rm_handler = self.hs.get_handlers().room_member_handler
|
rm_handler = self.hs.get_handlers().room_member_handler
|
||||||
app_service = yield self.store.get_app_service_by_user_id(
|
app_service = yield self.store.get_app_service_by_user_id(
|
||||||
|
Loading…
Reference in New Issue
Block a user