feat: Initialize the Electron frontend with core UI components and integrate Convex backend services.
This commit is contained in:
63
convex/members.ts
Normal file
63
convex/members.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { query } from "./_generated/server";
|
||||
import { v } from "convex/values";
|
||||
|
||||
export const getChannelMembers = query({
|
||||
args: {
|
||||
channelId: v.id("channels"),
|
||||
},
|
||||
returns: v.any(),
|
||||
handler: async (ctx, args) => {
|
||||
const channelKeyDocs = await ctx.db
|
||||
.query("channelKeys")
|
||||
.withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
|
||||
.collect();
|
||||
|
||||
const seenUsers = new Set<string>();
|
||||
const members = [];
|
||||
|
||||
for (const doc of channelKeyDocs) {
|
||||
const odId = doc.userId.toString();
|
||||
if (seenUsers.has(odId)) continue;
|
||||
seenUsers.add(odId);
|
||||
|
||||
const user = await ctx.db.get(doc.userId);
|
||||
if (!user) continue;
|
||||
|
||||
const userRoleDocs = await ctx.db
|
||||
.query("userRoles")
|
||||
.withIndex("by_user", (q) => q.eq("userId", doc.userId))
|
||||
.collect();
|
||||
|
||||
const roles = [];
|
||||
for (const ur of userRoleDocs) {
|
||||
const role = await ctx.db.get(ur.roleId);
|
||||
if (role) {
|
||||
roles.push({
|
||||
id: role._id,
|
||||
name: role.name,
|
||||
color: role.color,
|
||||
position: role.position,
|
||||
isHoist: role.isHoist,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let avatarUrl: string | null = null;
|
||||
if (user.avatarStorageId) {
|
||||
avatarUrl = await ctx.storage.getUrl(user.avatarStorageId);
|
||||
}
|
||||
|
||||
members.push({
|
||||
id: user._id,
|
||||
username: user.username,
|
||||
status: user.status || "online",
|
||||
roles: roles.sort((a, b) => b.position - a.position),
|
||||
avatarUrl,
|
||||
aboutMe: user.aboutMe,
|
||||
customStatus: user.customStatus,
|
||||
});
|
||||
}
|
||||
|
||||
return members;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user