Don't re-add inbound listeners on every reconnect/sync
This commit is contained in:
parent
ada6a56135
commit
b51ce9bc96
@ -73,6 +73,38 @@ class UserClient {
|
|||||||
|
|
||||||
this.mxid = mxid
|
this.mxid = mxid
|
||||||
this.peerClient = peerClient
|
this.peerClient = peerClient
|
||||||
|
|
||||||
|
this.#talkClient.on("chat", (data, channel) => {
|
||||||
|
this.log(`Received chat message ${data.chat.logId} in channel ${channel.channelId}`)
|
||||||
|
return this.write("chat", {
|
||||||
|
//is_sequential: true, // TODO Make sequential per user & channel (if it isn't already)
|
||||||
|
chatlog: data.chat,
|
||||||
|
channelId: channel.channelId,
|
||||||
|
channelType: channel.info.type,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/* TODO Many more listeners
|
||||||
|
this.#talkClient.on("chat_read", (chat, channel, reader) => {
|
||||||
|
this.log(`chat_read in channel ${channel.channelId}`)
|
||||||
|
//chat.logId
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.#talkClient.on("disconnected", (reason) => {
|
||||||
|
this.log(`Disconnected (reason=${reason})`)
|
||||||
|
this.disconnect()
|
||||||
|
return this.write("disconnected", {
|
||||||
|
reason: reason,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
this.#talkClient.on("switch_server", () => {
|
||||||
|
this.log(`Server switch requested`)
|
||||||
|
return this.write("switch_server", {
|
||||||
|
is_sequential: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,42 +159,7 @@ class UserClient {
|
|||||||
async connect(credential) {
|
async connect(credential) {
|
||||||
// TODO Don't re-login if possible. But must still return a LoginResult!
|
// TODO Don't re-login if possible. But must still return a LoginResult!
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
const res = await this.#talkClient.login(credential)
|
return await this.#talkClient.login(credential)
|
||||||
if (!res.success) return res
|
|
||||||
|
|
||||||
this.#talkClient.on("chat", (data, channel) => {
|
|
||||||
this.log(`Received chat message ${data.chat.logId} in channel ${channel.channelId}`)
|
|
||||||
return this.write("chat", {
|
|
||||||
//is_sequential: true, // TODO Make sequential per user & channel (if it isn't already)
|
|
||||||
chatlog: data.chat,
|
|
||||||
channelId: channel.channelId,
|
|
||||||
channelType: channel.info.type,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
/* TODO Many more listeners
|
|
||||||
this.#talkClient.on("chat_read", (chat, channel, reader) => {
|
|
||||||
this.log(`chat_read in channel ${channel.channelId}`)
|
|
||||||
//chat.logId
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.#talkClient.on("disconnected", (reason) => {
|
|
||||||
this.log(`Disconnected (reason=${reason})`)
|
|
||||||
this.disconnect()
|
|
||||||
return this.write("disconnected", {
|
|
||||||
reason: reason,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
this.#talkClient.on("switch_server", () => {
|
|
||||||
this.log(`Server switch requested`)
|
|
||||||
return this.write("switch_server", {
|
|
||||||
is_sequential: true,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
Loading…
Reference in New Issue
Block a user