Use profileKey from any incoming DataMessage
This commit is contained in:
parent
e0dc4c412d
commit
7e31b37417
3 changed files with 31 additions and 14 deletions
|
@ -205,6 +205,7 @@ import { CallMode } from './types/Calling';
|
|||
import { queueSyncTasks } from './util/syncTasks';
|
||||
import { isEnabled } from './RemoteConfig';
|
||||
import { AttachmentBackupManager } from './jobs/AttachmentBackupManager';
|
||||
import { getConversationIdForLogging } from './util/idForLogging';
|
||||
|
||||
export function isOverHourIntoPast(timestamp: number): boolean {
|
||||
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
|
||||
|
@ -690,7 +691,7 @@ export async function startApp(): Promise<void> {
|
|||
);
|
||||
messageReceiver.addEventListener(
|
||||
'profileKeyUpdate',
|
||||
queuedEventListener(onProfileKeyUpdate)
|
||||
queuedEventListener(onProfileKey)
|
||||
);
|
||||
messageReceiver.addEventListener(
|
||||
'fetchLatest',
|
||||
|
@ -2523,24 +2524,30 @@ export async function startApp(): Promise<void> {
|
|||
drop(message.handleDataMessage(data.message, event.confirm));
|
||||
}
|
||||
|
||||
async function onProfileKeyUpdate({
|
||||
async function onProfileKey({
|
||||
data,
|
||||
reason,
|
||||
confirm,
|
||||
}: ProfileKeyUpdateEvent): Promise<void> {
|
||||
const logId = `onProfileKey/${reason}`;
|
||||
const { conversation } = window.ConversationController.maybeMergeContacts({
|
||||
aci: data.sourceAci,
|
||||
e164: data.source,
|
||||
reason: 'onProfileKeyUpdate',
|
||||
reason: logId,
|
||||
});
|
||||
const idForLogging = getConversationIdForLogging(conversation.attributes);
|
||||
|
||||
if (!data.profileKey) {
|
||||
log.error('onProfileKeyUpdate: missing profileKey', data.profileKey);
|
||||
log.error(
|
||||
`${logId}: missing profileKey for ${idForLogging}`,
|
||||
data.profileKey
|
||||
);
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(
|
||||
'onProfileKeyUpdate: updating profileKey for',
|
||||
`${logId}: updating profileKey for ${idForLogging}`,
|
||||
data.sourceAci,
|
||||
data.source
|
||||
);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/* 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 { v4 as getGuid } from 'uuid';
|
||||
import { existsSync } from 'fs';
|
||||
|
@ -2523,24 +2523,33 @@ export default class MessageReceiver
|
|||
p = this.handleEndSession(envelope, sourceAci);
|
||||
}
|
||||
|
||||
if (msg.flags && msg.flags & Proto.DataMessage.Flags.PROFILE_KEY_UPDATE) {
|
||||
strictAssert(
|
||||
msg.profileKey != null && msg.profileKey.length > 0,
|
||||
'PROFILE_KEY_UPDATE without profileKey'
|
||||
);
|
||||
const { profileKey } = msg;
|
||||
const hasProfileKey = profileKey && profileKey.length > 0;
|
||||
const isProfileKeyUpdate =
|
||||
msg.flags && msg.flags & Proto.DataMessage.Flags.PROFILE_KEY_UPDATE;
|
||||
|
||||
if (isProfileKeyUpdate) {
|
||||
strictAssert(hasProfileKey, 'PROFILE_KEY_UPDATE without profileKey');
|
||||
logUnexpectedUrgentValue(envelope, 'profileKeyUpdate');
|
||||
}
|
||||
|
||||
if (hasProfileKey) {
|
||||
const ev = new ProfileKeyUpdateEvent(
|
||||
{
|
||||
source: envelope.source,
|
||||
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
|
||||
);
|
||||
|
||||
if (isProfileKeyUpdate) {
|
||||
return this.dispatchAndWait(logId, ev);
|
||||
}
|
||||
|
||||
drop(this.dispatchAndWait(logId, ev));
|
||||
}
|
||||
await p;
|
||||
|
||||
let type: SendTypesType = 'message';
|
||||
|
|
|
@ -213,6 +213,7 @@ export type ProfileKeyUpdateData = Readonly<{
|
|||
export class ProfileKeyUpdateEvent extends ConfirmableEvent {
|
||||
constructor(
|
||||
public readonly data: ProfileKeyUpdateData,
|
||||
public readonly reason: string,
|
||||
confirm: ConfirmCallback
|
||||
) {
|
||||
super('profileKeyUpdate', confirm);
|
||||
|
|
Loading…
Reference in a new issue