From ee3daab48db0f8e7d4f733e33212d9d7a9ed29ba Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 21 Mar 2022 01:04:21 -0400 Subject: [PATCH] Rename some login data types & variables --- matrix_appservice_kakaotalk/kt/client/client.py | 2 +- .../kt/types/api/auth_api_client.py | 5 ++--- .../kt/types/channel/channel_info.py | 5 ++--- .../kt/types/client/client_session.py | 14 +++++++------- matrix_appservice_kakaotalk/user.py | 14 +++++++------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 5a40ecd..c404bce 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -109,7 +109,7 @@ class Client: Obtain a session token by logging in with user-provided credentials. Must have first called register_device with these credentials. """ - # NOTE Actually returns a LoginData object, but this only needs an OAuthCredential + # NOTE Actually returns an auth LoginData, but this only needs an OAuthCredential return await cls._api_request_result(OAuthCredential, "login", is_secret=True, **req) # endregion diff --git a/matrix_appservice_kakaotalk/kt/types/api/auth_api_client.py b/matrix_appservice_kakaotalk/kt/types/api/auth_api_client.py index d744093..12332dc 100644 --- a/matrix_appservice_kakaotalk/kt/types/api/auth_api_client.py +++ b/matrix_appservice_kakaotalk/kt/types/api/auth_api_client.py @@ -22,8 +22,7 @@ from ..oauth import OAuthCredential @dataclass -class AuthLoginData(OAuthCredential): - """aka LoginData""" +class LoginData(OAuthCredential): countryIso: str countryCode: str accountId: int @@ -94,7 +93,7 @@ class KnownAuthStatusCode(IntEnum): __all__ = [ - "AuthLoginData", + "LoginData", "LoginForm", "TokenLoginForm", "KnownAuthStatusCode", diff --git a/matrix_appservice_kakaotalk/kt/types/channel/channel_info.py b/matrix_appservice_kakaotalk/kt/types/channel/channel_info.py index afceae0..a72f0d6 100644 --- a/matrix_appservice_kakaotalk/kt/types/channel/channel_info.py +++ b/matrix_appservice_kakaotalk/kt/types/channel/channel_info.py @@ -67,8 +67,7 @@ class ChannelData(SerializableAttrs, Generic[T]): @dataclass -class ChannelLoginData(SerializableAttrs, Generic[T]): - """aka non-auth LoginData""" +class LoginData(SerializableAttrs, Generic[T]): lastUpdate: int channel: T @@ -88,6 +87,6 @@ __all__ = [ "ChannelInfo", "NormalChannelInfo", "ChannelData", - "ChannelLoginData", + "LoginData", "NormalChannelData", ] diff --git a/matrix_appservice_kakaotalk/kt/types/client/client_session.py b/matrix_appservice_kakaotalk/kt/types/client/client_session.py index d9e3624..b2d08b5 100644 --- a/matrix_appservice_kakaotalk/kt/types/client/client_session.py +++ b/matrix_appservice_kakaotalk/kt/types/client/client_session.py @@ -20,28 +20,28 @@ from attr import dataclass from mautrix.types import SerializableAttrs, JSON, deserializer from ..bson import Long -from ..channel.channel_info import ChannelLoginData, NormalChannelData +from ..channel.channel_info import LoginData, NormalChannelData from ..openlink.open_channel_info import OpenChannelData -ChannelLoginDataItem = NewType("ChannelLoginDataItem", ChannelLoginData[Union[NormalChannelData, OpenChannelData]]) +LoginDataItem = NewType("LoginDataItem", LoginData[Union[NormalChannelData, OpenChannelData]]) -@deserializer(ChannelLoginDataItem) -def deserialize_channel_login_data_item(data: JSON) -> ChannelLoginDataItem: +@deserializer(LoginDataItem) +def deserialize_channel_login_data_item(data: JSON) -> LoginDataItem: channel_data = data["channel"] if "linkId" in channel_data: data["channel"] = OpenChannelData.deserialize(channel_data) else: data["channel"] = NormalChannelData.deserialize(channel_data) - return ChannelLoginData.deserialize(data) + return LoginData.deserialize(data) -setattr(ChannelLoginDataItem, "deserialize", deserialize_channel_login_data_item) +setattr(LoginDataItem, "deserialize", deserialize_channel_login_data_item) @dataclass class LoginResult(SerializableAttrs): """Return value of TalkClient.login""" - channelList: list[ChannelLoginDataItem] + channelList: list[LoginDataItem] userId: Long lastChannelId: Long lastTokenId: Long diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index b8b7c89..d184211 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -42,7 +42,7 @@ from .kt.types.bson import Long from .kt.types.channel.channel_info import ChannelInfo, NormalChannelInfo, NormalChannelData from .kt.types.channel.channel_type import ChannelType from .kt.types.chat.chat import Chatlog -from .kt.types.client.client_session import ChannelLoginDataItem, LoginResult +from .kt.types.client.client_session import LoginDataItem, LoginResult from .kt.types.oauth import OAuthCredential from .kt.types.openlink.open_channel_info import OpenChannelData, OpenChannelInfo @@ -449,19 +449,19 @@ class User(DBUser, BaseUser): sync_count = num_channels if sync_count < 0 else min(sync_count, num_channels) await self.push_bridge_state(BridgeStateEvent.BACKFILLING) self.log.debug(f"Syncing {sync_count} of {num_channels} channels...") - for channel_item in login_result.channelList[:sync_count]: + for login_data in login_result.channelList[:sync_count]: try: - await self._sync_channel(channel_item) + await self._sync_channel(login_data) except AuthenticationRequired: raise except Exception: - self.log.exception(f"Failed to sync channel {channel_item.channel.channelId}") + self.log.exception(f"Failed to sync channel {login_data.channel.channelId}") await self.update_direct_chats() - async def _sync_channel(self, channel_item: ChannelLoginDataItem) -> None: - channel_data = channel_item.channel - self.log.debug(f"Syncing channel {channel_data.channelId} (last updated at {channel_item.lastUpdate})") + async def _sync_channel(self, login_data: LoginDataItem) -> None: + channel_data = login_data.channel + self.log.debug(f"Syncing channel {channel_data.channelId} (last updated at {login_data.lastUpdate})") channel_info = channel_data.info if isinstance(channel_data, NormalChannelData): channel_data: NormalChannelData