Keep track of read / unread user messages with the MessageClicks table?

I am trying to implement a simple inbox system for users of my application to send basic messages to each other - as in many forums.

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

I think that clicks on a link to the Messages screen should be recorded in a separate table ( MessagesClicks ).

Is this the best approach here?

So, I check the MessagesClicks table to see if there are any new messages since the last click of this link - based on the last_clicked or updated_at field .

+4
source share
1 answer

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

If the user has any messages with dateRead date, 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 zero to the present.

+6
source

Source: https://habr.com/ru/post/907818/


All Articles