mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-02-02 14:04:39 -05:00
When getting a state event also include the previous content
This commit is contained in:
parent
684001ac62
commit
781ff713ba
@ -157,6 +157,11 @@ class SynapseEvent(JsonEncodedObject):
|
|||||||
|
|
||||||
|
|
||||||
class SynapseStateEvent(SynapseEvent):
|
class SynapseStateEvent(SynapseEvent):
|
||||||
|
|
||||||
|
valid_keys = SynapseEvent.valid_keys + [
|
||||||
|
"prev_content",
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if "state_key" not in kwargs:
|
if "state_key" not in kwargs:
|
||||||
kwargs["state_key"] = ""
|
kwargs["state_key"] = ""
|
||||||
|
@ -81,7 +81,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
defer.returnValue(latest)
|
defer.returnValue(latest)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_event(self, event_id):
|
def get_event(self, event_id, allow_none=False):
|
||||||
events_dict = yield self._simple_select_one(
|
events_dict = yield self._simple_select_one(
|
||||||
"events",
|
"events",
|
||||||
{"event_id": event_id},
|
{"event_id": event_id},
|
||||||
@ -92,8 +92,12 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
"content",
|
"content",
|
||||||
"unrecognized_keys"
|
"unrecognized_keys"
|
||||||
],
|
],
|
||||||
|
allow_none=allow_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not events_dict:
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
event = self._parse_event_from_row(events_dict)
|
event = self._parse_event_from_row(events_dict)
|
||||||
defer.returnValue(event)
|
defer.returnValue(event)
|
||||||
|
|
||||||
@ -220,7 +224,8 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
|
|
||||||
results = yield self._execute_and_decode(sql, *args)
|
results = yield self._execute_and_decode(sql, *args)
|
||||||
|
|
||||||
defer.returnValue([self._parse_event_from_row(r) for r in results])
|
events = yield self._parse_events(results)
|
||||||
|
defer.returnValue(events)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _get_min_token(self):
|
def _get_min_token(self):
|
||||||
|
@ -312,6 +312,25 @@ class SQLBaseStore(object):
|
|||||||
**d
|
**d
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _parse_events(self, rows):
|
||||||
|
return self._db_pool.runInteraction(self._parse_events_txn, rows)
|
||||||
|
|
||||||
|
def _parse_events_txn(self, txn, rows):
|
||||||
|
events = [self._parse_event_from_row(r) for r in rows]
|
||||||
|
|
||||||
|
sql = "SELECT * FROM events WHERE event_id = ?"
|
||||||
|
|
||||||
|
for ev in events:
|
||||||
|
if hasattr(ev, "prev_state"):
|
||||||
|
# Load previous state_content.
|
||||||
|
# TODO: Should we be pulling this out above?
|
||||||
|
cursor = txn.execute(sql, (ev.prev_state,))
|
||||||
|
prevs = self.cursor_to_dict(cursor)
|
||||||
|
if prevs:
|
||||||
|
prev = self._parse_event_from_row(prevs[0])
|
||||||
|
ev.prev_content = prev.content
|
||||||
|
|
||||||
|
return events
|
||||||
|
|
||||||
class Table(object):
|
class Table(object):
|
||||||
""" A base class used to store information about a particular table.
|
""" A base class used to store information about a particular table.
|
||||||
|
@ -88,7 +88,7 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
txn.execute(sql, (user_id, room_id))
|
txn.execute(sql, (user_id, room_id))
|
||||||
rows = self.cursor_to_dict(txn)
|
rows = self.cursor_to_dict(txn)
|
||||||
if rows:
|
if rows:
|
||||||
return self._parse_event_from_row(rows[0])
|
return self._parse_events_txn(txn, rows)[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ class RoomMemberStore(SQLBaseStore):
|
|||||||
|
|
||||||
# logger.debug("_get_members_query Got rows %s", rows)
|
# logger.debug("_get_members_query Got rows %s", rows)
|
||||||
|
|
||||||
results = [self._parse_event_from_row(r) for r in rows]
|
results = yield self._parse_events(rows)
|
||||||
defer.returnValue(results)
|
defer.returnValue(results)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -188,7 +188,7 @@ class StreamStore(SQLBaseStore):
|
|||||||
user_id, user_id, from_id, to_id
|
user_id, user_id, from_id, to_id
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = [self._parse_event_from_row(r) for r in rows]
|
ret = yield self._parse_events(rows)
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
key = "s%d" % max([r["stream_ordering"] for r in rows])
|
key = "s%d" % max([r["stream_ordering"] for r in rows])
|
||||||
@ -243,9 +243,11 @@ class StreamStore(SQLBaseStore):
|
|||||||
# TODO (erikj): We should work out what to do here instead.
|
# TODO (erikj): We should work out what to do here instead.
|
||||||
next_token = to_key if to_key else from_key
|
next_token = to_key if to_key else from_key
|
||||||
|
|
||||||
|
events = yield self._parse_events(rows)
|
||||||
|
|
||||||
defer.returnValue(
|
defer.returnValue(
|
||||||
(
|
(
|
||||||
[self._parse_event_from_row(r) for r in rows],
|
events,
|
||||||
next_token
|
next_token
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -277,12 +279,11 @@ class StreamStore(SQLBaseStore):
|
|||||||
else:
|
else:
|
||||||
token = (end_token, end_token)
|
token = (end_token, end_token)
|
||||||
|
|
||||||
defer.returnValue(
|
events = yield self._parse_events(rows)
|
||||||
(
|
|
||||||
[self._parse_event_from_row(r) for r in rows],
|
ret = (events, token)
|
||||||
token
|
|
||||||
)
|
defer.returnValue(ret)
|
||||||
)
|
|
||||||
|
|
||||||
def get_room_events_max_id(self):
|
def get_room_events_max_id(self):
|
||||||
return self._db_pool.runInteraction(self._get_room_events_max_id_txn)
|
return self._db_pool.runInteraction(self._get_room_events_max_id_txn)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user