Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fixed reaction to deleted message bug #961

Merged
merged 10 commits into from
Jan 25, 2025
8 changes: 7 additions & 1 deletion convex/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ export const deleteMessage = mutation({
const parsedMessageId = ctx.table("messages").normalizeId(args.messageId);

if (!parsedMessageId) {
throw new ConvexError("chatId was invalid");
throw new ConvexError("messageId was invalid");
}

const messageReactions = await ctx.table("reactions", "messageId", (q) =>
q.eq("messageId", parsedMessageId),
);

await Promise.all(messageReactions.map((reaction) => reaction.delete()));

const message = await ctx.table("messages").getX(parsedMessageId);

if ((await message.edge("user")).clerkId !== identity.tokenIdentifier) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export const Message = ({
api.messages.getMessages,
{ chatId },
existingMessages.map((message) =>
message._id === messageId ? { ...message, deleted: true } : message,
message._id === messageId
? { ...message, deleted: true, reactions: [] }
: message,
),
);

Expand Down
Loading