Skip to content

Commit 5d931b3

Browse files
committed
fix: avoid edited label for failed messages
1 parent 6db76b8 commit 5d931b3

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

package/src/__tests__/offline-support/optimistic-update.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { getTestClientWithUser } from '../../mock-builders/mock';
2626
import { upsertChannels } from '../../store/apis';
2727
import { SqliteClient } from '../../store/SqliteClient';
2828
import { BetterSqlite } from '../../test-utils/BetterSqlite';
29+
import { MessageStatusTypes } from '../../utils/utils';
2930

3031
test('Workaround to allow exporting tests', () => expect(true).toBe(true));
3132

@@ -509,6 +510,53 @@ export const OptimisticUpdates = () => {
509510
});
510511
});
511512

513+
it('should not set message_text_updated_at during optimistic edit of a failed message', async () => {
514+
const message = channel.state.messages[0];
515+
const optimisticStateSpy = jest.fn();
516+
517+
render(
518+
<Chat client={chatClient} enableOfflineSupport>
519+
<Channel
520+
channel={channel}
521+
doUpdateMessageRequest={() => {
522+
const optimisticMessage = channel.state.findMessage(message.id);
523+
optimisticStateSpy(optimisticMessage);
524+
525+
return {
526+
message: {
527+
...optimisticMessage,
528+
},
529+
};
530+
}}
531+
>
532+
<CallbackEffectWithContext
533+
callback={async ({ editMessage }) => {
534+
await editMessage({
535+
localMessage: {
536+
...message,
537+
cid: channel.cid,
538+
status: MessageStatusTypes.FAILED,
539+
text: 'edited failed message',
540+
},
541+
options: {},
542+
});
543+
}}
544+
context={MessageInputContext}
545+
>
546+
<View testID='children' />
547+
</CallbackEffectWithContext>
548+
</Channel>
549+
</Chat>,
550+
);
551+
552+
await waitFor(() => expect(screen.getByTestId('children')).toBeTruthy());
553+
554+
await waitFor(() => {
555+
expect(optimisticStateSpy).toHaveBeenCalled();
556+
expect(optimisticStateSpy.mock.calls[0][0].message_text_updated_at).toBeUndefined();
557+
});
558+
});
559+
512560
it('should keep the optimistic edit for attachment updates without auto-queueing', async () => {
513561
const message = channel.state.messages[0];
514562
const editedText = 'edited attachment message';

package/src/components/Channel/Channel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,13 +1567,16 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15671567

15681568
const cid = channel.cid;
15691569
const currentMessage = channel.state.findMessage(localMessage.id, localMessage.parent_id);
1570+
const isFailedMessage =
1571+
currentMessage?.status === MessageStatusTypes.FAILED ||
1572+
localMessage.status === MessageStatusTypes.FAILED;
15701573
const optimisticEditedAt = new Date();
15711574
const optimisticEditedAtString = optimisticEditedAt.toISOString();
15721575
const optimisticMessage = {
15731576
...currentMessage,
15741577
...localMessage,
15751578
cid,
1576-
message_text_updated_at: optimisticEditedAtString,
1579+
message_text_updated_at: isFailedMessage ? undefined : optimisticEditedAtString,
15771580
updated_at: optimisticEditedAt,
15781581
} as unknown as LocalMessage;
15791582

package/src/store/apis/updatePendingTask.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { SqliteClient } from '../SqliteClient';
66

77
export const updatePendingTask = async ({ id, task }: DBUpdatePendingTaskType) => {
88
const storableTask = mapTaskToStorable(task);
9+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
910
const { createdAt, id: taskId, ...nextTask } = storableTask;
10-
void createdAt;
11-
void taskId;
1211

1312
const query = createUpdateQuery('pendingTasks', nextTask, {
1413
id,

0 commit comments

Comments
 (0)