问题
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.
回答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.
来源:https://stackoverflow.com/questions/1561199/keep-track-of-read-unread-user-messages-with-a-messageclicks-table