combineContacts: Don't clear conversations to reset lookups
This commit is contained in:
parent
bab59ba2a1
commit
5a79ed1c60
2 changed files with 25 additions and 19 deletions
|
@ -2860,9 +2860,7 @@
|
||||||
* than just their id.
|
* than just their id.
|
||||||
*/
|
*/
|
||||||
initialize() {
|
initialize() {
|
||||||
this._byE164 = Object.create(null);
|
this.eraseLookups();
|
||||||
this._byUuid = Object.create(null);
|
|
||||||
this._byGroupId = Object.create(null);
|
|
||||||
this.on('idUpdated', (model, idProp, oldValue) => {
|
this.on('idUpdated', (model, idProp, oldValue) => {
|
||||||
if (oldValue) {
|
if (oldValue) {
|
||||||
if (idProp === 'e164') {
|
if (idProp === 'e164') {
|
||||||
|
@ -2889,14 +2887,16 @@
|
||||||
|
|
||||||
reset(...args) {
|
reset(...args) {
|
||||||
Backbone.Collection.prototype.reset.apply(this, args);
|
Backbone.Collection.prototype.reset.apply(this, args);
|
||||||
this._byE164 = Object.create(null);
|
this.resetLookups();
|
||||||
this._byUuid = Object.create(null);
|
|
||||||
this._byGroupId = Object.create(null);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
add(...models) {
|
resetLookups() {
|
||||||
const res = Backbone.Collection.prototype.add.apply(this, models);
|
this.eraseLookups();
|
||||||
[].concat(res).forEach(model => {
|
this.generateLookups(this.models);
|
||||||
|
},
|
||||||
|
|
||||||
|
generateLookups(models) {
|
||||||
|
models.forEach(model => {
|
||||||
const e164 = model.get('e164');
|
const e164 = model.get('e164');
|
||||||
if (e164) {
|
if (e164) {
|
||||||
const existing = this._byE164[e164];
|
const existing = this._byE164[e164];
|
||||||
|
@ -2922,7 +2922,20 @@
|
||||||
this._byGroupId[groupId] = model;
|
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;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -366,6 +366,7 @@ export class ConversationController {
|
||||||
|
|
||||||
// Conflict: If e164 match has no UUID, we merge. We prefer the UUID match.
|
// 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
|
// Note: no await here, we want to keep this function synchronous
|
||||||
|
convoUuid.updateE164(e164);
|
||||||
this.combineContacts(convoUuid, convoE164)
|
this.combineContacts(convoUuid, convoE164)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// If the old conversation was currently displayed, we load the new one
|
// 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'
|
'combineContacts: Eliminate old conversation from ConversationController lookups'
|
||||||
);
|
);
|
||||||
this._conversations.remove(obsolete);
|
this._conversations.remove(obsolete);
|
||||||
this.regenerateLookups();
|
this._conversations.resetLookups();
|
||||||
|
|
||||||
window.log.warn('combineContacts: Complete!', {
|
window.log.warn('combineContacts: Complete!', {
|
||||||
obsolete: obsoleteId,
|
obsolete: obsoleteId,
|
||||||
current: currentId,
|
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,
|
* Given a groupId and optional additional initialization properties,
|
||||||
* ensures the existence of a group conversation and returns a string
|
* ensures the existence of a group conversation and returns a string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue