# 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 . """Custom wrapper classes around types defined by the KakaoTalk API.""" from typing import Optional, NewType, Union from attr import dataclass from mautrix.types import SerializableAttrs, JSON, deserializer from ..types.bson import Long from ..types.channel.channel_info import NormalChannelInfo from ..types.channel.channel_type import ChannelType from ..types.openlink.open_channel_info import OpenChannelInfo from ..types.user.channel_user_info import NormalChannelUserInfo, OpenChannelUserInfo ChannelInfoUnion = NewType("ChannelInfoUnion", Union[NormalChannelInfo, OpenChannelInfo]) @deserializer(ChannelInfoUnion) def deserialize_channel_info_union(data: JSON) -> ChannelInfoUnion: if "openLink" in data: return OpenChannelInfo.deserialize(data) else: return NormalChannelInfo.deserialize(data) setattr(ChannelInfoUnion, "deserialize", deserialize_channel_info_union) UserInfoUnion = NewType("UserInfoUnion", Union[NormalChannelUserInfo, OpenChannelUserInfo]) @deserializer(UserInfoUnion) def deserialize_user_info_union(data: JSON) -> UserInfoUnion: if "perm" in data: return OpenChannelUserInfo.deserialize(data) else: return NormalChannelUserInfo.deserialize(data) setattr(UserInfoUnion, "deserialize", deserialize_user_info_union) @dataclass class PortalChannelInfo(SerializableAttrs): name: str participants: list[UserInfoUnion] # TODO Image channel_info: Optional[ChannelInfoUnion] = None # Should be set manually by caller @dataclass class ChannelProps(SerializableAttrs): id: Long type: ChannelType