Back

Message app

  • 0
  • Teams
  • Web
  • Databases
  • Accounts
  • Users
XaFigg
13 Sep, 2023, 12:10

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 !

TL;DR
The user is developing a chat application using Appwrite's "Teams" and "Databases" features. They want to implement a system to count unread messages without using a complementary system like RabbitMQ or Memphis. They received a suggestion to use aggregation functions like count to make it more efficient. Storing the last read message ID in a separate collection or on the client device is recommended. No solution was provided for real-time message updates.
Binyamin
13 Sep, 2023, 13:13

You want to display on read message per user in a given group?

XaFigg
13 Sep, 2023, 13:21

Yes ^^

Binyamin
13 Sep, 2023, 13:29

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.

XaFigg
13 Sep, 2023, 17:05

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 !

Binyamin
13 Sep, 2023, 17:05

👍

Binyamin
13 Sep, 2023, 17:05

In case of cross platform then yes client side won't be the right way

XaFigg
13 Sep, 2023, 17:07

I'm curious to know how aggreatation can work, I don't really understand ^^ Could you give me a little detail if possible? :D

Binyamin
13 Sep, 2023, 17:11

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

TypeScript
let counter = databases.count(
    "[DATABASE_ID]"
    "[COLLECTION_ID]",
    [
        Query.equal('group', 'group_id'),
        Query.greaterThan("$id", lastReadID)    
    ]
);

This would be much more faster

XaFigg
13 Sep, 2023, 18:46

Oh okay I see! I understand better now, thank you :)

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more