Rename some login data types & variables
This commit is contained in:
parent
b59b8a68c3
commit
ee3daab48d
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user