Fix attribution of chat updates on import

This commit is contained in:
Fedor Indutny 2025-01-21 16:47:13 -08:00 committed by GitHub
parent 0d6cd429d0
commit bdb43a6758
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View file

@ -297,7 +297,7 @@ export class BackupImportStream extends Writable {
await this.#processFrame(frame, { aboutMe: this.#aboutMe }); await this.#processFrame(frame, { aboutMe: this.#aboutMe });
if (!this.#aboutMe && this.#ourConversation) { if (!this.#aboutMe && this.#ourConversation) {
const { serviceId, pni } = this.#ourConversation; const { serviceId, pni, e164 } = this.#ourConversation;
strictAssert( strictAssert(
isAciString(serviceId), isAciString(serviceId),
'ourConversation serviceId must be ACI' 'ourConversation serviceId must be ACI'
@ -305,6 +305,7 @@ export class BackupImportStream extends Writable {
this.#aboutMe = { this.#aboutMe = {
aci: serviceId, aci: serviceId,
pni, pni,
e164,
}; };
} }
} }
@ -2336,7 +2337,12 @@ export class BackupImportStream extends Writable {
if (updateMessage.expirationTimerChange) { if (updateMessage.expirationTimerChange) {
const { expiresInMs } = updateMessage.expirationTimerChange; const { expiresInMs } = updateMessage.expirationTimerChange;
const sourceServiceId = author?.serviceId ?? aboutMe.aci; let sourceServiceId = author?.serviceId;
let source = author?.e164;
if (!sourceServiceId) {
sourceServiceId = aboutMe.aci;
source = aboutMe.e164;
}
const expireTimer = DurationInSeconds.fromMillis( const expireTimer = DurationInSeconds.fromMillis(
expiresInMs?.toNumber() ?? 0 expiresInMs?.toNumber() ?? 0
); );
@ -2345,6 +2351,7 @@ export class BackupImportStream extends Writable {
message: { message: {
type: 'timer-notification', type: 'timer-notification',
sourceServiceId, sourceServiceId,
source,
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE, flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: { expirationTimerUpdate: {
expireTimer, expireTimer,
@ -2506,6 +2513,7 @@ export class BackupImportStream extends Writable {
type: 'call-history', type: 'call-history',
callId, callId,
sourceServiceId: undefined, sourceServiceId: undefined,
source: undefined,
readStatus: ReadStatus.Read, readStatus: ReadStatus.Read,
seenStatus: read ? SeenStatus.Seen : SeenStatus.Unseen, seenStatus: read ? SeenStatus.Seen : SeenStatus.Unseen,
}, },
@ -2565,6 +2573,7 @@ export class BackupImportStream extends Writable {
type: 'call-history', type: 'call-history',
callId, callId,
sourceServiceId: undefined, sourceServiceId: undefined,
source: undefined,
readStatus: ReadStatus.Read, readStatus: ReadStatus.Read,
seenStatus: read ? SeenStatus.Seen : SeenStatus.Unseen, seenStatus: read ? SeenStatus.Seen : SeenStatus.Unseen,
}, },
@ -2579,11 +2588,12 @@ export class BackupImportStream extends Writable {
groupChange: Backups.IGroupChangeChatUpdate, groupChange: Backups.IGroupChangeChatUpdate,
options: { options: {
aboutMe: AboutMe; aboutMe: AboutMe;
author?: ConversationAttributesType;
timestamp: number; timestamp: number;
} }
): Promise<ChatItemParseResult | undefined> { ): Promise<ChatItemParseResult | undefined> {
const { updates } = groupChange; const { updates } = groupChange;
const { aboutMe, timestamp } = options; const { aboutMe, timestamp, author } = options;
const logId = `fromGroupUpdateMessage${timestamp}`; const logId = `fromGroupUpdateMessage${timestamp}`;
const details: Array<GroupV2ChangeDetailType> = []; const details: Array<GroupV2ChangeDetailType> = [];
@ -3090,9 +3100,13 @@ export class BackupImportStream extends Writable {
if (update.groupExpirationTimerUpdate) { if (update.groupExpirationTimerUpdate) {
const { updaterAci, expiresInMs } = update.groupExpirationTimerUpdate; const { updaterAci, expiresInMs } = update.groupExpirationTimerUpdate;
let sourceServiceId: AciString | undefined; let sourceServiceId: AciString | undefined;
let source = author?.e164;
if (Bytes.isNotEmpty(updaterAci)) { if (Bytes.isNotEmpty(updaterAci)) {
sourceServiceId = fromAciObject(Aci.fromUuidBytes(updaterAci)); sourceServiceId = fromAciObject(Aci.fromUuidBytes(updaterAci));
if (sourceServiceId !== author?.serviceId) {
source = undefined;
}
} }
const expireTimer = expiresInMs const expireTimer = expiresInMs
@ -3101,6 +3115,7 @@ export class BackupImportStream extends Writable {
additionalMessages.push({ additionalMessages.push({
type: 'timer-notification', type: 'timer-notification',
sourceServiceId, sourceServiceId,
source,
flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE, flags: SignalService.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
expirationTimerUpdate: { expirationTimerUpdate: {
expireTimer, expireTimer,

View file

@ -7,6 +7,7 @@ import type { ConversationColorType } from '../../types/Colors';
export type AboutMe = { export type AboutMe = {
aci: AciString; aci: AciString;
pni?: PniString; pni?: PniString;
e164?: string;
}; };
export enum BackupType { export enum BackupType {

View file

@ -16,7 +16,7 @@ export function getSenderIdentifier({
const conversation = window.ConversationController.lookupOrCreate({ const conversation = window.ConversationController.lookupOrCreate({
e164: source, e164: source,
serviceId: sourceServiceId, serviceId: sourceServiceId,
reason: 'MessageModel.getSenderIdentifier', reason: `MessageModel.getSenderIdentifier(${sentAt})`,
})!; })!;
return `${conversation?.id}.${sourceDevice}-${sentAt}`; return `${conversation?.id}.${sourceDevice}-${sentAt}`;