matrix-appservice-kakaotalk/matrix_appservice_kakaotalk/kt/types/channel/channel_info.py

94 lines
2.4 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 Generic, TypeVar
from attr import dataclass
from mautrix.types import SerializableAttrs, JSON
from ..bson import Long
from ..chat.chat import Chatlog
from ..user.channel_user_info import DisplayUserInfo
from .channel import Channel
from .channel_type import ChannelType
from .meta import ChannelMetaType
@dataclass
class ChannelMeta(SerializableAttrs):
content: str
@dataclass
class SetChannelMeta(ChannelMeta):
revision: int
authorId: Long
updatedAt: int
ChannelMetaMap = dict[ChannelMetaType, SetChannelMeta] # Substitute for Record<ChannelMetaType, SetChannelMeta>
@dataclass(kw_only=True)
class ChannelInfo(Channel):
type: ChannelType
activeUserCount: int
newChatCount: int
newChatCountInvalid: bool
lastChatLogId: Long
lastSeenLogId: Long
lastChatLog: Chatlog | None = None
metaMap: ChannelMetaMap
displayUserList: list[DisplayUserInfo]
pushAlert: bool
@dataclass
class NormalChannelInfo(ChannelInfo):
joinTime: int
T = TypeVar("T", bound=SerializableAttrs)
@dataclass
class ChannelData(SerializableAttrs, Generic[T]):
info: T
@dataclass
class ChannelLoginData(SerializableAttrs, Generic[T]):
"""aka non-auth LoginData"""
lastUpdate: int
channel: T
@dataclass
class NormalChannelData(Channel, ChannelData[NormalChannelInfo]):
@classmethod
def deserialize(cls, data: JSON) -> "NormalChannelData":
data["info"] = NormalChannelInfo.deserialize(data["info"])
return super().deserialize(data)
__all__ = [
"ChannelMeta",
"SetChannelMeta",
"ChannelMetaMap",
"ChannelInfo",
"NormalChannelInfo",
"ChannelData",
"ChannelLoginData",
"NormalChannelData",
]