Make state updates in the C+S API idempotent
This commit is contained in:
parent
f721fdbf87
commit
491f3d16dc
|
@ -26,6 +26,8 @@ from synapse.types import UserID, RoomStreamToken, StreamToken
|
||||||
|
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
|
|
||||||
|
from canonicaljson import encode_canonical_json
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -213,6 +215,16 @@ class MessageHandler(BaseHandler):
|
||||||
builder=builder,
|
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:
|
if event.type == EventTypes.Member:
|
||||||
member_handler = self.hs.get_handlers().room_member_handler
|
member_handler = self.hs.get_handlers().room_member_handler
|
||||||
yield member_handler.change_membership(event, context, is_guest=is_guest)
|
yield member_handler.change_membership(event, context, is_guest=is_guest)
|
||||||
|
|
Loading…
Reference in New Issue