Include room tags in v2 /sync
This commit is contained in:
parent
ddd8566f41
commit
57be722c46
|
@ -147,6 +147,10 @@ class FilterCollection(object):
|
||||||
self.filter_json.get("room", {}).get("ephemeral", {})
|
self.filter_json.get("room", {}).get("ephemeral", {})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.room_private_user_data = Filter(
|
||||||
|
self.filter_json.get("room", {}).get("private_user_data", {})
|
||||||
|
)
|
||||||
|
|
||||||
self.presence_filter = Filter(
|
self.presence_filter = Filter(
|
||||||
self.filter_json.get("presence", {})
|
self.filter_json.get("presence", {})
|
||||||
)
|
)
|
||||||
|
@ -172,6 +176,9 @@ class FilterCollection(object):
|
||||||
def filter_room_ephemeral(self, events):
|
def filter_room_ephemeral(self, events):
|
||||||
return self.room_ephemeral_filter.filter(events)
|
return self.room_ephemeral_filter.filter(events)
|
||||||
|
|
||||||
|
def filter_room_private_user_data(self, events):
|
||||||
|
return self.room_private_user_data.filter(events)
|
||||||
|
|
||||||
|
|
||||||
class Filter(object):
|
class Filter(object):
|
||||||
def __init__(self, filter_json):
|
def __init__(self, filter_json):
|
||||||
|
|
|
@ -51,6 +51,7 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"timeline",
|
"timeline",
|
||||||
"state",
|
"state",
|
||||||
"ephemeral",
|
"ephemeral",
|
||||||
|
"private_user_data",
|
||||||
])):
|
])):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
|
@ -58,13 +59,19 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"""Make the result appear empty if there are no updates. This is used
|
"""Make the result appear empty if there are no updates. This is used
|
||||||
to tell if room needs to be part of the sync result.
|
to tell if room needs to be part of the sync result.
|
||||||
"""
|
"""
|
||||||
return bool(self.timeline or self.state or self.ephemeral)
|
return bool(
|
||||||
|
self.timeline
|
||||||
|
or self.state
|
||||||
|
or self.ephemeral
|
||||||
|
or self.private_user_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ArchivedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
class ArchivedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"room_id",
|
"room_id",
|
||||||
"timeline",
|
"timeline",
|
||||||
"state",
|
"state",
|
||||||
|
"private_user_data",
|
||||||
])):
|
])):
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
|
|
||||||
|
@ -72,7 +79,11 @@ class ArchivedSyncResult(collections.namedtuple("JoinedSyncResult", [
|
||||||
"""Make the result appear empty if there are no updates. This is used
|
"""Make the result appear empty if there are no updates. This is used
|
||||||
to tell if room needs to be part of the sync result.
|
to tell if room needs to be part of the sync result.
|
||||||
"""
|
"""
|
||||||
return bool(self.timeline or self.state)
|
return bool(
|
||||||
|
self.timeline
|
||||||
|
or self.state
|
||||||
|
or self.private_user_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
|
class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
|
||||||
|
@ -197,6 +208,10 @@ class SyncHandler(BaseHandler):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tags_by_room = yield self.store.get_tags_for_user(
|
||||||
|
sync_config.user.to_string()
|
||||||
|
)
|
||||||
|
|
||||||
joined = []
|
joined = []
|
||||||
invited = []
|
invited = []
|
||||||
archived = []
|
archived = []
|
||||||
|
@ -207,7 +222,8 @@ class SyncHandler(BaseHandler):
|
||||||
sync_config=sync_config,
|
sync_config=sync_config,
|
||||||
now_token=now_token,
|
now_token=now_token,
|
||||||
timeline_since_token=timeline_since_token,
|
timeline_since_token=timeline_since_token,
|
||||||
typing_by_room=typing_by_room
|
typing_by_room=typing_by_room,
|
||||||
|
tags_by_room=tags_by_room,
|
||||||
)
|
)
|
||||||
joined.append(room_sync)
|
joined.append(room_sync)
|
||||||
elif event.membership == Membership.INVITE:
|
elif event.membership == Membership.INVITE:
|
||||||
|
@ -226,6 +242,7 @@ class SyncHandler(BaseHandler):
|
||||||
leave_event_id=event.event_id,
|
leave_event_id=event.event_id,
|
||||||
leave_token=leave_token,
|
leave_token=leave_token,
|
||||||
timeline_since_token=timeline_since_token,
|
timeline_since_token=timeline_since_token,
|
||||||
|
tags_by_room=tags_by_room,
|
||||||
)
|
)
|
||||||
archived.append(room_sync)
|
archived.append(room_sync)
|
||||||
|
|
||||||
|
@ -240,7 +257,7 @@ class SyncHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def full_state_sync_for_joined_room(self, room_id, sync_config,
|
def full_state_sync_for_joined_room(self, room_id, sync_config,
|
||||||
now_token, timeline_since_token,
|
now_token, timeline_since_token,
|
||||||
typing_by_room):
|
typing_by_room, tags_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.
|
||||||
|
@ -260,8 +277,21 @@ class SyncHandler(BaseHandler):
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=current_state_events,
|
state=current_state_events,
|
||||||
ephemeral=typing_by_room.get(room_id, []),
|
ephemeral=typing_by_room.get(room_id, []),
|
||||||
|
private_user_data=self.private_user_data_for_room(
|
||||||
|
room_id, tags_by_room
|
||||||
|
),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def private_user_data_for_room(self, room_id, tags_by_room):
|
||||||
|
private_user_data = []
|
||||||
|
tags = tags_by_room.get(room_id)
|
||||||
|
if tags:
|
||||||
|
private_user_data.append({
|
||||||
|
"type": "m.tag",
|
||||||
|
"content": {"tags": tags},
|
||||||
|
})
|
||||||
|
return private_user_data
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def typing_by_room(self, sync_config, now_token, since_token=None):
|
def typing_by_room(self, sync_config, now_token, since_token=None):
|
||||||
"""Get the typing events for each room the user is in
|
"""Get the typing events for each room the user is in
|
||||||
|
@ -296,7 +326,7 @@ class SyncHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def full_state_sync_for_archived_room(self, room_id, sync_config,
|
def full_state_sync_for_archived_room(self, room_id, sync_config,
|
||||||
leave_event_id, leave_token,
|
leave_event_id, leave_token,
|
||||||
timeline_since_token):
|
timeline_since_token, tags_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.
|
||||||
|
@ -314,6 +344,9 @@ class SyncHandler(BaseHandler):
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=leave_state[leave_event_id].values(),
|
state=leave_state[leave_event_id].values(),
|
||||||
|
private_user_data=self.private_user_data_for_room(
|
||||||
|
room_id, tags_by_room
|
||||||
|
),
|
||||||
))
|
))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -359,6 +392,11 @@ class SyncHandler(BaseHandler):
|
||||||
limit=timeline_limit + 1,
|
limit=timeline_limit + 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tags_by_room = yield self.store.get_updated_tags(
|
||||||
|
sync_config.user.to_string(),
|
||||||
|
since_token.private_user_data_key,
|
||||||
|
)
|
||||||
|
|
||||||
joined = []
|
joined = []
|
||||||
archived = []
|
archived = []
|
||||||
if len(room_events) <= timeline_limit:
|
if len(room_events) <= timeline_limit:
|
||||||
|
@ -399,7 +437,10 @@ class SyncHandler(BaseHandler):
|
||||||
limited=limited,
|
limited=limited,
|
||||||
),
|
),
|
||||||
state=state,
|
state=state,
|
||||||
ephemeral=typing_by_room.get(room_id, [])
|
ephemeral=typing_by_room.get(room_id, []),
|
||||||
|
private_user_data=self.private_user_data_for_room(
|
||||||
|
room_id, tags_by_room
|
||||||
|
),
|
||||||
)
|
)
|
||||||
if room_sync:
|
if room_sync:
|
||||||
joined.append(room_sync)
|
joined.append(room_sync)
|
||||||
|
@ -416,14 +457,14 @@ class SyncHandler(BaseHandler):
|
||||||
for room_id in joined_room_ids:
|
for room_id in joined_room_ids:
|
||||||
room_sync = yield self.incremental_sync_with_gap_for_room(
|
room_sync = yield self.incremental_sync_with_gap_for_room(
|
||||||
room_id, sync_config, since_token, now_token,
|
room_id, sync_config, since_token, now_token,
|
||||||
typing_by_room
|
typing_by_room, tags_by_room
|
||||||
)
|
)
|
||||||
if room_sync:
|
if room_sync:
|
||||||
joined.append(room_sync)
|
joined.append(room_sync)
|
||||||
|
|
||||||
for leave_event in leave_events:
|
for leave_event in leave_events:
|
||||||
room_sync = yield self.incremental_sync_for_archived_room(
|
room_sync = yield self.incremental_sync_for_archived_room(
|
||||||
sync_config, leave_event, since_token
|
sync_config, leave_event, since_token, tags_by_room
|
||||||
)
|
)
|
||||||
archived.append(room_sync)
|
archived.append(room_sync)
|
||||||
|
|
||||||
|
@ -487,7 +528,7 @@ class SyncHandler(BaseHandler):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def incremental_sync_with_gap_for_room(self, room_id, sync_config,
|
def incremental_sync_with_gap_for_room(self, room_id, sync_config,
|
||||||
since_token, now_token,
|
since_token, now_token,
|
||||||
typing_by_room):
|
typing_by_room, tags_by_room):
|
||||||
""" Get the incremental delta needed to bring the client up to date for
|
""" Get the incremental delta needed to bring the client up to date for
|
||||||
the room. Gives the client the most recent events and the changes to
|
the room. Gives the client the most recent events and the changes to
|
||||||
state.
|
state.
|
||||||
|
@ -528,7 +569,10 @@ class SyncHandler(BaseHandler):
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=state_events_delta,
|
state=state_events_delta,
|
||||||
ephemeral=typing_by_room.get(room_id, [])
|
ephemeral=typing_by_room.get(room_id, []),
|
||||||
|
private_user_data=self.private_user_data_for_room(
|
||||||
|
room_id, tags_by_room
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.debug("Room sync: %r", room_sync)
|
logging.debug("Room sync: %r", room_sync)
|
||||||
|
@ -537,7 +581,7 @@ class SyncHandler(BaseHandler):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def incremental_sync_for_archived_room(self, sync_config, leave_event,
|
def incremental_sync_for_archived_room(self, sync_config, leave_event,
|
||||||
since_token):
|
since_token, tags_by_room):
|
||||||
""" Get the incremental delta needed to bring the client up to date for
|
""" Get the incremental delta needed to bring the client up to date for
|
||||||
the archived room.
|
the archived room.
|
||||||
Returns:
|
Returns:
|
||||||
|
@ -578,6 +622,9 @@ class SyncHandler(BaseHandler):
|
||||||
room_id=leave_event.room_id,
|
room_id=leave_event.room_id,
|
||||||
timeline=batch,
|
timeline=batch,
|
||||||
state=state_events_delta,
|
state=state_events_delta,
|
||||||
|
private_user_data=self.private_user_data_for_room(
|
||||||
|
leave_event.room_id, tags_by_room
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.debug("Room sync: %r", room_sync)
|
logging.debug("Room sync: %r", room_sync)
|
||||||
|
|
|
@ -220,6 +220,10 @@ class SyncRestServlet(RestServlet):
|
||||||
)
|
)
|
||||||
timeline_event_ids.append(event.event_id)
|
timeline_event_ids.append(event.event_id)
|
||||||
|
|
||||||
|
private_user_data = filter.filter_room_private_user_data(
|
||||||
|
room.private_user_data
|
||||||
|
)
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"event_map": event_map,
|
"event_map": event_map,
|
||||||
"timeline": {
|
"timeline": {
|
||||||
|
@ -228,6 +232,7 @@ class SyncRestServlet(RestServlet):
|
||||||
"limited": room.timeline.limited,
|
"limited": room.timeline.limited,
|
||||||
},
|
},
|
||||||
"state": {"events": state_event_ids},
|
"state": {"events": state_event_ids},
|
||||||
|
"private_user_data": {"events": private_user_data},
|
||||||
}
|
}
|
||||||
|
|
||||||
if joined:
|
if joined:
|
||||||
|
|
Loading…
Reference in New Issue