Fix reaction field name in migration 88
This commit is contained in:
parent
8aa397b7a6
commit
e05de1aa6f
7 changed files with 25 additions and 30 deletions
|
@ -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,
|
||||
|
|
1
ts/model-types.d.ts
vendored
1
ts/model-types.d.ts
vendored
|
@ -111,7 +111,6 @@ export type GroupV1Update = {
|
|||
export type MessageReactionType = {
|
||||
emoji: undefined | string;
|
||||
fromId: string;
|
||||
targetAuthorAci: AciString;
|
||||
targetTimestamp: number;
|
||||
timestamp: number;
|
||||
isSentByConversationId?: Record<string, boolean>;
|
||||
|
|
|
@ -2967,7 +2967,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const newReaction: MessageReactionType = {
|
||||
emoji: reaction.remove ? undefined : reaction.emoji,
|
||||
fromId: reaction.fromId,
|
||||
targetAuthorAci: reaction.targetAuthorAci,
|
||||
targetTimestamp: reaction.targetTimestamp,
|
||||
timestamp: reaction.timestamp,
|
||||
isSentByConversationId: isFromThisDevice
|
||||
|
|
|
@ -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<Record<string, unknown>>;
|
||||
|
||||
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<{
|
||||
|
|
|
@ -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 } } : {}),
|
||||
|
|
|
@ -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(),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue