Drop verified syncs, use storage service for event
This commit is contained in:
parent
8c4b875dca
commit
da45f26d37
5 changed files with 10 additions and 135 deletions
|
@ -84,7 +84,6 @@ import type {
|
|||
SentEventData,
|
||||
StickerPackEvent,
|
||||
TypingEvent,
|
||||
VerifiedEvent,
|
||||
ViewEvent,
|
||||
ViewOnceOpenSyncEvent,
|
||||
ViewSyncEvent,
|
||||
|
@ -327,10 +326,6 @@ export async function startApp(): Promise<void> {
|
|||
'view',
|
||||
queuedEventListener(onViewReceipt)
|
||||
);
|
||||
messageReceiver.addEventListener(
|
||||
'verified',
|
||||
queuedEventListener(onVerified)
|
||||
);
|
||||
messageReceiver.addEventListener(
|
||||
'error',
|
||||
queuedEventListener(onError, false)
|
||||
|
@ -3716,77 +3711,6 @@ export async function startApp(): Promise<void> {
|
|||
return ViewSyncs.getSingleton().onSync(receipt);
|
||||
}
|
||||
|
||||
async function onVerified(ev: VerifiedEvent) {
|
||||
const e164 = ev.verified.destination;
|
||||
const uuid = ev.verified.destinationUuid;
|
||||
const key = ev.verified.identityKey;
|
||||
let state;
|
||||
|
||||
if (ev.confirm) {
|
||||
ev.confirm();
|
||||
}
|
||||
|
||||
const c = new window.Whisper.Conversation({
|
||||
e164,
|
||||
uuid,
|
||||
type: 'private',
|
||||
} as Partial<ConversationAttributesType> as WhatIsThis);
|
||||
const error = c.validate();
|
||||
if (error) {
|
||||
log.error(
|
||||
'Invalid verified sync received:',
|
||||
e164,
|
||||
uuid,
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ev.verified.state) {
|
||||
case Proto.Verified.State.DEFAULT:
|
||||
state = 'DEFAULT';
|
||||
break;
|
||||
case Proto.Verified.State.VERIFIED:
|
||||
state = 'VERIFIED';
|
||||
break;
|
||||
case Proto.Verified.State.UNVERIFIED:
|
||||
state = 'UNVERIFIED';
|
||||
break;
|
||||
default:
|
||||
log.error(`Got unexpected verified state: ${ev.verified.state}`);
|
||||
}
|
||||
|
||||
log.info(
|
||||
'got verified sync for',
|
||||
e164,
|
||||
uuid,
|
||||
state,
|
||||
ev.verified.viaContactSync ? 'via contact sync' : ''
|
||||
);
|
||||
|
||||
const verifiedId = window.ConversationController.ensureContactIds({
|
||||
e164,
|
||||
uuid,
|
||||
highTrust: true,
|
||||
reason: 'onVerified',
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const contact = window.ConversationController.get(verifiedId)!;
|
||||
const options = {
|
||||
viaSyncMessage: true,
|
||||
viaContactSync: ev.verified.viaContactSync,
|
||||
key,
|
||||
};
|
||||
|
||||
if (state === 'VERIFIED') {
|
||||
await contact.setVerified(options);
|
||||
} else if (state === 'DEFAULT') {
|
||||
await contact.setVerifiedDefault(options);
|
||||
} else {
|
||||
await contact.setUnverified(options);
|
||||
}
|
||||
}
|
||||
|
||||
function onDeliveryReceipt(ev: DeliveryEvent) {
|
||||
const { deliveryReceipt } = ev;
|
||||
const { envelopeTimestamp, sourceUuid, source, sourceDevice, timestamp } =
|
||||
|
|
2
ts/model-types.d.ts
vendored
2
ts/model-types.d.ts
vendored
|
@ -403,9 +403,7 @@ export type GroupV2PendingAdminApprovalType = {
|
|||
|
||||
export type VerificationOptions = {
|
||||
key?: null | Uint8Array;
|
||||
viaContactSync?: boolean;
|
||||
viaStorageServiceSync?: boolean;
|
||||
viaSyncMessage?: boolean;
|
||||
};
|
||||
|
||||
export type ShallowChallengeError = CustomError & {
|
||||
|
|
|
@ -2615,8 +2615,6 @@ export class ConversationModel extends window.Backbone
|
|||
const options = providedOptions || {};
|
||||
window._.defaults(options, {
|
||||
viaStorageServiceSync: false,
|
||||
viaSyncMessage: false,
|
||||
viaContactSync: false,
|
||||
key: null,
|
||||
});
|
||||
|
||||
|
@ -2633,7 +2631,7 @@ export class ConversationModel extends window.Backbone
|
|||
const uuid = this.getUuid();
|
||||
const beginningVerified = this.get('verified');
|
||||
let keyChange = false;
|
||||
if (options.viaSyncMessage || options.viaStorageServiceSync) {
|
||||
if (options.viaStorageServiceSync) {
|
||||
strictAssert(
|
||||
uuid,
|
||||
`Sync message didn't update uuid for conversation: ${this.id}`
|
||||
|
@ -2670,27 +2668,26 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
const didSomethingChange = keyChange || beginningVerified !== verified;
|
||||
const isExplicitUserAction =
|
||||
!options.viaContactSync && !options.viaStorageServiceSync;
|
||||
const shouldShowFromContactSync =
|
||||
options.viaContactSync && verified !== UNVERIFIED;
|
||||
const isExplicitUserAction = !options.viaStorageServiceSync;
|
||||
const shouldShowFromStorageSync =
|
||||
options.viaStorageServiceSync && verified !== UNVERIFIED;
|
||||
if (
|
||||
// The message came from an explicit verification in a client (not a contact sync
|
||||
// or storage service sync)
|
||||
(didSomethingChange && isExplicitUserAction) ||
|
||||
// The verification value received by the contact sync is different from what we
|
||||
// have on record (and it's not a transition to UNVERIFIED)
|
||||
(didSomethingChange && shouldShowFromContactSync) ||
|
||||
(didSomethingChange && shouldShowFromStorageSync) ||
|
||||
// Our local verification status is VERIFIED and it hasn't changed, but the key did
|
||||
// change (Key1/VERIFIED -> Key2/VERIFIED), but we don't want to show DEFAULT ->
|
||||
// DEFAULT or UNVERIFIED -> UNVERIFIED
|
||||
(keyChange && verified === VERIFIED)
|
||||
) {
|
||||
await this.addVerifiedChange(this.id, verified === VERIFIED, {
|
||||
local: !options.viaSyncMessage,
|
||||
local: isExplicitUserAction,
|
||||
});
|
||||
}
|
||||
if (!options.viaSyncMessage && uuid) {
|
||||
if (isExplicitUserAction && uuid) {
|
||||
await this.sendVerifySyncMessage(this.get('e164'), uuid, verified);
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,6 @@ import {
|
|||
KeysEvent,
|
||||
PNIIdentityEvent,
|
||||
StickerPackEvent,
|
||||
VerifiedEvent,
|
||||
ReadSyncEvent,
|
||||
ViewSyncEvent,
|
||||
ContactEvent,
|
||||
|
@ -485,11 +484,6 @@ export default class MessageReceiver
|
|||
handler: (ev: StickerPackEvent) => void
|
||||
): void;
|
||||
|
||||
public override addEventListener(
|
||||
name: 'verified',
|
||||
handler: (ev: VerifiedEvent) => void
|
||||
): void;
|
||||
|
||||
public override addEventListener(
|
||||
name: 'readSync',
|
||||
handler: (ev: ReadSyncEvent) => void
|
||||
|
@ -2458,7 +2452,9 @@ export default class MessageReceiver
|
|||
return this.handleRead(envelope, syncMessage.read);
|
||||
}
|
||||
if (syncMessage.verified) {
|
||||
return this.handleVerified(envelope, syncMessage.verified);
|
||||
log.info('Got verified sync message, dropping');
|
||||
this.removeFromCache(envelope);
|
||||
return undefined;
|
||||
}
|
||||
if (syncMessage.configuration) {
|
||||
return this.handleConfiguration(envelope, syncMessage.configuration);
|
||||
|
@ -2655,27 +2651,6 @@ export default class MessageReceiver
|
|||
return this.dispatchAndWait(ev);
|
||||
}
|
||||
|
||||
private async handleVerified(
|
||||
envelope: ProcessedEnvelope,
|
||||
verified: Proto.IVerified
|
||||
): Promise<void> {
|
||||
const ev = new VerifiedEvent(
|
||||
{
|
||||
state: verified.state,
|
||||
destination: dropNull(verified.destination),
|
||||
destinationUuid: verified.destinationUuid
|
||||
? normalizeUuid(
|
||||
verified.destinationUuid,
|
||||
'handleVerified.destinationUuid'
|
||||
)
|
||||
: undefined,
|
||||
identityKey: verified.identityKey ? verified.identityKey : undefined,
|
||||
},
|
||||
this.removeFromCache.bind(this, envelope)
|
||||
);
|
||||
return this.dispatchAndWait(ev);
|
||||
}
|
||||
|
||||
private async handleRead(
|
||||
envelope: ProcessedEnvelope,
|
||||
read: Array<Proto.SyncMessage.IRead>
|
||||
|
|
|
@ -379,25 +379,6 @@ export class StickerPackEvent extends ConfirmableEvent {
|
|||
}
|
||||
}
|
||||
|
||||
export type VerifiedEventData = Readonly<{
|
||||
state: Proto.IVerified['state'];
|
||||
destination?: string;
|
||||
destinationUuid?: string;
|
||||
identityKey?: Uint8Array;
|
||||
|
||||
// Used in `ts/background.ts`
|
||||
viaContactSync?: boolean;
|
||||
}>;
|
||||
|
||||
export class VerifiedEvent extends ConfirmableEvent {
|
||||
constructor(
|
||||
public readonly verified: VerifiedEventData,
|
||||
confirm: ConfirmCallback
|
||||
) {
|
||||
super('verified', confirm);
|
||||
}
|
||||
}
|
||||
|
||||
export type ReadSyncEventData = Readonly<{
|
||||
timestamp?: number;
|
||||
envelopeTimestamp: number;
|
||||
|
|
Loading…
Reference in a new issue