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(); channel.refreshModStatus();
}); });
} };
const initAPIs = async () => { const initAPIs = async () => {
const ourKey = textsecure.storage.user.getNumber(); const ourKey = textsecure.storage.user.getNumber();

@ -2079,6 +2079,24 @@
); );
return channelAPI; 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() { isModerator() {
if (!this.isPublic()) { if (!this.isPublic()) {
return false; return false;

@ -205,7 +205,7 @@ class LokiPublicChannelAPI {
this.baseChannelUrl = `channels/${this.channelId}`; this.baseChannelUrl = `channels/${this.channelId}`;
this.groupName = 'unknown'; this.groupName = 'unknown';
this.conversationId = conversationId; this.conversationId = conversationId;
this.lastGot = 0; this.lastGot = null;
this.stopPolling = false; this.stopPolling = false;
this.modStatus = false; this.modStatus = false;
this.deleteLastId = 1; this.deleteLastId = 1;
@ -416,9 +416,14 @@ class LokiPublicChannelAPI {
count: -20, count: -20,
include_deleted: false, include_deleted: false,
}; };
if (this.lastGot) { const conversation = ConversationController.get(this.conversationId);
params.since_id = this.lastGot; 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`, { const res = await this.serverRequest(`${this.baseChannelUrl}/messages`, {
params, params,
}); });
@ -485,6 +490,7 @@ class LokiPublicChannelAPI {
this.lastGot = !this.lastGot this.lastGot = !this.lastGot
? adnMessage.id ? adnMessage.id
: Math.max(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; this.closeable = settings.closeable;
// non configureable options // non configureable options
this.feedTimer = null; this.feedTimer = null;
this.conversationSetup = false;
// initial set up // initial set up
this.getFeed(); this.getFeed();
} }

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

Loading…
Cancel
Save