Merge pull request #1419 from Bilb/fix-pull-messages-open-groups

Fix pull messages open groups
pull/1435/head
Audric Ackermann 4 years ago committed by GitHub
commit 750b84066a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1051,7 +1051,7 @@ class LokiPublicChannelAPI {
this.baseChannelUrl = `channels/${this.channelId}`;
this.conversationId = conversationId;
this.conversation = ConversationController.getOrThrow(conversationId);
this.lastGot = null;
this.lastMessageServerID = null;
this.modStatus = false;
this.deleteLastId = 1;
this.timers = {};
@ -1664,14 +1664,20 @@ class LokiPublicChannelAPI {
};
if (!this.conversation) {
log.warn('Trying to poll for non-existing public conversation');
this.lastGot = 0;
} else if (!this.lastGot) {
this.lastGot = this.conversation.getLastRetrievedMessage();
}
params.since_id = this.lastGot;
// Just grab the most recent 100 messages if you don't have a valid lastGot
params.count = this.lastGot === 0 ? -100 : 20;
// log.info(`Getting ${params.count} from ${this.lastGot} on ${this.baseChannelUrl}`);
this.lastMessageServerID = 0;
} else if (!this.lastMessageServerID) {
this.lastMessageServerID = this.conversation.getLastRetrievedMessage();
}
// If lastMessageServerID is not set, it's the first pull of messages for this open group.
// We just pull 100 messages (server sends the most recent ones)
if (!this.lastMessageServerID || this.lastMessageServerID === 0) {
params.count = 100; // 64 on android
} else {
// if lastMessageServerID is set, we pull 200 messages per 200 messages, giving the since_id parameter set to our last received message id.
params.count = 200;
params.since_id = this.lastMessageServerID;
}
// log.info(`Getting ${params.count} from ${this.lastMessageServerID} on ${this.baseChannelUrl}`);
const res = await this.serverRequest(`${this.baseChannelUrl}/messages`, {
params,
});
@ -1709,9 +1715,9 @@ class LokiPublicChannelAPI {
// process these in chronological order
res.response.data.reverse().map(async adnMessage => {
// still update our last received if deleted, not signed or not valid
this.lastGot = !this.lastGot
this.lastMessageServerID = !this.lastMessageServerID
? adnMessage.id
: Math.max(this.lastGot, adnMessage.id);
: Math.max(this.lastMessageServerID, adnMessage.id);
if (
!adnMessage.id ||
@ -1850,7 +1856,7 @@ class LokiPublicChannelAPI {
// return early if we should stop processing
if (!pendingMessages.length || !this.running) {
this.conversation.setLastRetrievedMessage(this.lastGot);
this.conversation.setLastRetrievedMessage(this.lastMessageServerID);
this.messagesPollLock = false;
return;
}
@ -2016,7 +2022,7 @@ class LokiPublicChannelAPI {
}
// finally update our position
this.conversation.setLastRetrievedMessage(this.lastGot);
this.conversation.setLastRetrievedMessage(this.lastMessageServerID);
this.messagesPollLock = false;
}

Loading…
Cancel
Save