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 { try {
if (!messages.length) { if (!messages.length) {
DISCORD.loadOlderMessages();
isSending = false; isSending = false;
onTrackingContinued(false);
} }
else { else {
const anyNewMessages = await STATE.addDiscordMessages(info.id, messages); const anyNewMessages = await STATE.addDiscordMessages(info.id, messages);

View File

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