Awaitable / Promise cleanups

This commit is contained in:
Andrew Ferrazzutti 2022-04-13 03:15:28 -04:00
parent 7a78d6ba25
commit b29453a871
2 changed files with 40 additions and 40 deletions

View File

@ -430,15 +430,15 @@ class Client:
# region listeners
async def _on_chat(self, data: dict[str, JSON]) -> None:
await self.user.on_chat(
def _on_chat(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_chat(
Chatlog.deserialize(data["chatlog"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_chat_deleted(self, data: dict[str, JSON]) -> None:
await self.user.on_chat_deleted(
def _on_chat_deleted(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_chat_deleted(
Long.deserialize(data["chatId"]),
Long.deserialize(data["senderId"]),
int(data["timestamp"]),
@ -446,76 +446,76 @@ class Client:
str(data["channelType"]),
)
async def _on_chat_read(self, data: dict[str, JSON]) -> None:
await self.user.on_chat_read(
def _on_chat_read(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_chat_read(
Long.deserialize(data["chatId"]),
Long.deserialize(data["senderId"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_profile_changed(self, data: dict[str, JSON]) -> None:
await self.user.on_profile_changed(
def _on_profile_changed(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_profile_changed(
OpenLinkChannelUserInfo.deserialize(data["info"]),
)
async def _on_perm_changed(self, data: dict[str, JSON]) -> None:
await self.user.on_perm_changed(
def _on_perm_changed(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_perm_changed(
Long.deserialize(data["userId"]),
OpenChannelUserPerm(data["perm"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_channel_join(self, data: dict[str, JSON]) -> None:
await self.user.on_channel_join(
def _on_channel_join(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_channel_join(
ChannelInfo.deserialize(data["channelInfo"]),
)
async def _on_channel_left(self, data: dict[str, JSON]) -> None:
await self.user.on_channel_left(
def _on_channel_left(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_channel_left(
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_channel_kicked(self, data: dict[str, JSON]) -> None:
await self.user.on_channel_kicked(
def _on_channel_kicked(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_channel_kicked(
Long.deserialize(data["userId"]),
Long.deserialize(data["senderId"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_user_join(self, data: dict[str, JSON]) -> None:
await self.user.on_user_join(
def _on_user_join(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_user_join(
Long.deserialize(data["userId"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_user_left(self, data: dict[str, JSON]) -> None:
await self.user.on_user_left(
def _on_user_left(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_user_left(
Long.deserialize(data["userId"]),
Long.deserialize(data["channelId"]),
str(data["channelType"]),
)
async def _on_listen_disconnect(self, data: dict[str, JSON]) -> None:
def _on_listen_disconnect(self, data: dict[str, JSON]) -> Awaitable[None]:
try:
res = KickoutRes.deserialize(data)
except Exception:
self.log.exception("Invalid kickout reason, defaulting to None")
res = None
await self._on_disconnect(res)
return self._on_disconnect(res)
async def _on_switch_server(self) -> None:
def _on_switch_server(self) -> Awaitable[None]:
# TODO Reconnect automatically instead
await self._on_disconnect(KickoutRes(KnownKickoutType.CHANGE_SERVER))
return self._on_disconnect(KickoutRes(KnownKickoutType.CHANGE_SERVER))
async def _on_disconnect(self, res: KickoutRes | None) -> None:
def _on_disconnect(self, res: KickoutRes | None) -> Awaitable[None]:
self._stop_listen()
await self.user.on_disconnect(res)
return self.user.on_disconnect(res)
def _on_error(self, data: dict[str, JSON]) -> Awaitable[None]:
return self.user.on_error(data)

View File

@ -85,7 +85,7 @@ class UserClient {
this.#talkClient.on("chat", (data, channel) => {
this.log(`${data.chat.logId} received in channel ${channel.channelId}`)
return this.write("chat", {
this.write("chat", {
//is_sequential: true, // TODO Make sequential per user & channel (if it isn't already)
chatlog: data.chat,
channelId: channel.channelId,
@ -95,7 +95,7 @@ class UserClient {
this.#talkClient.on("chat_deleted", (feedChatlog, channel, feed) => {
this.log(`${feed.logId} deleted in channel ${channel.channelId} by user ${feedChatlog.sender.userId}`)
return this.write("chat_deleted", {
this.write("chat_deleted", {
chatId: feed.logId,
senderId: feedChatlog.sender.userId,
timestamp: feedChatlog.sendAt,
@ -106,7 +106,7 @@ class UserClient {
this.#talkClient.on("message_hidden", (hideLog, channel, feed) => {
this.log(`Message ${feed.logId} hid from channel ${channel.channelId} by user ${hideLog.sender.userId}`)
return this.write("chat_deleted", {
this.write("chat_deleted", {
chatId: feed.logId,
senderId: hideLog.sender.userId,
timestamp: hideLog.sendAt,
@ -117,7 +117,7 @@ class UserClient {
this.#talkClient.on("chat_read", (chat, channel, reader) => {
this.log(`${chat.logId} read in channel ${channel.channelId} by ${reader.userId}`)
return this.write("chat_read", {
this.write("chat_read", {
chatId: chat.logId,
senderId: reader.userId,
channelId: channel.channelId,
@ -127,7 +127,7 @@ class UserClient {
this.#talkClient.on("profile_changed", (channel, lastInfo, user) => {
this.log(`Profile of ${user.userId} changed (channel: ${channel ? channel.channelId : "None"})`)
return this.write("profile_changed", {
this.write("profile_changed", {
info: user,
/* TODO Is this ever a per-channel profile change?
channelId: channel.channelId,
@ -139,7 +139,7 @@ class UserClient {
this.#talkClient.on("perm_changed", (channel, lastInfo, user) => {
// TODO Fix the type hint on lastInfo and user: they should each be a OpenChannelUserInfo, not just a ChannelUserInfo
this.log(`Perms of user ${user.userId} in channel ${channel.channelId} changed from ${lastInfo.perm} to ${user.perm}`)
return this.write("perm_changed", {
this.write("perm_changed", {
is_sequential: true,
userId: user.userId,
perm: user.perm,
@ -150,14 +150,14 @@ class UserClient {
this.#talkClient.on("channel_join", channel => {
this.log(`Joined channel ${channel.channelId}`)
return this.write("channel_join", {
this.write("channel_join", {
channelInfo: channel.info,
})
})
this.#talkClient.on("channel_left", channel => {
this.log(`Left channel ${channel.channelId}`)
return this.write("channel_left", {
this.write("channel_left", {
channelId: channel.channelId,
channelType: channel.info.type,
})
@ -165,7 +165,7 @@ class UserClient {
this.#talkClient.on("channel_kicked", (kickedLog, channel, feed) => {
this.log(`User ${feed.member.userId} kicked from channel ${channel.channelId} by user ${kickedLog.sender.userId}`)
return this.write("channel_kicked", {
this.write("channel_kicked", {
userId: feed.member.userId,
senderId: kickedLog.sender.userId,
channelId: channel.channelId,
@ -175,7 +175,7 @@ class UserClient {
this.#talkClient.on("user_join", (joinLog, channel, user, feed) => {
this.log(`User ${user.userId} joined channel ${channel.channelId}`)
return this.write("user_join", {
this.write("user_join", {
userId: user.userId,
channelId: channel.channelId,
channelType: channel.info.type,
@ -184,7 +184,7 @@ class UserClient {
this.#talkClient.on("user_left", (leftLog, channel, user, feed) => {
this.log(`User ${user.userId} left channel ${channel.channelId}`)
return this.write("user_left", {
this.write("user_left", {
userId: user.userId,
channelId: channel.channelId,
channelType: channel.info.type,
@ -194,21 +194,21 @@ class UserClient {
this.#talkClient.on("disconnected", (reason) => {
this.log(`Disconnected (reason=${reason})`)
this.disconnect()
return this.write("disconnected", {
this.write("disconnected", {
reason: reason,
})
})
this.#talkClient.on("switch_server", () => {
this.log(`Server switch requested`)
return this.write("switch_server", {
this.write("switch_server", {
is_sequential: true,
})
})
this.#talkClient.on("error", (err) => {
this.log(`Client error: ${err}`)
return this.write("error", {
this.write("error", {
error: err,
})
})