Use profileKey from any incoming DataMessage

This commit is contained in:
Scott Nonnenberg 2024-06-11 06:21:44 +10:00 committed by ayumi-signal
parent e0dc4c412d
commit 7e31b37417
3 changed files with 31 additions and 14 deletions

View file

@ -205,6 +205,7 @@ import { CallMode } from './types/Calling';
import { queueSyncTasks } from './util/syncTasks'; import { queueSyncTasks } from './util/syncTasks';
import { isEnabled } from './RemoteConfig'; import { isEnabled } from './RemoteConfig';
import { AttachmentBackupManager } from './jobs/AttachmentBackupManager'; import { AttachmentBackupManager } from './jobs/AttachmentBackupManager';
import { getConversationIdForLogging } from './util/idForLogging';
export function isOverHourIntoPast(timestamp: number): boolean { export function isOverHourIntoPast(timestamp: number): boolean {
return isNumber(timestamp) && isOlderThan(timestamp, HOUR); return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
@ -690,7 +691,7 @@ export async function startApp(): Promise<void> {
); );
messageReceiver.addEventListener( messageReceiver.addEventListener(
'profileKeyUpdate', 'profileKeyUpdate',
queuedEventListener(onProfileKeyUpdate) queuedEventListener(onProfileKey)
); );
messageReceiver.addEventListener( messageReceiver.addEventListener(
'fetchLatest', 'fetchLatest',
@ -2523,24 +2524,30 @@ export async function startApp(): Promise<void> {
drop(message.handleDataMessage(data.message, event.confirm)); drop(message.handleDataMessage(data.message, event.confirm));
} }
async function onProfileKeyUpdate({ async function onProfileKey({
data, data,
reason,
confirm, confirm,
}: ProfileKeyUpdateEvent): Promise<void> { }: ProfileKeyUpdateEvent): Promise<void> {
const logId = `onProfileKey/${reason}`;
const { conversation } = window.ConversationController.maybeMergeContacts({ const { conversation } = window.ConversationController.maybeMergeContacts({
aci: data.sourceAci, aci: data.sourceAci,
e164: data.source, e164: data.source,
reason: 'onProfileKeyUpdate', reason: logId,
}); });
const idForLogging = getConversationIdForLogging(conversation.attributes);
if (!data.profileKey) { if (!data.profileKey) {
log.error('onProfileKeyUpdate: missing profileKey', data.profileKey); log.error(
`${logId}: missing profileKey for ${idForLogging}`,
data.profileKey
);
confirm(); confirm();
return; return;
} }
log.info( log.info(
'onProfileKeyUpdate: updating profileKey for', `${logId}: updating profileKey for ${idForLogging}`,
data.sourceAci, data.sourceAci,
data.source data.source
); );

View file

@ -3,7 +3,7 @@
/* eslint-disable no-bitwise */ /* eslint-disable no-bitwise */
import { isBoolean, isNumber, isString, omit } from 'lodash'; import { isBoolean, isNumber, isString, noop, omit } from 'lodash';
import PQueue from 'p-queue'; import PQueue from 'p-queue';
import { v4 as getGuid } from 'uuid'; import { v4 as getGuid } from 'uuid';
import { existsSync } from 'fs'; import { existsSync } from 'fs';
@ -2523,23 +2523,32 @@ export default class MessageReceiver
p = this.handleEndSession(envelope, sourceAci); p = this.handleEndSession(envelope, sourceAci);
} }
if (msg.flags && msg.flags & Proto.DataMessage.Flags.PROFILE_KEY_UPDATE) { const { profileKey } = msg;
strictAssert( const hasProfileKey = profileKey && profileKey.length > 0;
msg.profileKey != null && msg.profileKey.length > 0, const isProfileKeyUpdate =
'PROFILE_KEY_UPDATE without profileKey' msg.flags && msg.flags & Proto.DataMessage.Flags.PROFILE_KEY_UPDATE;
);
if (isProfileKeyUpdate) {
strictAssert(hasProfileKey, 'PROFILE_KEY_UPDATE without profileKey');
logUnexpectedUrgentValue(envelope, 'profileKeyUpdate'); logUnexpectedUrgentValue(envelope, 'profileKeyUpdate');
}
if (hasProfileKey) {
const ev = new ProfileKeyUpdateEvent( const ev = new ProfileKeyUpdateEvent(
{ {
source: envelope.source, source: envelope.source,
sourceAci, sourceAci,
profileKey: Bytes.toBase64(msg.profileKey), profileKey: Bytes.toBase64(profileKey),
}, },
this.removeFromCache.bind(this, envelope) isProfileKeyUpdate ? 'profileKeyUpdate' : 'profileKeyHarvest',
isProfileKeyUpdate ? this.removeFromCache.bind(this, envelope) : noop
); );
return this.dispatchAndWait(logId, ev);
if (isProfileKeyUpdate) {
return this.dispatchAndWait(logId, ev);
}
drop(this.dispatchAndWait(logId, ev));
} }
await p; await p;

View file

@ -213,6 +213,7 @@ export type ProfileKeyUpdateData = Readonly<{
export class ProfileKeyUpdateEvent extends ConfirmableEvent { export class ProfileKeyUpdateEvent extends ConfirmableEvent {
constructor( constructor(
public readonly data: ProfileKeyUpdateData, public readonly data: ProfileKeyUpdateData,
public readonly reason: string,
confirm: ConfirmCallback confirm: ConfirmCallback
) { ) {
super('profileKeyUpdate', confirm); super('profileKeyUpdate', confirm);