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,
|
SentEventData,
|
||||||
StickerPackEvent,
|
StickerPackEvent,
|
||||||
TypingEvent,
|
TypingEvent,
|
||||||
VerifiedEvent,
|
|
||||||
ViewEvent,
|
ViewEvent,
|
||||||
ViewOnceOpenSyncEvent,
|
ViewOnceOpenSyncEvent,
|
||||||
ViewSyncEvent,
|
ViewSyncEvent,
|
||||||
|
@ -327,10 +326,6 @@ export async function startApp(): Promise<void> {
|
||||||
'view',
|
'view',
|
||||||
queuedEventListener(onViewReceipt)
|
queuedEventListener(onViewReceipt)
|
||||||
);
|
);
|
||||||
messageReceiver.addEventListener(
|
|
||||||
'verified',
|
|
||||||
queuedEventListener(onVerified)
|
|
||||||
);
|
|
||||||
messageReceiver.addEventListener(
|
messageReceiver.addEventListener(
|
||||||
'error',
|
'error',
|
||||||
queuedEventListener(onError, false)
|
queuedEventListener(onError, false)
|
||||||
|
@ -3716,77 +3711,6 @@ export async function startApp(): Promise<void> {
|
||||||
return ViewSyncs.getSingleton().onSync(receipt);
|
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) {
|
function onDeliveryReceipt(ev: DeliveryEvent) {
|
||||||
const { deliveryReceipt } = ev;
|
const { deliveryReceipt } = ev;
|
||||||
const { envelopeTimestamp, sourceUuid, source, sourceDevice, timestamp } =
|
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 = {
|
export type VerificationOptions = {
|
||||||
key?: null | Uint8Array;
|
key?: null | Uint8Array;
|
||||||
viaContactSync?: boolean;
|
|
||||||
viaStorageServiceSync?: boolean;
|
viaStorageServiceSync?: boolean;
|
||||||
viaSyncMessage?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ShallowChallengeError = CustomError & {
|
export type ShallowChallengeError = CustomError & {
|
||||||
|
|
|
@ -2615,8 +2615,6 @@ export class ConversationModel extends window.Backbone
|
||||||
const options = providedOptions || {};
|
const options = providedOptions || {};
|
||||||
window._.defaults(options, {
|
window._.defaults(options, {
|
||||||
viaStorageServiceSync: false,
|
viaStorageServiceSync: false,
|
||||||
viaSyncMessage: false,
|
|
||||||
viaContactSync: false,
|
|
||||||
key: null,
|
key: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2633,7 +2631,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const uuid = this.getUuid();
|
const uuid = this.getUuid();
|
||||||
const beginningVerified = this.get('verified');
|
const beginningVerified = this.get('verified');
|
||||||
let keyChange = false;
|
let keyChange = false;
|
||||||
if (options.viaSyncMessage || options.viaStorageServiceSync) {
|
if (options.viaStorageServiceSync) {
|
||||||
strictAssert(
|
strictAssert(
|
||||||
uuid,
|
uuid,
|
||||||
`Sync message didn't update uuid for conversation: ${this.id}`
|
`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 didSomethingChange = keyChange || beginningVerified !== verified;
|
||||||
const isExplicitUserAction =
|
const isExplicitUserAction = !options.viaStorageServiceSync;
|
||||||
!options.viaContactSync && !options.viaStorageServiceSync;
|
const shouldShowFromStorageSync =
|
||||||
const shouldShowFromContactSync =
|
options.viaStorageServiceSync && verified !== UNVERIFIED;
|
||||||
options.viaContactSync && verified !== UNVERIFIED;
|
|
||||||
if (
|
if (
|
||||||
// The message came from an explicit verification in a client (not a contact sync
|
// The message came from an explicit verification in a client (not a contact sync
|
||||||
// or storage service sync)
|
// or storage service sync)
|
||||||
(didSomethingChange && isExplicitUserAction) ||
|
(didSomethingChange && isExplicitUserAction) ||
|
||||||
// The verification value received by the contact sync is different from what we
|
// The verification value received by the contact sync is different from what we
|
||||||
// have on record (and it's not a transition to UNVERIFIED)
|
// 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
|
// 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 ->
|
// change (Key1/VERIFIED -> Key2/VERIFIED), but we don't want to show DEFAULT ->
|
||||||
// DEFAULT or UNVERIFIED -> UNVERIFIED
|
// DEFAULT or UNVERIFIED -> UNVERIFIED
|
||||||
(keyChange && verified === VERIFIED)
|
(keyChange && verified === VERIFIED)
|
||||||
) {
|
) {
|
||||||
await this.addVerifiedChange(this.id, 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);
|
await this.sendVerifySyncMessage(this.get('e164'), uuid, verified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,6 @@ import {
|
||||||
KeysEvent,
|
KeysEvent,
|
||||||
PNIIdentityEvent,
|
PNIIdentityEvent,
|
||||||
StickerPackEvent,
|
StickerPackEvent,
|
||||||
VerifiedEvent,
|
|
||||||
ReadSyncEvent,
|
ReadSyncEvent,
|
||||||
ViewSyncEvent,
|
ViewSyncEvent,
|
||||||
ContactEvent,
|
ContactEvent,
|
||||||
|
@ -485,11 +484,6 @@ export default class MessageReceiver
|
||||||
handler: (ev: StickerPackEvent) => void
|
handler: (ev: StickerPackEvent) => void
|
||||||
): void;
|
): void;
|
||||||
|
|
||||||
public override addEventListener(
|
|
||||||
name: 'verified',
|
|
||||||
handler: (ev: VerifiedEvent) => void
|
|
||||||
): void;
|
|
||||||
|
|
||||||
public override addEventListener(
|
public override addEventListener(
|
||||||
name: 'readSync',
|
name: 'readSync',
|
||||||
handler: (ev: ReadSyncEvent) => void
|
handler: (ev: ReadSyncEvent) => void
|
||||||
|
@ -2458,7 +2452,9 @@ export default class MessageReceiver
|
||||||
return this.handleRead(envelope, syncMessage.read);
|
return this.handleRead(envelope, syncMessage.read);
|
||||||
}
|
}
|
||||||
if (syncMessage.verified) {
|
if (syncMessage.verified) {
|
||||||
return this.handleVerified(envelope, syncMessage.verified);
|
log.info('Got verified sync message, dropping');
|
||||||
|
this.removeFromCache(envelope);
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
if (syncMessage.configuration) {
|
if (syncMessage.configuration) {
|
||||||
return this.handleConfiguration(envelope, syncMessage.configuration);
|
return this.handleConfiguration(envelope, syncMessage.configuration);
|
||||||
|
@ -2655,27 +2651,6 @@ export default class MessageReceiver
|
||||||
return this.dispatchAndWait(ev);
|
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(
|
private async handleRead(
|
||||||
envelope: ProcessedEnvelope,
|
envelope: ProcessedEnvelope,
|
||||||
read: Array<Proto.SyncMessage.IRead>
|
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<{
|
export type ReadSyncEventData = Readonly<{
|
||||||
timestamp?: number;
|
timestamp?: number;
|
||||||
envelopeTimestamp: number;
|
envelopeTimestamp: number;
|
||||||
|
|
Loading…
Reference in a new issue