I am trying to create a group notification system. If I am in a group, then anyone who comment on the group's wall, a notification will send out to every group member. Here is my database design: I have two tables: Notification
and NotificationRead
.
NotificationRead
+userId (String)
+lastRead (int) - default is 0
Notification
...
+time(int)
...
Every user has one entry in NotificationRead
, it keep track of when is the last time I read my notification.
The logic is: for a particular user, if Notification.time > NotificationRead.lastRead
, then that notification is considered unread. Let say that in group A
, there are 4 notifications I have not read, and their time
is 7, 8, 9, 10
, then when I click onto group A
, I set my NotificationRead.lastRead = 10
(the largest time), so I wont read them again. New notifications will have their time start at 11. Now, here is my problem. Let say I have 3 groups, A, B and C
A (4): largest time is 10
B (1): largest time is 14
C (1): largest time is 12
if I click onto A, my NotificationRead.lastRead = 10
, the 4
next to A clear off, 1
next to B and C stay put. Now if I click on B, my lastRead
now is 14, so not only it clear off the 1
next to B but also the 1
next to C since 14 > 12
. Can anyone help me think of a way to solve this. I am open to completely redesign everything