diff --git a/ts/jobs/helpers/sendReaction.ts b/ts/jobs/helpers/sendReaction.ts index 942c023bd7b0..0d5adb6a80cf 100644 --- a/ts/jobs/helpers/sendReaction.ts +++ b/ts/jobs/helpers/sendReaction.ts @@ -15,6 +15,7 @@ import type { ConversationModel } from '../../models/conversations'; import * as reactionUtil from '../../reactions/util'; import { isSent, SendStatus } from '../../messages/MessageSendState'; import { getMessageById } from '../../messages/getMessageById'; +import { isIncoming } from '../../messages/helpers'; import { isMe, isDirectConversation, @@ -26,7 +27,8 @@ import { handleMessageSend } from '../../util/handleMessageSend'; import { ourProfileKeyService } from '../../services/ourProfileKey'; import { canReact, isStory } from '../../state/selectors/message'; import { findAndFormatContact } from '../../util/findAndFormatContact'; -import type { ServiceIdString } from '../../types/ServiceId'; +import type { AciString, ServiceIdString } from '../../types/ServiceId'; +import { isAciString } from '../../types/ServiceId'; import { handleMultipleSendErrors } from './handleMultipleSendErrors'; import { incrementMessageCounter } from '../../util/incrementMessageCounter'; @@ -136,8 +138,18 @@ export async function sendReaction( ? await ourProfileKeyService.get() : undefined; - const { emoji, targetAuthorAci, ...restOfPendingReaction } = - pendingReaction; + const { emoji, ...restOfPendingReaction } = pendingReaction; + + let targetAuthorAci: AciString; + if (isIncoming(message.attributes)) { + strictAssert( + isAciString(message.attributes.sourceServiceId), + 'incoming message does not have sender ACI' + ); + ({ sourceServiceId: targetAuthorAci } = message.attributes); + } else { + targetAuthorAci = ourAci; + } const reactionForSend = { ...restOfPendingReaction, diff --git a/ts/model-types.d.ts b/ts/model-types.d.ts index c0867f34af0f..fc3c34117d9c 100644 --- a/ts/model-types.d.ts +++ b/ts/model-types.d.ts @@ -111,7 +111,6 @@ export type GroupV1Update = { export type MessageReactionType = { emoji: undefined | string; fromId: string; - targetAuthorAci: AciString; targetTimestamp: number; timestamp: number; isSentByConversationId?: Record; diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 4cbf148ab156..021c2ecc653d 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -2967,7 +2967,6 @@ export class MessageModel extends window.Backbone.Model { const newReaction: MessageReactionType = { emoji: reaction.remove ? undefined : reaction.emoji, fromId: reaction.fromId, - targetAuthorAci: reaction.targetAuthorAci, targetTimestamp: reaction.targetTimestamp, timestamp: reaction.timestamp, isSentByConversationId: isFromThisDevice diff --git a/ts/sql/migrations/88-service-ids.ts b/ts/sql/migrations/88-service-ids.ts index 5cba44197400..6bf60da40297 100644 --- a/ts/sql/migrations/88-service-ids.ts +++ b/ts/sql/migrations/88-service-ids.ts @@ -799,11 +799,9 @@ function migrateMessages(db: Database, logger: LoggerType): void { ), } : undefined, - reactions: reactions?.map(r => - migrateReaction(r, 'reactions', logger) - ), + reactions: reactions?.map(r => migrateReaction(r)), storyReaction: storyReaction - ? migrateReaction(storyReaction, 'storyReaction', logger) + ? migrateReaction(storyReaction) : undefined, storyReplyContext: storyReplyContext ? { @@ -1231,22 +1229,13 @@ function migrateBodyRanges( } type LegacyReaction = JSONWithUnknownFields<{ - authorUuid?: string; + targetAuthorUuid?: string; }>; -type UpdatedReaction = JSONWithUnknownFields<{ - authorAci: AciString | undefined; -}>; +type UpdatedReaction = JSONWithUnknownFields>; -function migrateReaction( - { authorUuid, ...legacy }: LegacyReaction, - context: string, - logger: LoggerType -): UpdatedReaction { - return { - ...legacy, - authorAci: normalizeAci(authorUuid, context, logger), - }; +function migrateReaction(legacy: LegacyReaction): UpdatedReaction { + return omit(legacy, 'targetAuthorUuid'); } type LegacyGroupChange = JSONWithUnknownFields<{ diff --git a/ts/test-both/reactions/util_test.ts b/ts/test-both/reactions/util_test.ts index e3d04beb65bc..1ef470a1df04 100644 --- a/ts/test-both/reactions/util_test.ts +++ b/ts/test-both/reactions/util_test.ts @@ -6,7 +6,6 @@ import { v4 as uuid } from 'uuid'; import { omit } from 'lodash'; import type { MessageReactionType } from '../../model-types.d'; import { isEmpty } from '../../util/iterables'; -import { generateAci } from '../../types/ServiceId'; import { addOutgoingReaction, @@ -25,7 +24,6 @@ describe('reaction utilities', () => { ): MessageReactionType => ({ emoji, fromId: OUR_CONVO_ID, - targetAuthorAci: generateAci(), targetTimestamp: Date.now(), timestamp: Date.now(), ...(isPending ? { isSentByConversationId: { [uuid()]: false } } : {}), diff --git a/ts/test-electron/state/ducks/conversations_test.ts b/ts/test-electron/state/ducks/conversations_test.ts index f2b615f5b4c3..c358832165db 100644 --- a/ts/test-electron/state/ducks/conversations_test.ts +++ b/ts/test-electron/state/ducks/conversations_test.ts @@ -1607,7 +1607,6 @@ describe('both/state/ducks/conversations', () => { fromId: 'some-other-id', timestamp: 2222, targetTimestamp: 1111, - targetAuthorAci: generateAci(), }, ], }; @@ -1638,7 +1637,6 @@ describe('both/state/ducks/conversations', () => { fromId: 'some-other-id', timestamp: 2222, targetTimestamp: 1111, - targetAuthorAci: generateAci(), }, ], }, diff --git a/ts/test-node/sql/migration_88_test.ts b/ts/test-node/sql/migration_88_test.ts index b0e0a07db64c..df6d6ba48d7d 100644 --- a/ts/test-node/sql/migration_88_test.ts +++ b/ts/test-node/sql/migration_88_test.ts @@ -247,8 +247,8 @@ describe('SQL/updateToSchemaVersion88', () => { expirationTimerUpdate: { sourceUuid: THEIR_UUID, }, - reactions: [{ authorUuid: THEIR_UUID }], - storyReaction: { authorUuid: THEIR_UUID }, + reactions: [{ targetAuthorUuid: THEIR_UUID }], + storyReaction: { targetAuthorUuid: THEIR_UUID }, storyReplyContext: { authorUuid: THEIR_UUID, }, @@ -290,8 +290,8 @@ describe('SQL/updateToSchemaVersion88', () => { expirationTimerUpdate: { sourceServiceId: THEIR_UUID, }, - reactions: [{ authorAci: THEIR_UUID }], - storyReaction: { authorAci: THEIR_UUID }, + reactions: [{}], + storyReaction: {}, storyReplyContext: { authorAci: THEIR_UUID, },