kopia lustrzana https://gitlab.com/jaywink/federation
rodzic
499d222719
commit
d981cb7811
|
@ -133,6 +133,7 @@ class Profile(CreatedAtMixin, OptionalRawContentMixin, PublicMixin, BaseEntity):
|
|||
url = ""
|
||||
username = ""
|
||||
inboxes: Dict = None
|
||||
mxid = ""
|
||||
|
||||
_allowed_children = (Image,)
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue