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.
|
Obtain a session token by logging in with user-provided credentials.
|
||||||
Must have first called register_device with these 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)
|
return await cls._api_request_result(OAuthCredential, "login", is_secret=True, **req)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
@ -22,8 +22,7 @@ from ..oauth import OAuthCredential
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AuthLoginData(OAuthCredential):
|
class LoginData(OAuthCredential):
|
||||||
"""aka LoginData"""
|
|
||||||
countryIso: str
|
countryIso: str
|
||||||
countryCode: str
|
countryCode: str
|
||||||
accountId: int
|
accountId: int
|
||||||
@ -94,7 +93,7 @@ class KnownAuthStatusCode(IntEnum):
|
|||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"AuthLoginData",
|
"LoginData",
|
||||||
"LoginForm",
|
"LoginForm",
|
||||||
"TokenLoginForm",
|
"TokenLoginForm",
|
||||||
"KnownAuthStatusCode",
|
"KnownAuthStatusCode",
|
||||||
|
@ -67,8 +67,7 @@ class ChannelData(SerializableAttrs, Generic[T]):
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ChannelLoginData(SerializableAttrs, Generic[T]):
|
class LoginData(SerializableAttrs, Generic[T]):
|
||||||
"""aka non-auth LoginData"""
|
|
||||||
lastUpdate: int
|
lastUpdate: int
|
||||||
channel: T
|
channel: T
|
||||||
|
|
||||||
@ -88,6 +87,6 @@ __all__ = [
|
|||||||
"ChannelInfo",
|
"ChannelInfo",
|
||||||
"NormalChannelInfo",
|
"NormalChannelInfo",
|
||||||
"ChannelData",
|
"ChannelData",
|
||||||
"ChannelLoginData",
|
"LoginData",
|
||||||
"NormalChannelData",
|
"NormalChannelData",
|
||||||
]
|
]
|
||||||
|
@ -20,28 +20,28 @@ from attr import dataclass
|
|||||||
from mautrix.types import SerializableAttrs, JSON, deserializer
|
from mautrix.types import SerializableAttrs, JSON, deserializer
|
||||||
|
|
||||||
from ..bson import Long
|
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
|
from ..openlink.open_channel_info import OpenChannelData
|
||||||
|
|
||||||
|
|
||||||
ChannelLoginDataItem = NewType("ChannelLoginDataItem", ChannelLoginData[Union[NormalChannelData, OpenChannelData]])
|
LoginDataItem = NewType("LoginDataItem", LoginData[Union[NormalChannelData, OpenChannelData]])
|
||||||
|
|
||||||
@deserializer(ChannelLoginDataItem)
|
@deserializer(LoginDataItem)
|
||||||
def deserialize_channel_login_data_item(data: JSON) -> ChannelLoginDataItem:
|
def deserialize_channel_login_data_item(data: JSON) -> LoginDataItem:
|
||||||
channel_data = data["channel"]
|
channel_data = data["channel"]
|
||||||
if "linkId" in channel_data:
|
if "linkId" in channel_data:
|
||||||
data["channel"] = OpenChannelData.deserialize(channel_data)
|
data["channel"] = OpenChannelData.deserialize(channel_data)
|
||||||
else:
|
else:
|
||||||
data["channel"] = NormalChannelData.deserialize(channel_data)
|
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
|
@dataclass
|
||||||
class LoginResult(SerializableAttrs):
|
class LoginResult(SerializableAttrs):
|
||||||
"""Return value of TalkClient.login"""
|
"""Return value of TalkClient.login"""
|
||||||
channelList: list[ChannelLoginDataItem]
|
channelList: list[LoginDataItem]
|
||||||
userId: Long
|
userId: Long
|
||||||
lastChannelId: Long
|
lastChannelId: Long
|
||||||
lastTokenId: 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_info import ChannelInfo, NormalChannelInfo, NormalChannelData
|
||||||
from .kt.types.channel.channel_type import ChannelType
|
from .kt.types.channel.channel_type import ChannelType
|
||||||
from .kt.types.chat.chat import Chatlog
|
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.oauth import OAuthCredential
|
||||||
from .kt.types.openlink.open_channel_info import OpenChannelData, OpenChannelInfo
|
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)
|
sync_count = num_channels if sync_count < 0 else min(sync_count, num_channels)
|
||||||
await self.push_bridge_state(BridgeStateEvent.BACKFILLING)
|
await self.push_bridge_state(BridgeStateEvent.BACKFILLING)
|
||||||
self.log.debug(f"Syncing {sync_count} of {num_channels} channels...")
|
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:
|
try:
|
||||||
await self._sync_channel(channel_item)
|
await self._sync_channel(login_data)
|
||||||
except AuthenticationRequired:
|
except AuthenticationRequired:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
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()
|
await self.update_direct_chats()
|
||||||
|
|
||||||
async def _sync_channel(self, channel_item: ChannelLoginDataItem) -> None:
|
async def _sync_channel(self, login_data: LoginDataItem) -> None:
|
||||||
channel_data = channel_item.channel
|
channel_data = login_data.channel
|
||||||
self.log.debug(f"Syncing channel {channel_data.channelId} (last updated at {channel_item.lastUpdate})")
|
self.log.debug(f"Syncing channel {channel_data.channelId} (last updated at {login_data.lastUpdate})")
|
||||||
channel_info = channel_data.info
|
channel_info = channel_data.info
|
||||||
if isinstance(channel_data, NormalChannelData):
|
if isinstance(channel_data, NormalChannelData):
|
||||||
channel_data: NormalChannelData
|
channel_data: NormalChannelData
|
||||||
|
Loading…
Reference in New Issue
Block a user