|
|
@ -18,6 +18,7 @@ from twisted.internet import defer |
|
|
|
from synapse.api.constants import EventTypes, Membership |
|
|
|
from synapse.api.constants import EventTypes, Membership |
|
|
|
from synapse.api.errors import RoomError |
|
|
|
from synapse.api.errors import RoomError |
|
|
|
from synapse.streams.config import PaginationConfig |
|
|
|
from synapse.streams.config import PaginationConfig |
|
|
|
|
|
|
|
from synapse.events.utils import serialize_event |
|
|
|
from synapse.events.validator import EventValidator |
|
|
|
from synapse.events.validator import EventValidator |
|
|
|
from synapse.util.logcontext import PreserveLoggingContext |
|
|
|
from synapse.util.logcontext import PreserveLoggingContext |
|
|
|
from synapse.types import UserID |
|
|
|
from synapse.types import UserID |
|
|
@ -100,9 +101,11 @@ class MessageHandler(BaseHandler): |
|
|
|
"room_key", next_key |
|
|
|
"room_key", next_key |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time_now = self.clock.time_msec() |
|
|
|
|
|
|
|
|
|
|
|
chunk = { |
|
|
|
chunk = { |
|
|
|
"chunk": [ |
|
|
|
"chunk": [ |
|
|
|
self.hs.serialize_event(e, as_client_event) for e in events |
|
|
|
serialize_event(e, time_now, as_client_event) for e in events |
|
|
|
], |
|
|
|
], |
|
|
|
"start": pagin_config.from_token.to_string(), |
|
|
|
"start": pagin_config.from_token.to_string(), |
|
|
|
"end": next_token.to_string(), |
|
|
|
"end": next_token.to_string(), |
|
|
@ -211,7 +214,8 @@ class MessageHandler(BaseHandler): |
|
|
|
|
|
|
|
|
|
|
|
# TODO: This is duplicating logic from snapshot_all_rooms |
|
|
|
# TODO: This is duplicating logic from snapshot_all_rooms |
|
|
|
current_state = yield self.state_handler.get_current_state(room_id) |
|
|
|
current_state = yield self.state_handler.get_current_state(room_id) |
|
|
|
defer.returnValue([self.hs.serialize_event(c) for c in current_state]) |
|
|
|
now = self.clock.time_msec() |
|
|
|
|
|
|
|
defer.returnValue([serialize_event(c, now) for c in current_state]) |
|
|
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
@defer.inlineCallbacks |
|
|
|
def snapshot_all_rooms(self, user_id=None, pagin_config=None, |
|
|
|
def snapshot_all_rooms(self, user_id=None, pagin_config=None, |
|
|
@ -283,10 +287,11 @@ class MessageHandler(BaseHandler): |
|
|
|
|
|
|
|
|
|
|
|
start_token = now_token.copy_and_replace("room_key", token[0]) |
|
|
|
start_token = now_token.copy_and_replace("room_key", token[0]) |
|
|
|
end_token = now_token.copy_and_replace("room_key", token[1]) |
|
|
|
end_token = now_token.copy_and_replace("room_key", token[1]) |
|
|
|
|
|
|
|
time_now = self.clock.time_msec() |
|
|
|
|
|
|
|
|
|
|
|
d["messages"] = { |
|
|
|
d["messages"] = { |
|
|
|
"chunk": [ |
|
|
|
"chunk": [ |
|
|
|
self.hs.serialize_event(m, as_client_event) |
|
|
|
serialize_event(m, time_now, as_client_event) |
|
|
|
for m in messages |
|
|
|
for m in messages |
|
|
|
], |
|
|
|
], |
|
|
|
"start": start_token.to_string(), |
|
|
|
"start": start_token.to_string(), |
|
|
@ -297,7 +302,8 @@ class MessageHandler(BaseHandler): |
|
|
|
event.room_id |
|
|
|
event.room_id |
|
|
|
) |
|
|
|
) |
|
|
|
d["state"] = [ |
|
|
|
d["state"] = [ |
|
|
|
self.hs.serialize_event(c) for c in current_state |
|
|
|
serialize_event(c, time_now, as_client_event) |
|
|
|
|
|
|
|
for c in current_state |
|
|
|
] |
|
|
|
] |
|
|
|
except: |
|
|
|
except: |
|
|
|
logger.exception("Failed to get snapshot") |
|
|
|
logger.exception("Failed to get snapshot") |
|
|
@ -320,8 +326,9 @@ class MessageHandler(BaseHandler): |
|
|
|
auth_user = UserID.from_string(user_id) |
|
|
|
auth_user = UserID.from_string(user_id) |
|
|
|
|
|
|
|
|
|
|
|
# TODO: These concurrently |
|
|
|
# TODO: These concurrently |
|
|
|
|
|
|
|
time_now = self.clock.time_msec() |
|
|
|
state_tuples = yield self.state_handler.get_current_state(room_id) |
|
|
|
state_tuples = yield self.state_handler.get_current_state(room_id) |
|
|
|
state = [self.hs.serialize_event(x) for x in state_tuples] |
|
|
|
state = [serialize_event(x, time_now) for x in state_tuples] |
|
|
|
|
|
|
|
|
|
|
|
member_event = (yield self.store.get_room_member( |
|
|
|
member_event = (yield self.store.get_room_member( |
|
|
|
user_id=user_id, |
|
|
|
user_id=user_id, |
|
|
@ -360,11 +367,13 @@ class MessageHandler(BaseHandler): |
|
|
|
"Failed to get member presence of %r", m.user_id |
|
|
|
"Failed to get member presence of %r", m.user_id |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time_now = self.clock.time_msec() |
|
|
|
|
|
|
|
|
|
|
|
defer.returnValue({ |
|
|
|
defer.returnValue({ |
|
|
|
"membership": member_event.membership, |
|
|
|
"membership": member_event.membership, |
|
|
|
"room_id": room_id, |
|
|
|
"room_id": room_id, |
|
|
|
"messages": { |
|
|
|
"messages": { |
|
|
|
"chunk": [self.hs.serialize_event(m) for m in messages], |
|
|
|
"chunk": [serialize_event(m, time_now) for m in messages], |
|
|
|
"start": start_token.to_string(), |
|
|
|
"start": start_token.to_string(), |
|
|
|
"end": end_token.to_string(), |
|
|
|
"end": end_token.to_string(), |
|
|
|
}, |
|
|
|
}, |
|
|
|