Fixes, event type, enums

matrix-delivery
Jason Robinson 2020-12-24 01:27:56 +02:00
rodzic f9d03fd916
commit dfc7264465
3 zmienionych plików z 20 dodań i 11 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
import logging
from federation.entities.base import Post, Profile
from federation.entities.matrix.enums import EventType
from federation.entities.mixins import BaseEntity
from federation.entities.utils import get_base_attributes
@ -8,29 +9,26 @@ logger = logging.getLogger("federation")
class MatrixEntityMixin(BaseEntity):
_event_type = None
_state_key = None
_event_type: str = None
_txn_id: str = None
@property
def event_type(self):
def event_type(self) -> str:
return self._event_type
@classmethod
def from_base(cls, entity):
# type: (BaseEntity) -> MatrixEntityMixin
# noinspection PyArgumentList
return cls(**get_base_attributes(entity))
@property
def state_key(self):
return self._state_key
def to_string(self):
# noinspection PyUnresolvedReferences
return ""
def txn_id(self) -> str:
return self._txn_id
class MatrixRoomMessage(Post, MatrixEntityMixin):
pass
_event_type = EventType.ROOM_MESSAGE.value
class MatrixProfile(Profile, MatrixEntityMixin):

Wyświetl plik

@ -0,0 +1,11 @@
from enum import Enum
class EnumBase(Enum):
@classmethod
def values(cls):
return [value.value for value in cls.__members__.values()]
class EventType(EnumBase):
ROOM_MESSAGE = "m.room.message"

Wyświetl plik

@ -331,7 +331,7 @@ def handle_send(
},
"payload": rendered_payload,
"urls": {
f"{endpoint}/_matrix/client/r0/rooms/{fid}/state/{entity.event_type}/{entity.state_key}"
f"{endpoint}/_matrix/client/r0/rooms/{fid}/send/{entity.event_type}/{entity.txn_id}"
f"?user_id={user_id}",
},
})