combineContacts: Don't clear conversations to reset lookups

This commit is contained in:
Scott Nonnenberg 2020-07-24 16:52:26 -07:00
parent bab59ba2a1
commit 5a79ed1c60
2 changed files with 25 additions and 19 deletions

View file

@ -2860,9 +2860,7 @@
* than just their id.
*/
initialize() {
this._byE164 = Object.create(null);
this._byUuid = Object.create(null);
this._byGroupId = Object.create(null);
this.eraseLookups();
this.on('idUpdated', (model, idProp, oldValue) => {
if (oldValue) {
if (idProp === 'e164') {
@ -2889,14 +2887,16 @@
reset(...args) {
Backbone.Collection.prototype.reset.apply(this, args);
this._byE164 = Object.create(null);
this._byUuid = Object.create(null);
this._byGroupId = Object.create(null);
this.resetLookups();
},
add(...models) {
const res = Backbone.Collection.prototype.add.apply(this, models);
[].concat(res).forEach(model => {
resetLookups() {
this.eraseLookups();
this.generateLookups(this.models);
},
generateLookups(models) {
models.forEach(model => {
const e164 = model.get('e164');
if (e164) {
const existing = this._byE164[e164];
@ -2922,7 +2922,20 @@
this._byGroupId[groupId] = model;
}
});
return res;
},
eraseLookups() {
this._byE164 = Object.create(null);
this._byUuid = Object.create(null);
this._byGroupId = Object.create(null);
},
add(...models) {
const result = Backbone.Collection.prototype.add.apply(this, models);
this.generateLookups(Array.isArray(result) ? result.slice(0) : [result]);
return result;
},
/**

View file

@ -366,6 +366,7 @@ export class ConversationController {
// Conflict: If e164 match has no UUID, we merge. We prefer the UUID match.
// Note: no await here, we want to keep this function synchronous
convoUuid.updateE164(e164);
this.combineContacts(convoUuid, convoE164)
.then(() => {
// If the old conversation was currently displayed, we load the new one
@ -537,21 +538,13 @@ export class ConversationController {
'combineContacts: Eliminate old conversation from ConversationController lookups'
);
this._conversations.remove(obsolete);
this.regenerateLookups();
this._conversations.resetLookups();
window.log.warn('combineContacts: Complete!', {
obsolete: obsoleteId,
current: currentId,
});
}
regenerateLookups() {
const models = [...this._conversations.models];
this.reset();
this._conversations.add(models);
// We force the initial fetch to be true
this._initialFetchComplete = true;
}
/**
* Given a groupId and optional additional initialization properties,
* ensures the existence of a group conversation and returns a string