Handles safety number changes while in a call

This commit is contained in:
Josh Perez 2020-12-08 14:37:04 -05:00 committed by GitHub
parent 561baf6309
commit 318013e83d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 387 additions and 162 deletions

View file

@ -1194,6 +1194,7 @@ export class ConversationModel extends window.Backbone.Model<
isGroupV1AndDisabled: this.isGroupV1AndDisabled(),
isPinned: this.get('isPinned'),
isMissingMandatoryProfileSharing: this.isMissingRequiredProfileSharing(),
isUntrusted: this.isUntrusted(),
isVerified: this.isVerified(),
lastMessage: {
status: this.get('lastMessageStatus')!,
@ -1809,64 +1810,50 @@ export class ConversationModel extends window.Backbone.Model<
return window.textsecure.storage.protocol.setApproval(this.id, true);
}
async safeIsUntrusted(): Promise<boolean> {
return window.textsecure.storage.protocol
.isUntrusted(this.id)
.catch(() => false);
safeIsUntrusted(): boolean {
try {
return window.textsecure.storage.protocol.isUntrusted(this.id);
} catch (err) {
return false;
}
}
async isUntrusted(): Promise<boolean> {
isUntrusted(): boolean {
if (this.isPrivate()) {
return this.safeIsUntrusted();
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!this.contactCollection!.length) {
return Promise.resolve(false);
return false;
}
return Promise.all(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.contactCollection!.map(contact => {
if (contact.isMe()) {
return false;
}
return contact.safeIsUntrusted();
})
).then(results => window._.any(results, result => result));
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.contactCollection!.any(contact => {
if (contact.isMe()) {
return false;
}
return contact.safeIsUntrusted();
});
}
async getUntrusted(): Promise<Backbone.Collection> {
// This is a bit ugly because isUntrusted() is async. Could do the work to cache
// it locally, but we really only need it for this call.
getUntrusted(): Backbone.Collection {
if (this.isPrivate()) {
return this.isUntrusted().then(untrusted => {
if (untrusted) {
return new window.Backbone.Collection([this]);
}
return new window.Backbone.Collection();
});
if (this.isUntrusted()) {
return new window.Backbone.Collection([this]);
}
return new window.Backbone.Collection();
}
return Promise.all(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.contactCollection!.map(contact => {
if (contact.isMe()) {
return [false, contact];
}
return Promise.all([contact.isUntrusted(), contact]);
})
).then(results => {
const filtered = window._.filter(results, result => {
const untrusted = result[0];
return untrusted;
});
return new window.Backbone.Collection(
window._.map(filtered, result => {
const contact = result[1];
return contact;
})
);
const results = this.contactCollection!.map(contact => {
if (contact.isMe()) {
return [false, contact];
}
return [contact.isUntrusted(), contact];
});
return new window.Backbone.Collection(
results.filter(result => result[0]).map(result => result[1])
);
}
getSentMessageCount(): number {
@ -1983,7 +1970,15 @@ export class ConversationModel extends window.Backbone.Model<
})
);
const isUntrusted = await this.isUntrusted();
this.trigger('newmessage', model);
const uuid = this.get('uuid');
// Group calls are always with folks that have a UUID
if (isUntrusted && uuid) {
window.reduxActions.calling.keyChanged({ uuid });
}
}
async addVerifiedChange(