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 * as reactionUtil from '../../reactions/util';
|
||||||
import { isSent, SendStatus } from '../../messages/MessageSendState';
|
import { isSent, SendStatus } from '../../messages/MessageSendState';
|
||||||
import { getMessageById } from '../../messages/getMessageById';
|
import { getMessageById } from '../../messages/getMessageById';
|
||||||
|
import { isIncoming } from '../../messages/helpers';
|
||||||
import {
|
import {
|
||||||
isMe,
|
isMe,
|
||||||
isDirectConversation,
|
isDirectConversation,
|
||||||
|
@ -26,7 +27,8 @@ import { handleMessageSend } from '../../util/handleMessageSend';
|
||||||
import { ourProfileKeyService } from '../../services/ourProfileKey';
|
import { ourProfileKeyService } from '../../services/ourProfileKey';
|
||||||
import { canReact, isStory } from '../../state/selectors/message';
|
import { canReact, isStory } from '../../state/selectors/message';
|
||||||
import { findAndFormatContact } from '../../util/findAndFormatContact';
|
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 { handleMultipleSendErrors } from './handleMultipleSendErrors';
|
||||||
import { incrementMessageCounter } from '../../util/incrementMessageCounter';
|
import { incrementMessageCounter } from '../../util/incrementMessageCounter';
|
||||||
|
|
||||||
|
@ -136,8 +138,18 @@ export async function sendReaction(
|
||||||
? await ourProfileKeyService.get()
|
? await ourProfileKeyService.get()
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const { emoji, targetAuthorAci, ...restOfPendingReaction } =
|
const { emoji, ...restOfPendingReaction } = pendingReaction;
|
||||||
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 = {
|
const reactionForSend = {
|
||||||
...restOfPendingReaction,
|
...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 = {
|
export type MessageReactionType = {
|
||||||
emoji: undefined | string;
|
emoji: undefined | string;
|
||||||
fromId: string;
|
fromId: string;
|
||||||
targetAuthorAci: AciString;
|
|
||||||
targetTimestamp: number;
|
targetTimestamp: number;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
isSentByConversationId?: Record<string, boolean>;
|
isSentByConversationId?: Record<string, boolean>;
|
||||||
|
|
|
@ -2967,7 +2967,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
const newReaction: MessageReactionType = {
|
const newReaction: MessageReactionType = {
|
||||||
emoji: reaction.remove ? undefined : reaction.emoji,
|
emoji: reaction.remove ? undefined : reaction.emoji,
|
||||||
fromId: reaction.fromId,
|
fromId: reaction.fromId,
|
||||||
targetAuthorAci: reaction.targetAuthorAci,
|
|
||||||
targetTimestamp: reaction.targetTimestamp,
|
targetTimestamp: reaction.targetTimestamp,
|
||||||
timestamp: reaction.timestamp,
|
timestamp: reaction.timestamp,
|
||||||
isSentByConversationId: isFromThisDevice
|
isSentByConversationId: isFromThisDevice
|
||||||
|
|
|
@ -799,11 +799,9 @@ function migrateMessages(db: Database, logger: LoggerType): void {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
reactions: reactions?.map(r =>
|
reactions: reactions?.map(r => migrateReaction(r)),
|
||||||
migrateReaction(r, 'reactions', logger)
|
|
||||||
),
|
|
||||||
storyReaction: storyReaction
|
storyReaction: storyReaction
|
||||||
? migrateReaction(storyReaction, 'storyReaction', logger)
|
? migrateReaction(storyReaction)
|
||||||
: undefined,
|
: undefined,
|
||||||
storyReplyContext: storyReplyContext
|
storyReplyContext: storyReplyContext
|
||||||
? {
|
? {
|
||||||
|
@ -1231,22 +1229,13 @@ function migrateBodyRanges(
|
||||||
}
|
}
|
||||||
|
|
||||||
type LegacyReaction = JSONWithUnknownFields<{
|
type LegacyReaction = JSONWithUnknownFields<{
|
||||||
authorUuid?: string;
|
targetAuthorUuid?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
type UpdatedReaction = JSONWithUnknownFields<{
|
type UpdatedReaction = JSONWithUnknownFields<Record<string, unknown>>;
|
||||||
authorAci: AciString | undefined;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
function migrateReaction(
|
function migrateReaction(legacy: LegacyReaction): UpdatedReaction {
|
||||||
{ authorUuid, ...legacy }: LegacyReaction,
|
return omit(legacy, 'targetAuthorUuid');
|
||||||
context: string,
|
|
||||||
logger: LoggerType
|
|
||||||
): UpdatedReaction {
|
|
||||||
return {
|
|
||||||
...legacy,
|
|
||||||
authorAci: normalizeAci(authorUuid, context, logger),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type LegacyGroupChange = JSONWithUnknownFields<{
|
type LegacyGroupChange = JSONWithUnknownFields<{
|
||||||
|
|
|
@ -6,7 +6,6 @@ import { v4 as uuid } from 'uuid';
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
import type { MessageReactionType } from '../../model-types.d';
|
import type { MessageReactionType } from '../../model-types.d';
|
||||||
import { isEmpty } from '../../util/iterables';
|
import { isEmpty } from '../../util/iterables';
|
||||||
import { generateAci } from '../../types/ServiceId';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addOutgoingReaction,
|
addOutgoingReaction,
|
||||||
|
@ -25,7 +24,6 @@ describe('reaction utilities', () => {
|
||||||
): MessageReactionType => ({
|
): MessageReactionType => ({
|
||||||
emoji,
|
emoji,
|
||||||
fromId: OUR_CONVO_ID,
|
fromId: OUR_CONVO_ID,
|
||||||
targetAuthorAci: generateAci(),
|
|
||||||
targetTimestamp: Date.now(),
|
targetTimestamp: Date.now(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
...(isPending ? { isSentByConversationId: { [uuid()]: false } } : {}),
|
...(isPending ? { isSentByConversationId: { [uuid()]: false } } : {}),
|
||||||
|
|
|
@ -1607,7 +1607,6 @@ describe('both/state/ducks/conversations', () => {
|
||||||
fromId: 'some-other-id',
|
fromId: 'some-other-id',
|
||||||
timestamp: 2222,
|
timestamp: 2222,
|
||||||
targetTimestamp: 1111,
|
targetTimestamp: 1111,
|
||||||
targetAuthorAci: generateAci(),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -1638,7 +1637,6 @@ describe('both/state/ducks/conversations', () => {
|
||||||
fromId: 'some-other-id',
|
fromId: 'some-other-id',
|
||||||
timestamp: 2222,
|
timestamp: 2222,
|
||||||
targetTimestamp: 1111,
|
targetTimestamp: 1111,
|
||||||
targetAuthorAci: generateAci(),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -247,8 +247,8 @@ describe('SQL/updateToSchemaVersion88', () => {
|
||||||
expirationTimerUpdate: {
|
expirationTimerUpdate: {
|
||||||
sourceUuid: THEIR_UUID,
|
sourceUuid: THEIR_UUID,
|
||||||
},
|
},
|
||||||
reactions: [{ authorUuid: THEIR_UUID }],
|
reactions: [{ targetAuthorUuid: THEIR_UUID }],
|
||||||
storyReaction: { authorUuid: THEIR_UUID },
|
storyReaction: { targetAuthorUuid: THEIR_UUID },
|
||||||
storyReplyContext: {
|
storyReplyContext: {
|
||||||
authorUuid: THEIR_UUID,
|
authorUuid: THEIR_UUID,
|
||||||
},
|
},
|
||||||
|
@ -290,8 +290,8 @@ describe('SQL/updateToSchemaVersion88', () => {
|
||||||
expirationTimerUpdate: {
|
expirationTimerUpdate: {
|
||||||
sourceServiceId: THEIR_UUID,
|
sourceServiceId: THEIR_UUID,
|
||||||
},
|
},
|
||||||
reactions: [{ authorAci: THEIR_UUID }],
|
reactions: [{}],
|
||||||
storyReaction: { authorAci: THEIR_UUID },
|
storyReaction: {},
|
||||||
storyReplyContext: {
|
storyReplyContext: {
|
||||||
authorAci: THEIR_UUID,
|
authorAci: THEIR_UUID,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue