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
- 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...
- context deadline exceeded
Hi, in one of my projects i continuously receive context deadline exceeded when trying to reach users API from my local machine: https://fra.cloud.appwrite.io/v...
- π Realtime Flutter SDK Crash β Realtime...
**Summary** When using Appwrite Cloud with the Flutter SDK (latest appwrite release: 21.4.0), Realtime crashes with: ```Unhandled async error: type '_Map<String...