diff options
author | Richard van der Hoff <richard@matrix.org> | 2019-05-21 17:35:31 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2019-05-21 17:35:31 +0100 |
commit | f3ff64e000f6f4b752ab8c819e57db6c34c6e396 (patch) | |
tree | 941bf312c3bd6b2bab698459d73cd34acb9e62c8 /synapse/handlers/message.py | |
parent | Fix spelling in changelog (diff) | |
parent | Merge pull request #5203 from matrix-org/erikj/aggregate_by_sender (diff) | |
download | synapse-f3ff64e000f6f4b752ab8c819e57db6c34c6e396.tar.xz |
Merge commit 'f4c80d70f' into release-v0.99.5
Diffstat (limited to 'synapse/handlers/message.py')
-rw-r--r-- | synapse/handlers/message.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 7b2c33a922..792edc7579 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -22,7 +22,7 @@ from canonicaljson import encode_canonical_json, json from twisted.internet import defer from twisted.internet.defer import succeed -from synapse.api.constants import EventTypes, Membership +from synapse.api.constants import EventTypes, Membership, RelationTypes from synapse.api.errors import ( AuthError, Codes, @@ -601,6 +601,20 @@ class EventCreationHandler(object): self.validator.validate_new(event) + # If this event is an annotation then we check that that the sender + # can't annotate the same way twice (e.g. stops users from liking an + # event multiple times). + relation = event.content.get("m.relates_to", {}) + if relation.get("rel_type") == RelationTypes.ANNOTATION: + relates_to = relation["event_id"] + aggregation_key = relation["key"] + + already_exists = yield self.store.has_user_annotated_event( + relates_to, event.type, aggregation_key, event.sender, + ) + if already_exists: + raise SynapseError(400, "Can't send same reaction twice") + logger.debug( "Created event %s", event.event_id, |