feat: Initialize the Electron frontend with core UI components and integrate Convex backend services.
This commit is contained in:
@@ -20,6 +20,11 @@ export const list = query({
|
||||
result.page.map(async (msg) => {
|
||||
const sender = await ctx.db.get(msg.senderId);
|
||||
|
||||
let avatarUrl: string | null = null;
|
||||
if (sender?.avatarStorageId) {
|
||||
avatarUrl = await ctx.storage.getUrl(sender.avatarStorageId);
|
||||
}
|
||||
|
||||
const reactionDocs = await ctx.db
|
||||
.query("messageReactions")
|
||||
.withIndex("by_message", (q) => q.eq("messageId", msg._id))
|
||||
@@ -34,6 +39,23 @@ export const list = query({
|
||||
}
|
||||
}
|
||||
|
||||
let replyToUsername: string | null = null;
|
||||
let replyToContent: string | null = null;
|
||||
let replyToNonce: string | null = null;
|
||||
let replyToAvatarUrl: string | null = null;
|
||||
if (msg.replyTo) {
|
||||
const repliedMsg = await ctx.db.get(msg.replyTo);
|
||||
if (repliedMsg) {
|
||||
const repliedSender = await ctx.db.get(repliedMsg.senderId);
|
||||
replyToUsername = repliedSender?.username || "Unknown";
|
||||
replyToContent = repliedMsg.ciphertext;
|
||||
replyToNonce = repliedMsg.nonce;
|
||||
if (repliedSender?.avatarStorageId) {
|
||||
replyToAvatarUrl = await ctx.storage.getUrl(repliedSender.avatarStorageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: msg._id,
|
||||
channel_id: msg.channelId,
|
||||
@@ -45,7 +67,15 @@ export const list = query({
|
||||
created_at: new Date(msg._creationTime).toISOString(),
|
||||
username: sender?.username || "Unknown",
|
||||
public_signing_key: sender?.publicSigningKey || "",
|
||||
avatarUrl,
|
||||
reactions: Object.keys(reactions).length > 0 ? reactions : null,
|
||||
replyToId: msg.replyTo || null,
|
||||
replyToUsername,
|
||||
replyToContent,
|
||||
replyToNonce,
|
||||
replyToAvatarUrl,
|
||||
editedAt: msg.editedAt || null,
|
||||
pinned: msg.pinned || false,
|
||||
};
|
||||
})
|
||||
);
|
||||
@@ -62,6 +92,7 @@ export const send = mutation({
|
||||
nonce: v.string(),
|
||||
signature: v.string(),
|
||||
keyVersion: v.number(),
|
||||
replyTo: v.optional(v.id("messages")),
|
||||
},
|
||||
returns: v.object({ id: v.id("messages") }),
|
||||
handler: async (ctx, args) => {
|
||||
@@ -72,11 +103,74 @@ export const send = mutation({
|
||||
nonce: args.nonce,
|
||||
signature: args.signature,
|
||||
keyVersion: args.keyVersion,
|
||||
replyTo: args.replyTo,
|
||||
});
|
||||
return { id };
|
||||
},
|
||||
});
|
||||
|
||||
export const edit = mutation({
|
||||
args: {
|
||||
id: v.id("messages"),
|
||||
ciphertext: v.string(),
|
||||
nonce: v.string(),
|
||||
signature: v.string(),
|
||||
},
|
||||
returns: v.null(),
|
||||
handler: async (ctx, args) => {
|
||||
await ctx.db.patch(args.id, {
|
||||
ciphertext: args.ciphertext,
|
||||
nonce: args.nonce,
|
||||
signature: args.signature,
|
||||
editedAt: Date.now(),
|
||||
});
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
export const pin = mutation({
|
||||
args: {
|
||||
id: v.id("messages"),
|
||||
pinned: v.boolean(),
|
||||
},
|
||||
returns: v.null(),
|
||||
handler: async (ctx, args) => {
|
||||
await ctx.db.patch(args.id, { pinned: args.pinned });
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
export const listPinned = query({
|
||||
args: {
|
||||
channelId: v.id("channels"),
|
||||
},
|
||||
returns: v.any(),
|
||||
handler: async (ctx, args) => {
|
||||
const allMessages = await ctx.db
|
||||
.query("messages")
|
||||
.withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
|
||||
.collect();
|
||||
|
||||
const pinned = allMessages.filter((m) => m.pinned === true);
|
||||
|
||||
return Promise.all(
|
||||
pinned.map(async (msg) => {
|
||||
const sender = await ctx.db.get(msg.senderId);
|
||||
return {
|
||||
id: msg._id,
|
||||
ciphertext: msg.ciphertext,
|
||||
nonce: msg.nonce,
|
||||
signature: msg.signature,
|
||||
key_version: msg.keyVersion,
|
||||
created_at: new Date(msg._creationTime).toISOString(),
|
||||
username: sender?.username || "Unknown",
|
||||
public_signing_key: sender?.publicSigningKey || "",
|
||||
};
|
||||
})
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const remove = mutation({
|
||||
args: { id: v.id("messages") },
|
||||
returns: v.null(),
|
||||
|
||||
Reference in New Issue
Block a user