Conversation: Wait for database fetch to add incoming messages
This commit is contained in:
parent
0f9bc57ccb
commit
3e5071e340
4 changed files with 21 additions and 4 deletions
|
@ -321,6 +321,7 @@
|
||||||
this.debouncedUpdateLastMessage();
|
this.debouncedUpdateLastMessage();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// For outgoing messages, we can call this directly. We're already loaded.
|
||||||
addSingleMessage(message) {
|
addSingleMessage(message) {
|
||||||
const { id } = message;
|
const { id } = message;
|
||||||
const existing = this.messageCollection.get(id);
|
const existing = this.messageCollection.get(id);
|
||||||
|
@ -342,6 +343,15 @@
|
||||||
return model;
|
return model;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// For incoming messages, they might arrive while we're in the middle of a bulk fetch
|
||||||
|
// from the database. We'll wait until that is done to process this newly-arrived
|
||||||
|
// message.
|
||||||
|
async addIncomingMessage(message) {
|
||||||
|
await this.inProgressFetch;
|
||||||
|
|
||||||
|
this.addSingleMessage(message);
|
||||||
|
},
|
||||||
|
|
||||||
format() {
|
format() {
|
||||||
return this.cachedProps;
|
return this.cachedProps;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1115,8 +1115,8 @@
|
||||||
}
|
}
|
||||||
return msFromNow;
|
return msFromNow;
|
||||||
},
|
},
|
||||||
async setToExpire(force = false, options = {}) {
|
async setToExpire(force = false, options) {
|
||||||
const { skipSave } = options;
|
const { skipSave } = options || {};
|
||||||
|
|
||||||
if (this.isExpiring() && (force || !this.get('expires_at'))) {
|
if (this.isExpiring() && (force || !this.get('expires_at'))) {
|
||||||
const start = this.get('expirationStartTimestamp');
|
const start = this.get('expirationStartTimestamp');
|
||||||
|
|
|
@ -47,8 +47,15 @@ function initialize({ events, storage, navigator, logger }) {
|
||||||
);
|
);
|
||||||
const expires = decoded.expires.toNumber();
|
const expires = decoded.expires.toNumber();
|
||||||
|
|
||||||
const time = Math.min(now + ONE_DAY, expires - MINIMUM_TIME_LEFT);
|
// If we have a time in place and it's already before the safety zone before expire,
|
||||||
|
// we keep it
|
||||||
|
if (scheduledTime && scheduledTime <= expires - MINIMUM_TIME_LEFT) {
|
||||||
|
setTimeoutForNextRun(scheduledTime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, we reset every day, or earlier if the safety zone requires it
|
||||||
|
const time = Math.min(now + ONE_DAY, expires - MINIMUM_TIME_LEFT);
|
||||||
setTimeoutForNextRun(time);
|
setTimeoutForNextRun(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1827,7 +1827,7 @@
|
||||||
// We do this here because we don't want convo.messageCollection to have
|
// We do this here because we don't want convo.messageCollection to have
|
||||||
// anything in it unless it has an associated view. This is so, when we
|
// anything in it unless it has an associated view. This is so, when we
|
||||||
// fetch on open, it's clean.
|
// fetch on open, it's clean.
|
||||||
this.model.addSingleMessage(message);
|
this.model.addIncomingMessage(message);
|
||||||
},
|
},
|
||||||
|
|
||||||
async showMembers(e, providedMembers, options = {}) {
|
async showMembers(e, providedMembers, options = {}) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue