so i'm testing a chat app feature that i'm making and i'm trying to chat between two accounds on different devices connected to the local development server but i have to refresh to see a new message that i type on my other device
here is my realtime subscription snippet
let unsubscribe;
const setupRealtimeConnection = () => {
return client.subscribe(
[
databases.${import.meta.env.VITE_DATABASE_COMMUNITIES_ID}.collections.${
import.meta.env.VITE_COLLECTION_ID_SERVER_MESSAGES
}.documents
],
(response) => {
const { events, payload } = response;
console.log(response);
scrollToBottom();
if (payload.communityId !== id) return;
if (events.includes('databases.*.collections.*.documents.create')) {
messages.update((msgs) => {
return [...msgs, payload].sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
});
}
}
);
};
onMount(async () => {
await listCommunities();
unsubscribe = setupRealtimeConnection();
scrollToBottom(); // Ensure scrolling is handled properly
getData(); // Fetch initial data
});
onDestroy(() => {
if (unsubscribe) unsubscribe(); // Clean up the subscription on component destroy
});
Recommended threads
- I'm experiencing a critical bug on Appwr...
Hey <@870607367597850624> team / support π I'm experiencing a critical bug on Appwrite Cloud that's blocking my production Flutter app. I've already filed GitH...
- Bug: TOTP MFA verification always fails ...
*Bug: TOTP MFA verify always returns `user_invalid_token` (Cloud 1.8.1, Frankfurt)** Project ID: `68dd48440003e537d849` SDK: `appwrite@18.2.0` (also tested wit...
- SSL Certificate Issuance Failed
When we first deployed our site using appwrite and a custom domain everything was working, but it seems like the SSL certificate never got renewed. I tried dele...