diff --git a/federation/entities/base.py b/federation/entities/base.py index 65f7cd3..792f7b1 100644 --- a/federation/entities/base.py +++ b/federation/entities/base.py @@ -133,6 +133,7 @@ class Profile(CreatedAtMixin, OptionalRawContentMixin, PublicMixin, BaseEntity): url = "" username = "" inboxes: Dict = None + mxid = "" _allowed_children = (Image,) diff --git a/federation/entities/matrix/entities.py b/federation/entities/matrix/entities.py index 8f6feb8..bbfdc9c 100644 --- a/federation/entities/matrix/entities.py +++ b/federation/entities/matrix/entities.py @@ -22,6 +22,9 @@ class MatrixEntityMixin(BaseEntity): # noinspection PyArgumentList return cls(**get_base_attributes(entity)) + def get_endpoint(self, *args, **kwargs) -> str: + return "/_matrix/client/r0/" + @property def txn_id(self) -> str: return self._txn_id @@ -30,6 +33,13 @@ class MatrixEntityMixin(BaseEntity): class MatrixRoomMessage(Post, MatrixEntityMixin): _event_type = EventType.ROOM_MESSAGE.value + def get_endpoint(self, fid: str, user_id: str) -> str: + endpoint = super().get_endpoint() + return f"{endpoint}rooms/{fid}/send/{self.event_type}/{self.txn_id}?user_id={user_id}" + class MatrixProfile(Profile, MatrixEntityMixin): - pass + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # We always require an mxid + self._required.add('mxid') diff --git a/federation/outbound.py b/federation/outbound.py index b87bb91..cad68b9 100644 --- a/federation/outbound.py +++ b/federation/outbound.py @@ -321,7 +321,6 @@ def handle_send( continue if not matrix_config: matrix_config = get_matrix_configuration() - user_id = f"@{author_user.username}:{matrix_config['homeserver_name']}" # noinspection PyUnresolvedReferences payloads.append({ "auth": None, @@ -331,8 +330,7 @@ def handle_send( }, "payload": rendered_payload, "urls": { - f"{endpoint}/_matrix/client/r0/rooms/{fid}/send/{entity.event_type}/{entity.txn_id}" - f"?user_id={user_id}", + entity.get_endpoint(fid=fid, user_id=author_user.mxid), }, }) diff --git a/federation/types.py b/federation/types.py index 81f05fa..afd3be2 100644 --- a/federation/types.py +++ b/federation/types.py @@ -28,6 +28,7 @@ class ReceiverVariant(Enum): FOLLOWERS = "followers" +# TODO needed? class UserVariant(Enum): """ Indicates whether the user is local or remote. @@ -47,7 +48,8 @@ class UserType: guid: Optional[str] = attr.ib(default=None) # Required only if sending to Matrix protocol - username: Optional[str] = attr.ib(default=None) + mxid: Optional[str] = attr.ib(default=None) + # TODO needed? variant: Optional[UserVariant] = attr.ib(default=None) @property