Correctly return new token when returning events. Serialize events correctly.

This commit is contained in:
Erik Johnston 2014-08-15 15:28:54 +01:00
parent 114984a236
commit 01f089d9fb
5 changed files with 25 additions and 9 deletions

View File

@ -15,6 +15,7 @@
from synapse.api.constants import Membership from synapse.api.constants import Membership
from synapse.api.events.room import RoomMemberEvent from synapse.api.events.room import RoomMemberEvent
from synapse.api.streams.event import EventsStreamData
from twisted.internet import defer from twisted.internet import defer
from twisted.internet import reactor from twisted.internet import reactor
@ -66,7 +67,7 @@ class Notifier(object):
self._notify_and_callback( self._notify_and_callback(
user_id=user_id, user_id=user_id,
event_data=event.get_dict(), event_data=event.get_dict(),
stream_type=event.type, stream_type=EventsStreamData.EVENT_TYPE,
store_id=store_id) store_id=store_id)
def on_new_user_event(self, user_id, event_data, stream_type, store_id): def on_new_user_event(self, user_id, event_data, stream_type, store_id):

View File

@ -160,7 +160,7 @@ class EventStream(PaginationStream):
self.user_id, from_pkey, to_pkey, limit self.user_id, from_pkey, to_pkey, limit
) )
chunk += event_chunk chunk += [e.get_dict() for e in event_chunk]
next_ver.append(str(max_pkey)) next_ver.append(str(max_pkey))
defer.returnValue((chunk, EventStream.SEPARATOR.join(next_ver))) defer.returnValue((chunk, EventStream.SEPARATOR.join(next_ver)))

View File

@ -255,7 +255,10 @@ class MessageHandler(BaseHandler):
ret = [] ret = []
for event in room_list: for event in room_list:
d = event.get_dict() d = {
"room_id": event.room_id,
"membership": event.membership,
}
ret.append(d) ret.append(d)
if event.membership != Membership.JOIN: if event.membership != Membership.JOIN:

View File

@ -57,7 +57,8 @@ class DataStore(RoomMemberStore, RoomStore,
elif event.type == RoomTopicEvent.TYPE: elif event.type == RoomTopicEvent.TYPE:
yield self._store_room_topic(event) yield self._store_room_topic(event)
yield self._store_event(event) ret = yield self._store_event(event)
defer.returnValue(ret)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_event(self, event_id): def get_event(self, event_id):
@ -114,6 +115,9 @@ class DataStore(RoomMemberStore, RoomStore,
} }
) )
latest = yield self.get_room_events_max_id()
defer.returnValue(latest)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_current_state(self, room_id, event_type=None, state_key=""): def get_current_state(self, room_id, event_type=None, state_key=""):
sql = ( sql = (

View File

@ -43,7 +43,7 @@ class StreamStore(SQLBaseStore):
) )
invites_sql = ( invites_sql = (
"SELECT m.event_id FROM room_membershipas as m " "SELECT m.event_id FROM room_memberships as m "
"INNER JOIN current_state_events as c ON m.event_id = c.event_id " "INNER JOIN current_state_events as c ON m.event_id = c.event_id "
"WHERE m.user_id = ? AND m.membership = ?" "WHERE m.user_id = ? AND m.membership = ?"
) )
@ -55,8 +55,9 @@ class StreamStore(SQLBaseStore):
sql = ( sql = (
"SELECT * FROM events as e WHERE " "SELECT * FROM events as e WHERE "
"(room_id IN (%(current)s)) OR " "((room_id IN (%(current)s)) OR "
"(event_id IN (%(invites)s)) " "(event_id IN (%(invites)s))) "
" AND e.ordering > ? AND e.ordering < ? "
"ORDER BY ordering ASC LIMIT %(limit)d" "ORDER BY ordering ASC LIMIT %(limit)d"
) % { ) % {
"current": current_room_membership_sql, "current": current_room_membership_sql,
@ -66,10 +67,17 @@ class StreamStore(SQLBaseStore):
rows = yield self._execute_and_decode( rows = yield self._execute_and_decode(
sql, sql,
user_id, user_id, Membership.INVITE user_id, user_id, Membership.INVITE, from_key, to_key
) )
defer.returnValue([self._parse_event_from_row(r) for r in rows]) ret = [self._parse_event_from_row(r) for r in rows]
if ret:
max_id = max([r["ordering"] for r in rows])
else:
max_id = to_key
defer.returnValue((ret, max_id))
@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, with_feedback=False):