mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Pass room_version into create_local_event_from_event_dict
This commit is contained in:
parent
ef6bdafb29
commit
54f3f369bd
@ -12,8 +12,10 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
from nacl.signing import SigningKey
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
@ -26,11 +28,15 @@ from synapse.api.room_versions import (
|
|||||||
RoomVersion,
|
RoomVersion,
|
||||||
)
|
)
|
||||||
from synapse.crypto.event_signing import add_hashes_and_signatures
|
from synapse.crypto.event_signing import add_hashes_and_signatures
|
||||||
from synapse.types import EventID
|
from synapse.events import (
|
||||||
|
EventBase,
|
||||||
|
_EventInternalMetadata,
|
||||||
|
event_type_from_format_version,
|
||||||
|
)
|
||||||
|
from synapse.types import EventID, JsonDict
|
||||||
|
from synapse.util import Clock
|
||||||
from synapse.util.stringutils import random_string
|
from synapse.util.stringutils import random_string
|
||||||
|
|
||||||
from . import _EventInternalMetadata, event_type_from_format_version
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True, cmp=False, frozen=True)
|
@attr.s(slots=True, cmp=False, frozen=True)
|
||||||
class EventBuilder(object):
|
class EventBuilder(object):
|
||||||
@ -150,7 +156,7 @@ class EventBuilder(object):
|
|||||||
clock=self._clock,
|
clock=self._clock,
|
||||||
hostname=self._hostname,
|
hostname=self._hostname,
|
||||||
signing_key=self._signing_key,
|
signing_key=self._signing_key,
|
||||||
format_version=format_version,
|
room_version=self.room_version,
|
||||||
event_dict=event_dict,
|
event_dict=event_dict,
|
||||||
internal_metadata_dict=self.internal_metadata.get_dict(),
|
internal_metadata_dict=self.internal_metadata.get_dict(),
|
||||||
)
|
)
|
||||||
@ -216,29 +222,19 @@ class EventBuilderFactory(object):
|
|||||||
|
|
||||||
|
|
||||||
def create_local_event_from_event_dict(
|
def create_local_event_from_event_dict(
|
||||||
clock,
|
clock: Clock,
|
||||||
hostname,
|
hostname: str,
|
||||||
signing_key,
|
signing_key: SigningKey,
|
||||||
format_version,
|
room_version: RoomVersion,
|
||||||
event_dict,
|
event_dict: JsonDict,
|
||||||
internal_metadata_dict=None,
|
internal_metadata_dict: Optional[JsonDict] = None,
|
||||||
):
|
) -> EventBase:
|
||||||
"""Takes a fully formed event dict, ensuring that fields like `origin`
|
"""Takes a fully formed event dict, ensuring that fields like `origin`
|
||||||
and `origin_server_ts` have correct values for a locally produced event,
|
and `origin_server_ts` have correct values for a locally produced event,
|
||||||
then signs and hashes it.
|
then signs and hashes it.
|
||||||
|
|
||||||
Args:
|
|
||||||
clock (Clock)
|
|
||||||
hostname (str)
|
|
||||||
signing_key
|
|
||||||
format_version (int)
|
|
||||||
event_dict (dict)
|
|
||||||
internal_metadata_dict (dict|None)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
FrozenEvent
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
format_version = room_version.event_format
|
||||||
if format_version not in KNOWN_EVENT_FORMAT_VERSIONS:
|
if format_version not in KNOWN_EVENT_FORMAT_VERSIONS:
|
||||||
raise Exception("No event format defined for version %r" % (format_version,))
|
raise Exception("No event format defined for version %r" % (format_version,))
|
||||||
|
|
||||||
|
@ -470,8 +470,6 @@ class FederationClient(FederationBase):
|
|||||||
if not room_version:
|
if not room_version:
|
||||||
raise UnsupportedRoomVersionError()
|
raise UnsupportedRoomVersionError()
|
||||||
|
|
||||||
event_format = room_version_to_event_format(room_version_id)
|
|
||||||
|
|
||||||
pdu_dict = ret.get("event", None)
|
pdu_dict = ret.get("event", None)
|
||||||
if not isinstance(pdu_dict, dict):
|
if not isinstance(pdu_dict, dict):
|
||||||
raise InvalidResponseError("Bad 'event' field in response")
|
raise InvalidResponseError("Bad 'event' field in response")
|
||||||
@ -490,7 +488,7 @@ class FederationClient(FederationBase):
|
|||||||
self._clock,
|
self._clock,
|
||||||
self.hostname,
|
self.hostname,
|
||||||
self.signing_key,
|
self.signing_key,
|
||||||
format_version=event_format,
|
room_version=room_version,
|
||||||
event_dict=pdu_dict,
|
event_dict=pdu_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user