matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/kt/types/chat/chat.py

93 lines
2.2 KiB
Python

# matrix-appservice-kakaotalk - A Matrix-KakaoTalk puppeting bridge.
# Copyright (C) 2022 Tulir Asokan, Andrew Ferrazzutti
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Optional, Union
from attr import dataclass
from mautrix.types import SerializableAttrs
from ..bson import Long
from ..user.channel_user import ChannelUser
from ..attachment import Attachment
from .chat_type import ChatType
@dataclass
class ChatTypeComponent(SerializableAttrs):
type: ChatType # Substitute for T, where T extends ChatType = ChatType
@dataclass(kw_only=True)
class Chat(ChatTypeComponent):
text: Optional[str] = None
attachment: Optional[Attachment] = None
supplement: Optional[dict] = None
@dataclass
class TypedChat(Chat, ChatTypeComponent):
"""Substitute for TypedChat<T extends ChatType> = Chat & ChatTypeComponent<T>"""
pass
@dataclass
class ChatLogged(SerializableAttrs):
logId: Long
@dataclass
class ChatLoggedType(ChatLogged):
type: ChatType
@dataclass
class ChatLogLinked(ChatLogged):
prevLogId: Long
@dataclass
class ChatWritten(Chat):
sender: ChannelUser
sendAt: int
messageId: Union[int, Long]
@dataclass
class Chatlog(ChatLogLinked, ChatWritten):
pass
@dataclass
class TypedChatlog(Chatlog, TypedChat):
"""Substitute for TypedChatlog<T extends ChatType> = Chatlog & TypedChat<T>"""
pass
@dataclass(kw_only=True)
class ChatOptions(SerializableAttrs):
shout: Optional[bool] = None
__all__ = [
"ChatTypeComponent",
"Chat",
"TypedChat",
"ChatLogged",
"ChatLoggedType",
"ChatLogLinked",
"ChatWritten",
"Chatlog",
"TypedChatlog",
"ChatOptions",
]