diff --git a/convex/users.ts b/convex/users.ts index c018b8b..64e8400 100644 --- a/convex/users.ts +++ b/convex/users.ts @@ -103,4 +103,26 @@ export const getMe = query({ }, }); -// TODO: add getGroupMembers query -- later +export const getGroupMembers = query({ + args: { conversationId: v.id("conversations") }, + handler: async (ctx, args) => { + const identity = await ctx.auth.getUserIdentity(); + + if (!identity) { + throw new ConvexError("Unauthorized"); + } + + const conversation = await ctx.db + .query("conversations") + .filter((q) => q.eq(q.field("_id"), args.conversationId)) + .first(); + if (!conversation) { + throw new ConvexError("Conversation not found"); + } + + const users = await ctx.db.query("users").collect(); + const groupMembers = users.filter((user) => conversation.participants.includes(user._id)); + + return groupMembers; + }, +}); diff --git a/package-lock.json b/package-lock.json index ae83500..4e82962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,8 @@ "react-hot-toast": "^2.4.1", "svix": "^1.21.0", "tailwind-merge": "^2.2.2", - "tailwindcss-animate": "^1.0.7" + "tailwindcss-animate": "^1.0.7", + "zustand": "^4.5.2" }, "devDependencies": { "@types/node": "^20", @@ -6791,6 +6792,33 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zustand": { + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz", + "integrity": "sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==", + "dependencies": { + "use-sync-external-store": "1.2.0" + }, + "engines": { + "node": ">=12.7.0" + }, + "peerDependencies": { + "@types/react": ">=16.8", + "immer": ">=9.0.6", + "react": ">=16.8" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + } + } } } } diff --git a/package.json b/package.json index bcdc7ea..dffc153 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "react-hot-toast": "^2.4.1", "svix": "^1.21.0", "tailwind-merge": "^2.2.2", - "tailwindcss-animate": "^1.0.7" + "tailwindcss-animate": "^1.0.7", + "zustand": "^4.5.2" }, "devDependencies": { "@types/node": "^20", diff --git a/src/components/home/conversation.tsx b/src/components/home/conversation.tsx index 148cac2..5d18454 100644 --- a/src/components/home/conversation.tsx +++ b/src/components/home/conversation.tsx @@ -4,6 +4,7 @@ import { MessageSeenSvg } from "@/lib/svgs"; import { ImageIcon, Users, VideoIcon } from "lucide-react"; import { useQuery } from "convex/react"; import { api } from "../../../convex/_generated/api"; +import { useConversationStore } from "@/store/chat-store"; const Conversation = ({ conversation }: { conversation: any }) => { const conversationImage = conversation.groupImage || conversation.image; @@ -11,11 +12,18 @@ const Conversation = ({ conversation }: { conversation: any }) => { const lastMessage = conversation.lastMessage; const lastMessageType = lastMessage?.messageType; const me = useQuery(api.users.getMe); - // + + const { setSelectedConversation, selectedConversation } = useConversationStore(); + const activeBgClass = selectedConversation?._id === conversation._id; return ( <> -