
Hello Appwrite community! I have a "chores" app. When User A adds a chore to a shared list, I want it to appear instantly on User B's screen without them needing to refresh. Real-time updates are not being received by other users. However, if I manually refresh the screen, the new chore appears correctly, which proves that the basic database read permissions are working. If I set the chores collection's read permission to Any or Guests, the real-time updates work perfectly. As soon as I restrict it to authenticated users (Users), the real-time events stop, even though the users are logged in and can fetch the data when refreshing. I'm trying to follow the simple pattern used in many working chat apps.
- Flutter Client (chore_state_notifier.dart) - Subscribing
My Flutter app subscribes directly to the chores collection. `// lib/features/chores/presentation/providers/chore_state_notifier.dart
void _subscribeToChoreUpdates() { final realtime = _ref.read(appwriteRealtimeProvider); final databaseId = AppwriteConstants.databaseId; final collectionId = AppwriteConstants.choresCollectionId;
// Subscribing directly to the chores collection
final channel = 'databases.$databaseId.collections.$collectionId.documents';
_subscription = realtime.subscribe([channel]);
_subscription!.stream.listen((response) {
**// THIS PRINT STATEMENT NEVER APPEARS FOR OTHER USERS**
print("<<<<< DIRECT REALTIME EVENT RECEIVED: ${response.payload} >>>>>");
// ... logic to update the UI state
});
}`
Logs:
I/flutter (20357): Received heartbeat response from realtime server
I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents
I/flutter (20357): subscription: wss://fra.cloud.appwrite.io/v1/realtime?project=xxxx&channels%5B%5D=databases.xxxx.collections.chores.documents&channels%5B%5D=databases.xxxx.collections.choreLists.documents

- Appwrite Function (mergedFunction/src/main.js) - Setting Permissions
When a user creates a chore, my app calls an Appwrite function. The function's only job is to create the chore document and add a specific, individual read permission for every member of that chore list.
Function code: `case 'createChore': { const { choreData } = data; const currentUser = await account.get(); const userId = currentUser.$id; const { id = ID.unique(), description, points = 0, type = 'daily', deadline = null, lastCompletedAt = null, resetDurationInSeconds = null, choreListId, } = choreData; const userDatabases = new Databases(userClient);
const choreListDoc = await userDatabases.getDocument(
APPWRITE_DATABASE_ID,
CHORE_LISTS_COLLECTION_ID,
choreListId
);
const teamId = choreListDoc.teamId;
// 1. Get all members of the team.
const teamMemberships = await teams.listMemberships(teamId);
const members = teamMemberships.memberships;
console.log(`Found ${members.length} members in the team.`);
// 2. An array of specific read permissions for EACH member.
const memberReadPermissions = members.map(member =>
Permission.read(`user:${member.userId}`)
);
console.log(`Created ${memberReadPermissions.length} individual read permissions.`);`

` const newChore = await databases.createDocument( APPWRITE_DATABASE_ID, CHORES_COLLECTION_ID, id, { id, description, isDone: false, points, type, deadline, lastCompletedAt, resetDurationInSeconds, userId, choreListId, }, [ ...memberReadPermissions,
Permission.update(Role.team(teamId, "editor")),
Permission.update(Role.team(teamId, "owner")),
Permission.delete(Role.team(teamId, "editor")),
Permission.delete(Role.team(teamId, "owner")),
]
);
console.log(`Chore created with ID: ${newChore.$id}`);
console.log(`Final permissions on document: ${JSON.stringify(newChore.$permissions)}`);
console.log("--- Finished CreateChore ---");
return context.res.json({
ok: true,
message: 'Chore created successfully.',
choreId: newChore.$id
});
}``
Log output:
Found 2 members in the team.
Created 2 individual read permissions.
Chore created with ID: 68d574f73413bfd0e403
Final permissions on document: ["read(\"user:xxxx\")","read(\"user:xxxx\")","update(\"team:xxxx/editor\")","update(\"team:xxxx/owner\")","delete(\"team:xxxx/editor\")","delete(\"team:xxxx/owner\")"]
--- Finished CreateChore ---
Recommended threads
- Filtering Tables in Real Time
Is there a way to use real time and filter the tables with the fields? For instance, let's say i have a table that holds private messages, and in that DM table ...
- Filtering Tables in Real Time
Is there a way to use real time and filter the tables with the fields? For instance, let's say i have a table that holds private messages, and in that DM table ...
- Teams Invite issue
We are getting this error ```AppwriteException: general_unknown, Server Error (500)``` when trying run the createPhoneToken after receiving a Teams invite email...
