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

狂风中的少年 提交于 2020-01-01 12:35:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!