feat: Implement core Discord clone functionality including Convex backend, Electron frontend, and UI components for chat, voice, and settings.
This commit is contained in:
61
convex/reactions.ts
Normal file
61
convex/reactions.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { mutation } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
|
||||
// Add reaction (upsert - no duplicates)
|
||||
export const add = mutation({
|
||||
args: {
|
||||
messageId: v.id("messages"),
|
||||
userId: v.id("userProfiles"),
|
||||
emoji: v.string(),
|
||||
},
|
||||
returns: v.null(),
|
||||
handler: async (ctx, args) => {
|
||||
// Check if already exists
|
||||
const existing = await ctx.db
|
||||
.query("messageReactions")
|
||||
.withIndex("by_message_user_emoji", (q) =>
|
||||
q
|
||||
.eq("messageId", args.messageId)
|
||||
.eq("userId", args.userId)
|
||||
.eq("emoji", args.emoji)
|
||||
)
|
||||
.unique();
|
||||
|
||||
if (!existing) {
|
||||
await ctx.db.insert("messageReactions", {
|
||||
messageId: args.messageId,
|
||||
userId: args.userId,
|
||||
emoji: args.emoji,
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
// Remove reaction
|
||||
export const remove = mutation({
|
||||
args: {
|
||||
messageId: v.id("messages"),
|
||||
userId: v.id("userProfiles"),
|
||||
emoji: v.string(),
|
||||
},
|
||||
returns: v.null(),
|
||||
handler: async (ctx, args) => {
|
||||
const existing = await ctx.db
|
||||
.query("messageReactions")
|
||||
.withIndex("by_message_user_emoji", (q) =>
|
||||
q
|
||||
.eq("messageId", args.messageId)
|
||||
.eq("userId", args.userId)
|
||||
.eq("emoji", args.emoji)
|
||||
)
|
||||
.unique();
|
||||
|
||||
if (existing) {
|
||||
await ctx.db.delete(existing._id);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user