mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Change IM sync api to also return the current presence list.
This commit is contained in:
parent
ad869fa4b3
commit
e7ee0b9fc1
@ -24,6 +24,7 @@ from synapse.api.events.room import (
|
|||||||
RoomConfigEvent
|
RoomConfigEvent
|
||||||
)
|
)
|
||||||
from synapse.api.streams.event import EventStream, EventsStreamData
|
from synapse.api.streams.event import EventStream, EventsStreamData
|
||||||
|
from synapse.handlers.presence import PresenceStreamData
|
||||||
from synapse.util import stringutils
|
from synapse.util import stringutils
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
|
|
||||||
@ -257,7 +258,19 @@ class MessageHandler(BaseHandler):
|
|||||||
membership_list=[Membership.INVITE, Membership.JOIN]
|
membership_list=[Membership.INVITE, Membership.JOIN]
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = []
|
rooms_ret = []
|
||||||
|
|
||||||
|
now_rooms_token = yield self.store.get_room_events_max_id()
|
||||||
|
|
||||||
|
# FIXME (erikj): Fix this.
|
||||||
|
presence_stream = PresenceStreamData(self.hs)
|
||||||
|
now_presence_token = yield presence_stream.max_token()
|
||||||
|
presence = yield presence_stream.get_rows(
|
||||||
|
user_id, 0, now_presence_token, None, None
|
||||||
|
)
|
||||||
|
|
||||||
|
# FIXME (erikj): We need to not generate this token,
|
||||||
|
now_token = "%s_%s" % (now_rooms_token, now_presence_token)
|
||||||
|
|
||||||
for event in room_list:
|
for event in room_list:
|
||||||
d = {
|
d = {
|
||||||
@ -268,14 +281,15 @@ class MessageHandler(BaseHandler):
|
|||||||
if event.membership == Membership.INVITE:
|
if event.membership == Membership.INVITE:
|
||||||
d["inviter"] = event.user_id
|
d["inviter"] = event.user_id
|
||||||
|
|
||||||
ret.append(d)
|
rooms_ret.append(d)
|
||||||
|
|
||||||
if event.membership != Membership.JOIN:
|
if event.membership != Membership.JOIN:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
messages, token = yield self.store.get_recent_events_for_room(
|
messages, token = yield self.store.get_recent_events_for_room(
|
||||||
event.room_id,
|
event.room_id,
|
||||||
limit=50,
|
limit=10,
|
||||||
|
end_token=now_rooms_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
d["messages"] = {
|
d["messages"] = {
|
||||||
@ -289,6 +303,10 @@ class MessageHandler(BaseHandler):
|
|||||||
except:
|
except:
|
||||||
logger.exception("Failed to get snapshot")
|
logger.exception("Failed to get snapshot")
|
||||||
|
|
||||||
|
user = self.hs.parse_userid(user_id)
|
||||||
|
|
||||||
|
ret = {"rooms": rooms_ret, "presence": presence[0], "end": now_token}
|
||||||
|
|
||||||
logger.debug("snapshot_all_rooms returning: %s", ret)
|
logger.debug("snapshot_all_rooms returning: %s", ret)
|
||||||
|
|
||||||
defer.returnValue(ret)
|
defer.returnValue(ret)
|
||||||
|
@ -249,11 +249,10 @@ class StreamStore(SQLBaseStore):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_recent_events_for_room(self, room_id, limit, with_feedback=False):
|
def get_recent_events_for_room(self, room_id, limit, end_token,
|
||||||
|
with_feedback=False):
|
||||||
# TODO (erikj): Handle compressed feedback
|
# TODO (erikj): Handle compressed feedback
|
||||||
|
|
||||||
end_token = yield self.get_room_events_max_id()
|
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT * FROM events "
|
"SELECT * FROM events "
|
||||||
"WHERE room_id = ? AND stream_ordering <= ? "
|
"WHERE room_id = ? AND stream_ordering <= ? "
|
||||||
|
Loading…
Reference in New Issue
Block a user