Good morning ! I come to you because I encounter a problem.
For fun, I'm developing a chat application, with "groups" made up of several users.
You can send messages in these groups.
I use Appwrite's "Teams" feature to manage groups and Appwrite's "Databases" feature to manage group messages.
Now I want to implement a system to know the number of unread messages. But I don't know how to do it without a complementary system like RabbitMQ, Memphis with their ACK systems.
Do you have any ideas to suggest to me? Thank you so much !
You want to display on read message per user in a given group?
Yes ^^
In the future with the adding of aggregation functions like count and sum, it will just one step. As of now what you'll need to fetch the data even that you just want to count it.
The process should be something like this. In the client device you should create table that holds each chat last read message ID, then you can run listDocuments
where you search all message in the group after that ID.
If it's realtime then you can increase the counter each time a new message was receive in that group.
p.s. You can also set the last read ID in another collection, but for most of the time the local will be sufficient.
I think not storing anything on the client side due to lack of persistence & cross-platform. On the other hand, as you specify, in another collection, I can store the last id of the message read, it's a good idea ^^ Thanks !
👍
In case of cross platform then yes client side won't be the right way
I'm curious to know how aggreatation can work, I don't really understand ^^ Could you give me a little detail if possible? :D
Using aggregation like count will be much more efficient when counting those message. so instead of running listDocuments
and count the results, (and paginiate if needed) you'll be able to something like so
let counter = databases.count(
"[DATABASE_ID]"
"[COLLECTION_ID]",
[
Query.equal('group', 'group_id'),
Query.greaterThan("$id", lastReadID)
]
);
This would be much more faster
Oh okay I see! I understand better now, thank you :)
Recommended threads
- Seed db
hello there... is this correct way to seed appwrite
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...