diff options
author | Mark Haines <mjark@negativecurvature.net> | 2015-12-02 17:14:45 +0000 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2015-12-02 17:14:45 +0000 |
commit | 748c0f5efa33ebdc24ff45a230c72adbbf9521c6 (patch) | |
tree | df2a61dc99f5f6735d2cf010576bdcdde354ffe5 /synapse | |
parent | Merge pull request #412 from matrix-org/erikj/search (diff) | |
parent | Make state updates in the C+S API idempotent (diff) | |
download | synapse-748c0f5efa33ebdc24ff45a230c72adbbf9521c6.tar.xz |
Merge pull request #416 from matrix-org/markjh/idempotent_state
Make state updates in the C+S API idempotent
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/handlers/message.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index c972e8cd4c..ccdd3d8473 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -26,6 +26,8 @@ from synapse.types import UserID, RoomStreamToken, StreamToken from ._base import BaseHandler +from canonicaljson import encode_canonical_json + import logging logger = logging.getLogger(__name__) @@ -213,6 +215,16 @@ class MessageHandler(BaseHandler): builder=builder, ) + if event.is_state(): + prev_state = context.current_state.get((event.type, event.state_key)) + if prev_state and event.user_id == prev_state.user_id: + prev_content = encode_canonical_json(prev_state.content) + next_content = encode_canonical_json(event.content) + if prev_content == next_content: + # Duplicate suppression for state updates with same sender + # and content. + defer.returnValue(prev_state) + if event.type == EventTypes.Member: member_handler = self.hs.get_handlers().room_member_handler yield member_handler.change_membership(event, context, is_guest=is_guest) |