TwendyKirn
TwendyKirn•11mo ago

How to implement new message arrival in the channel

Hello, thank you so much for the platform! I have a question regarding channels app (similar to Telegram). We need to show a generic read/unread logic for our channels when new post is published. But Im not sure what the best practice with Convex would look like. Currently we are saving each channel follower as separate document with isNewMessage param. But I assume that we would hit the limits if for example 20k channel gonna publish a post and then we gonna need to go through each follower and update that param. Also its unclear how to update all of them at once if we wouldnt have a limit because it seems like you need ID of each document before patch. Which means that firstly we gonna need to read all documents for this channel then loop through all of them and try to patch. Would really love to hear a possible solution! Thank you for your time and support! 🙂
3 Replies
erquhart
erquhart•11mo ago
One approach that I think is pretty common is to use a last read timestamp for each follower. Then you only ever update the last read time when the user is online and interacting, and you never have to mass update them. Every message newer than the last read timestamp is new.
TwendyKirn
TwendyKirnOP•11mo ago
Hey, thank you! Gonna try to implement it! 🙂
erquhart
erquhart•11mo ago
Feel free to follow up here as needed, will be a helpful thread for others in the future.

Did you find this page helpful?