Foressi
Foressi
CCConvex Community
Created by Foressi on 12/16/2024 in #support-community
About receiving useQuery events
I have a question about useQuery. (This is a translation, so the wording may be awkward). I'm developing a chat room. I'll give you an example to help you understand. I've created the following getMessages function to query messages per chat room. export const getMessages = query({ args: { roomId: v.id(“rooms”) }, handler: async (ctx, args) => { return await ctx.db .query(“messages”) .filter(q => q.eq(q.field(“roomId”), args.roomId)) .collect(); } }); When a new message is inserted in a chat room with roomId A, users who are in chat room A will receive a newMessage event and see the new message. Users in the chat room with roomId B should not see the new message, but the logs in the convex dashboard show that users in room B are also receiving getMessages events, meaning that as many getMessages logs are being generated as users who are currently viewing the chat screen, regardless of roomId. In this case, we are receiving as many events as there are users in the chat room, is this normal behavior? Or am I making a mistake or missing something in my code? I want to make sure that I only receive events that match the roomId.
13 replies