Keep track of read/unread User Messages with a MessageClicks table?

I'm trying to implement a simple Inbox system for users of my app so that can send basic messages to each other - just like in many forum systems.

If User has_many :messages, how do I keep track of and notify the User of messages unread since last time they were read?

I'm thinking clicks on the link to the Messages screen need to be recorded in a separate table (MessagesClicks).

Is that the best approach here?

So then I check the MessagesClicks table to see if any new messages have arrived since the last time that link was clicked - based on a last_clicked or updated_at field.

13.10.2009 16:01:13
1 ОТВЕТ
РЕШЕНИЕ

I would keep track of when a message was read on the message itself with the default value of null.

If the user has any Messages with a dateRead value of null then they have unread messages.

When you display a message to the user on the Messages screen, update the dateRead property of the message from null to now.

6
13.10.2009 16:14:09
@user730569 in this case you could add a reference table that contains user_id and message_id (and maybe timestamps or other interesting information) and store that information there.
tosh 14.06.2012 12:50:54
It won't work for conversations having multiple participants. For that you will have to make another association model, say, ReadReceipt
Sachin 7.02.2017 07:29:18