Fix stalling on empty channels

Closes #164
This commit is contained in:
chylex 2022-03-13 16:34:04 +01:00
parent f70bbd53d9
commit ad299bf762
No known key found for this signature in database
GPG Key ID: 4DE42C8F19A80548
2 changed files with 20 additions and 16 deletions

View File

@ -117,8 +117,8 @@
try {
if (!messages.length) {
DISCORD.loadOlderMessages();
isSending = false;
onTrackingContinued(false);
}
else {
const anyNewMessages = await STATE.addDiscordMessages(info.id, messages);

View File

@ -67,14 +67,7 @@ class DISCORD {
}
const messages = this.getMessages();
let hasChanged = false;
for (const message of messages) {
if (!previousMessages.has(message.id)) {
hasChanged = true;
break;
}
}
const hasChanged = messages.some(message => !previousMessages.has(message.id)) || !this.hasMoreMessages();
if (!hasChanged) {
return;
@ -140,16 +133,27 @@ class DISCORD {
try {
let obj;
for (const ele of this.getMessageElements()) {
const props = this.getMessageElementProps(ele);
try {
for (const child of DOM.getReactProps(DOM.queryReactClass("chatContent")).children) {
if (child && child.props && child.props.channel) {
obj = child.props.channel;
break;
}
}
} catch (e) {
console.error("[DHT] Error retrieving selected channel from 'chatContent' element.", e);
if (props != null) {
obj = props.channel;
break;
for (const ele of this.getMessageElements()) {
const props = this.getMessageElementProps(ele);
if (props != null) {
obj = props.channel;
break;
}
}
}
if (!obj) {
if (!obj || typeof obj.id !== "string") {
return null;
}
@ -215,7 +219,7 @@ class DISCORD {
return null;
}
} catch (e) {
console.error(e);
console.error("[DHT] Error retrieving selected channel.", e);
return null;
}
}