【发布时间】:2022-12-27 20:06:42
【问题描述】:
I have a simple chat messaging system where users can send one-on-one messages to each other. It uses SignalR to send chat messages, and then the messages are stored in a database in this format:
SenderId | RecipientId | Message | SentDateTime | RecipientHasRead
Currently, when a userA sends a message to userB, the SignalR service immediately sends a push notification to userB at the same time as saving the message to the datbase.
UserB can then get overloaded with lots of notification. I need some way to batch the notifications.
For example, currently User B will get the following notifications:
10:00am: User A has sent you a new message 10:01am: User A has sent you a new message 10:01am: User A has sent you a new message 10:01am: User C has sent you a new message
I would prefer that User B will get something like this:
10:01am: You have 4 unread messages
What are some techniques to implement this? Should I just run a job every 5 minutes to check un-read messages for a given user in the past 5 mins and send that out?
【问题讨论】:
-
It sounds like you are sending a message to the user that they have X unread messages every time they get a message. Rather than sending a message, why not have a counter that just increments and displays how many messages they have. That could be updated whenever a message is sent and counting the messages in the table.
标签: push-notification notifications signalr