Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Land basic reaction and edit support. #5209

Merged
merged 24 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ae69a6a
Merge branch 'erikj/async_serialize_event' into erikj/reactions_rebase
erikjohnston May 14, 2019
495e859
Merge branch 'erikj/fix_config_ratelimiting' into erikj/test
erikjohnston May 14, 2019
a9fc71c
Merge branch 'erikj/refactor_pagination_bounds' into erikj/reactions_…
erikjohnston May 15, 2019
efe3c79
Add simple send_relation API and track in DB
erikjohnston May 14, 2019
b50641e
Add simple pagination API
erikjohnston May 14, 2019
5fb72e6
Newsfile
erikjohnston May 14, 2019
e6459c2
Actually implement idempotency
erikjohnston May 15, 2019
5be34fc
Actually check for None rather falsey
erikjohnston May 15, 2019
f201a30
Merge pull request #5186 from matrix-org/erikj/simple_pagination
erikjohnston May 16, 2019
a060352
Add aggregations API
erikjohnston May 14, 2019
3345341
Add cache to relations
erikjohnston May 16, 2019
b5c62c6
Fix relations in worker mode
erikjohnston May 16, 2019
95f3fcd
Check that event is visible in new APIs
erikjohnston May 16, 2019
2c662dd
Indirect tuple conversion
erikjohnston May 16, 2019
7a7eba8
Move parsing of tokens out of storage layer
erikjohnston May 16, 2019
5c39d26
Merge pull request #5192 from matrix-org/erikj/relations_aggregations
erikjohnston May 16, 2019
d46aab3
Add basic editing support
erikjohnston May 14, 2019
5dbff34
Fixup bsaed on review comments
erikjohnston May 17, 2019
d4ca533
Make tests use different user for each reaction it sends
erikjohnston May 17, 2019
210cb6d
Merge pull request #5195 from matrix-org/erikj/edits
erikjohnston May 20, 2019
935af0d
Correctly update aggregation counts after redaction
erikjohnston May 20, 2019
2ac9c96
Fixup comments
erikjohnston May 20, 2019
9ad246e
Merge pull request #5207 from matrix-org/erikj/reactions_redactions
erikjohnston May 20, 2019
0667105
Newsfile
erikjohnston May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixup bsaed on review comments
  • Loading branch information
erikjohnston committed May 17, 2019
commit 5dbff345094327e61fa9c1425ba0f955c9530ba7
4 changes: 1 addition & 3 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ def serialize_event(self, event, time_now, **kwargs):

edit = None
if event.type == EventTypes.Message:
edit = yield self.store.get_applicable_edit(
event.event_id, event.type, event.sender,
)
edit = yield self.store.get_applicable_edit(event_id)

if edit:
# If there is an edit replace the content, preserving existing
Expand Down
2 changes: 1 addition & 1 deletion synapse/replication/slave/storage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ def invalidate_caches_for_event(self, stream_ordering, event_id, room_id,
if relates_to:
self.get_relations_for_event.invalidate_many((relates_to,))
self.get_aggregation_groups_for_event.invalidate_many((relates_to,))
self.get_applicable_edit.invalidate_many((relates_to,))
self.get_applicable_edit.invalidate((relates_to,))
32 changes: 17 additions & 15 deletions synapse/storage/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from twisted.internet import defer

from synapse.api.constants import EventTypes, RelationTypes
from synapse.api.constants import RelationTypes
from synapse.api.errors import SynapseError
from synapse.storage._base import SQLBaseStore
from synapse.storage.stream import generate_pagination_where_clause
Expand Down Expand Up @@ -314,44 +314,44 @@ def _get_aggregation_groups_for_event_txn(txn):
"get_aggregation_groups_for_event", _get_aggregation_groups_for_event_txn
)

@cachedInlineCallbacks(tree=True)
def get_applicable_edit(self, event_id, event_type, sender):
@cachedInlineCallbacks()
def get_applicable_edit(self, event_id):
"""Get the most recent edit (if any) that has happened for the given
event.

Correctly handles checking whether edits were allowed to happen.

Args:
event_id (str): The original event ID
event_type (str): The original event type
sender (str): The original event sender

Returns:
Deferred[EventBase|None]: Returns the most recent edit, if any.
"""

# We only allow edits for `m.room.message` events that have the same sender
# and event type. We can't assert these things during regular event auth so
# we have to do the post hoc.

if event_type != EventTypes.Message:
return
# we have to do the checks post hoc.

# Fetches latest edit that has the same type and sender as the
# original, and is an `m.room.message`.
sql = """
SELECT event_id, origin_server_ts FROM events
SELECT edit.event_id FROM events AS edit
INNER JOIN event_relations USING (event_id)
INNER JOIN events AS original ON
original.event_id = relates_to_id
AND edit.type = original.type
AND edit.sender = original.sender
WHERE
relates_to_id = ?
AND relation_type = ?
AND type = ?
AND sender = ?
ORDER by origin_server_ts DESC, event_id DESC
AND edit.type = 'm.room.message'
ORDER by edit.origin_server_ts DESC, edit.event_id DESC
LIMIT 1
"""

def _get_applicable_edit_txn(txn):
txn.execute(
sql, (event_id, RelationTypes.REPLACES, event_type, sender)
sql, (event_id, RelationTypes.REPLACES,)
)
row = txn.fetchone()
if row:
Expand Down Expand Up @@ -412,4 +412,6 @@ def _handle_event_relations(self, txn, event):
txn.call_after(
self.get_aggregation_groups_for_event.invalidate_many, (parent_id,)
)
txn.call_after(self.get_applicable_edit.invalidate_many, (parent_id,))

if rel_type == RelationTypes.REPLACES:
txn.call_after(self.get_applicable_edit.invalidate, (parent_id,))