Save the last retrieved message for public chats on the conversation

pull/460/head
Beaudan Brown 6 years ago
parent 1625a22053
commit 27976a053c

@ -227,7 +227,7 @@
);
channel.refreshModStatus();
});
}
};
const initAPIs = async () => {
const ourKey = textsecure.storage.user.getNumber();

@ -2079,6 +2079,24 @@
);
return channelAPI;
},
getLastRetrievedMessage() {
if (!this.isPublic()) {
return null;
}
const lastMessageId = this.get('lastPublicMessage') || 0;
return lastMessageId;
},
async setLastRetrievedMessage(newLastMessageId) {
if (!this.isPublic()) {
return;
}
if (this.get('lastPublicMessage') !== newLastMessageId) {
this.set({ lastPublicMessage: newLastMessageId });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
}
},
isModerator() {
if (!this.isPublic()) {
return false;

@ -205,7 +205,7 @@ class LokiPublicChannelAPI {
this.baseChannelUrl = `channels/${this.channelId}`;
this.groupName = 'unknown';
this.conversationId = conversationId;
this.lastGot = 0;
this.lastGot = null;
this.stopPolling = false;
this.modStatus = false;
this.deleteLastId = 1;
@ -416,9 +416,14 @@ class LokiPublicChannelAPI {
count: -20,
include_deleted: false,
};
if (this.lastGot) {
params.since_id = this.lastGot;
const conversation = ConversationController.get(this.conversationId);
if (!conversation) {
log.warn('Trying to poll for non-existing public conversation');
this.lastGot = 0;
} else if (!this.lastGot) {
this.lastGot = conversation.getLastRetrievedMessage();
}
params.since_id = this.lastGot;
const res = await this.serverRequest(`${this.baseChannelUrl}/messages`, {
params,
});
@ -485,6 +490,7 @@ class LokiPublicChannelAPI {
this.lastGot = !this.lastGot
? adnMessage.id
: Math.max(this.lastGot, adnMessage.id);
conversation.setLastRetrievedMessage(this.lastGot);
});
}

@ -49,7 +49,6 @@ class LokiRssAPI extends EventEmitter {
this.closeable = settings.closeable;
// non configureable options
this.feedTimer = null;
this.conversationSetup = false;
// initial set up
this.getFeed();
}

@ -89,6 +89,7 @@ class LokiSnodeAPI {
async initialiseRandomPool(seedNodes = [...window.seedNodeList]) {
const params = {
limit: 20,
active_only: true,
fields: {
public_ip: true,
storage_port: true,

Loading…
Cancel
Save