mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Fix bug when uploading state with empty state_key
This commit is contained in:
parent
aae8a37e63
commit
02db7eb209
@ -118,6 +118,9 @@ class EventBase(object):
|
||||
|
||||
return d
|
||||
|
||||
def get(self, key, default):
|
||||
return self._event_dict.get(key, default)
|
||||
|
||||
def get_internal_metadata_dict(self):
|
||||
return self.internal_metadata.get_dict()
|
||||
|
||||
@ -165,6 +168,9 @@ class FrozenEvent(EventBase):
|
||||
return _unfreeze(super(FrozenEvent, self).get_dict())
|
||||
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
def __repr__(self):
|
||||
return "<FrozenEvent event_id='%s', type='%s', state_key='%s'>" % (
|
||||
self.event_id, self.type, self.state_key,
|
||||
self.event_id, self.type, self.get("state_key", None),
|
||||
)
|
@ -97,6 +97,11 @@ class BaseHandler(object):
|
||||
|
||||
event = builder.build()
|
||||
|
||||
logger.debug(
|
||||
"Created event %s with auth_events: %s, current state: %s",
|
||||
event.event_id, context.auth_events, context.current_state,
|
||||
)
|
||||
|
||||
defer.returnValue(
|
||||
(event, context,)
|
||||
)
|
||||
@ -147,64 +152,3 @@ class BaseHandler(object):
|
||||
None,
|
||||
destinations=destinations,
|
||||
)
|
||||
|
||||
# @defer.inlineCallbacks
|
||||
# def _on_new_room_event(self, event, snapshot, extra_destinations=[],
|
||||
# extra_users=[], suppress_auth=False,
|
||||
# do_invite_host=None):
|
||||
# yield run_on_reactor()
|
||||
#
|
||||
# snapshot.fill_out_prev_events(event)
|
||||
#
|
||||
# yield self.state_handler.annotate_event_with_state(event)
|
||||
#
|
||||
# yield self.auth.add_auth_events(event)
|
||||
#
|
||||
# logger.debug("Signing event...")
|
||||
#
|
||||
# add_hashes_and_signatures(
|
||||
# event, self.server_name, self.signing_key
|
||||
# )
|
||||
#
|
||||
# logger.debug("Signed event.")
|
||||
#
|
||||
# if not suppress_auth:
|
||||
# logger.debug("Authing...")
|
||||
# self.auth.check(event, auth_events=event.old_state_events)
|
||||
# logger.debug("Authed")
|
||||
# else:
|
||||
# logger.debug("Suppressed auth.")
|
||||
#
|
||||
# if do_invite_host:
|
||||
# federation_handler = self.hs.get_handlers().federation_handler
|
||||
# invite_event = yield federation_handler.send_invite(
|
||||
# do_invite_host,
|
||||
# event
|
||||
# )
|
||||
#
|
||||
# # FIXME: We need to check if the remote changed anything else
|
||||
# event.signatures = invite_event.signatures
|
||||
#
|
||||
# yield self.store.persist_event(event)
|
||||
#
|
||||
# destinations = set(extra_destinations)
|
||||
# # Send a PDU to all hosts who have joined the room.
|
||||
#
|
||||
# for k, s in event.state_events.items():
|
||||
# try:
|
||||
# if k[0] == RoomMemberEvent.TYPE:
|
||||
# if s.content["membership"] == Membership.JOIN:
|
||||
# destinations.add(
|
||||
# self.hs.parse_userid(s.state_key).domain
|
||||
# )
|
||||
# except:
|
||||
# logger.warn(
|
||||
# "Failed to get destination from event %s", s.event_id
|
||||
# )
|
||||
#
|
||||
# event.destinations = list(destinations)
|
||||
#
|
||||
# yield self.notifier.on_new_room_event(event, extra_users=extra_users)
|
||||
#
|
||||
# federation_handler = self.hs.get_handlers().federation_handler
|
||||
# yield federation_handler.handle_new_event(event, snapshot)
|
||||
|
@ -165,21 +165,6 @@ class MessageHandler(BaseHandler):
|
||||
|
||||
defer.returnValue(event)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def store_room_data(self, event=None):
|
||||
""" Stores data for a room.
|
||||
|
||||
Args:
|
||||
event : The room path event
|
||||
stamp_event (bool) : True to stamp event content with server keys.
|
||||
Raises:
|
||||
SynapseError if something went wrong.
|
||||
"""
|
||||
|
||||
snapshot = yield self.store.snapshot_room(event)
|
||||
|
||||
yield self._on_new_room_event(event, snapshot)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_data(self, user_id=None, room_id=None,
|
||||
event_type=None, state_key=""):
|
||||
|
@ -147,16 +147,18 @@ class RoomStateEventRestServlet(RestServlet):
|
||||
|
||||
content = _parse_json(request)
|
||||
|
||||
msg_handler = self.handlers.message_handler
|
||||
yield msg_handler.handle_event(
|
||||
{
|
||||
event_dict = {
|
||||
"type": event_type,
|
||||
"content": content,
|
||||
"room_id": room_id,
|
||||
"room_id": urllib.unquote(room_id),
|
||||
"sender": user.to_string(),
|
||||
"state_key": urllib.unquote(state_key),
|
||||
}
|
||||
)
|
||||
|
||||
if state_key is not None:
|
||||
event_dict["state_key"] = urllib.unquote(state_key)
|
||||
|
||||
msg_handler = self.handlers.message_handler
|
||||
yield msg_handler.handle_event(event_dict)
|
||||
|
||||
defer.returnValue((200, {}))
|
||||
|
||||
|
@ -39,6 +39,7 @@ from .state import StateStore
|
||||
from .signatures import SignatureStore
|
||||
|
||||
from syutil.base64util import decode_base64
|
||||
from syutil.jsonutil import encode_canonical_json
|
||||
|
||||
from synapse.crypto.event_signing import compute_event_reference_hash
|
||||
|
||||
@ -162,7 +163,8 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
table="event_json",
|
||||
values={
|
||||
"event_id": event.event_id,
|
||||
"json": json.dumps(event_dict, separators=(',', ':')),
|
||||
"room_id": event.room_id,
|
||||
"json": encode_canonical_json(event_dict),
|
||||
},
|
||||
or_replace=True,
|
||||
)
|
||||
|
@ -35,11 +35,13 @@ CREATE INDEX IF NOT EXISTS events_room_id ON events (room_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS event_json(
|
||||
event_id TEXT NOT NULL,
|
||||
room_id TEXT NOT NULL,
|
||||
json BLOB NOT NULL,
|
||||
CONSTRAINT ev_j_uniq UNIQUE (event_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS event_json_id ON event_json(event_id);
|
||||
CREATE INDEX IF NOT EXISTS event_json_room_id ON event_json(room_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS state_events(
|
||||
|
Loading…
Reference in New Issue
Block a user