mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
fetchConversation: Minimize scans across loaded messages
FREEBIE
This commit is contained in:
parent
d5d1d58cc2
commit
3beecce94e
1 changed files with 16 additions and 7 deletions
|
@ -564,7 +564,11 @@
|
|||
if (typeof unreadCount !== 'number') {
|
||||
unreadCount = 0;
|
||||
}
|
||||
var startingLoadedUnread = this.getLoadedUnreadCount();
|
||||
|
||||
var startingLoadedUnread = 0;
|
||||
if (unreadCount > 0) {
|
||||
startingLoadedUnread = this.getLoadedUnreadCount();
|
||||
}
|
||||
return new Promise(function(resolve) {
|
||||
var upper;
|
||||
if (this.length === 0) {
|
||||
|
@ -586,12 +590,17 @@
|
|||
};
|
||||
this.fetch(options).then(resolve);
|
||||
}.bind(this)).then(function() {
|
||||
var loadedUnread = this.getLoadedUnreadCount();
|
||||
if (startingLoadedUnread === loadedUnread) {
|
||||
// that fetch didn't get us any more unread. stop fetching more.
|
||||
return;
|
||||
}
|
||||
if (loadedUnread < unreadCount) {
|
||||
if (unreadCount > 0) {
|
||||
if (unreadCount <= startingLoadedUnread) {
|
||||
return;
|
||||
}
|
||||
|
||||
var loadedUnread = this.getLoadedUnreadCount();
|
||||
if (startingLoadedUnread === loadedUnread) {
|
||||
// that fetch didn't get us any more unread. stop fetching more.
|
||||
return;
|
||||
}
|
||||
|
||||
return this.fetchConversation(conversationId, limit, unreadCount);
|
||||
}
|
||||
}.bind(this));
|
||||
|
|
Loading…
Reference in a new issue