Exemplo n.º 1
0
        async def send_request(destination: str) -> Tuple[str, EventBase, RoomVersion]:
            ret = await self.transport_layer.make_membership_event(
                destination, room_id, user_id, membership, params
            )

            # Note: If not supplied, the room version may be either v1 or v2,
            # however either way the event format version will be v1.
            room_version_id = ret.get("room_version", RoomVersions.V1.identifier)
            room_version = KNOWN_ROOM_VERSIONS.get(room_version_id)
            if not room_version:
                raise UnsupportedRoomVersionError()

            pdu_dict = ret.get("event", None)
            if not isinstance(pdu_dict, dict):
                raise InvalidResponseError("Bad 'event' field in response")

            logger.debug("Got response to make_%s: %s", membership, pdu_dict)

            pdu_dict["content"].update(content)

            # The protoevent received over the JSON wire may not have all
            # the required fields. Lets just gloss over that because
            # there's some we never care about
            if "prev_state" not in pdu_dict:
                pdu_dict["prev_state"] = []

            ev = builder.create_local_event_from_event_dict(
                self._clock,
                self.hostname,
                self.signing_key,
                room_version=room_version,
                event_dict=pdu_dict,
            )

            return destination, ev, room_version
Exemplo n.º 2
0
def _retrieve_and_check_room_version(room_id: str,
                                     room_version_id: str) -> RoomVersion:
    v = KNOWN_ROOM_VERSIONS.get(room_version_id)
    if not v:
        raise UnsupportedRoomVersionError(
            "Room %s uses a room version %s which is no longer supported" %
            (room_id, room_version_id))
    return v
Exemplo n.º 3
0
    def new(self, room_version: str, key_values: dict) -> EventBuilder:
        """Generate an event builder appropriate for the given room version

        Deprecated: use for_room_version with a RoomVersion object instead

        Args:
            room_version: Version of the room that we're creating an event builder for
            key_values: Fields used as the basis of the new event

        Returns:
            EventBuilder
        """
        v = KNOWN_ROOM_VERSIONS.get(room_version)
        if not v:
            # this can happen if support is withdrawn for a room version
            raise UnsupportedRoomVersionError()
        return self.for_room_version(v, key_values)
Exemplo n.º 4
0
def room_version_to_event_format(room_version):
    """Converts a room version string to the event format

    Args:
        room_version (str)

    Returns:
        int

    Raises:
        UnsupportedRoomVersionError if the room version is unknown
    """
    v = KNOWN_ROOM_VERSIONS.get(room_version)

    if not v:
        # this can happen if support is withdrawn for a room version
        raise UnsupportedRoomVersionError()

    return v.event_format
Exemplo n.º 5
0
    async def get_room_version(self, room_id: str) -> RoomVersion:
        """Get the room_version of a given room

        Raises:
            NotFoundError: if the room is unknown

            UnsupportedRoomVersionError: if the room uses an unknown room version.
                Typically this happens if support for the room's version has been
                removed from Synapse.
        """
        room_version_id = await self.get_room_version_id(room_id)
        v = KNOWN_ROOM_VERSIONS.get(room_version_id)

        if not v:
            raise UnsupportedRoomVersionError(
                "Room %s uses a room version %s which is no longer supported" %
                (room_id, room_version_id))

        return v
Exemplo n.º 6
0
    def get_room_version_txn(self, txn: LoggingTransaction,
                             room_id: str) -> RoomVersion:
        """Get the room_version of a given room
        Args:
            txn: Transaction object
            room_id: The room_id of the room you are trying to get the version for
        Raises:
            NotFoundError: if the room is unknown
            UnsupportedRoomVersionError: if the room uses an unknown room version.
                Typically this happens if support for the room's version has been
                removed from Synapse.
        """
        room_version_id = self.get_room_version_id_txn(txn, room_id)
        v = KNOWN_ROOM_VERSIONS.get(room_version_id)

        if not v:
            raise UnsupportedRoomVersionError(
                "Room %s uses a room version %s which is no longer supported" %
                (room_id, room_version_id))

        return v