const channel = supabase
.channel("notifications")
// New messages
.on(
"postgres_changes",
{ event: "INSERT", schema: "public", table: "messages" },
(payload) => {
const msg = payload.new as {
conversation_id: string;
sender_id: string;
};
console.log(msg, " new message");
if (msg.sender_id === user.id) return;
setUnreadConversations((prev) => {
const next = new Set(prev);
next.add(msg.conversation_id);
return next;
});
queryClient.invalidateQueries({ queryKey: ["conversations"] });
}
)
const channel = supabase
.channel("notifications")
// New messages
.on(
"postgres_changes",
{ event: "INSERT", schema: "public", table: "messages" },
(payload) => {
const msg = payload.new as {
conversation_id: string;
sender_id: string;
};
console.log(msg, " new message");
if (msg.sender_id === user.id) return;
setUnreadConversations((prev) => {
const next = new Set(prev);
next.add(msg.conversation_id);
return next;
});
queryClient.invalidateQueries({ queryKey: ["conversations"] });
}
)