updateSharedGroups: Make one database query, check for membership, sort

This commit is contained in:
Scott Nonnenberg 2022-01-06 07:20:54 -08:00 committed by GitHub
parent fc3ebe40a7
commit 7d397167cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -4590,16 +4590,23 @@ export class ConversationModel extends window.Backbone
}
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
const ourGroups =
await window.ConversationController.getAllGroupsInvolvingUuid(ourUuid);
const theirUuid = this.getUuid();
if (!theirUuid) {
return;
}
const theirGroups =
await window.ConversationController.getAllGroupsInvolvingUuid(theirUuid);
const sharedGroups = window._.intersection(ourGroups, theirGroups);
const ourGroups =
await window.ConversationController.getAllGroupsInvolvingUuid(ourUuid);
const sharedGroups = ourGroups
.filter(
c =>
c.hasMember(ourUuid.toString()) && c.hasMember(theirUuid.toString())
)
.sort(
(left, right) =>
(right.get('timestamp') || 0) - (left.get('timestamp') || 0)
);
const sharedGroupNames = sharedGroups.map(conversation =>
conversation.getTitle()
);