The need to add a red dot to the entry when the content is updated is common and not complicated to implement. There are many realization scenarios, such as Web end, APP end, small program end and so on. The realization ideas are almost the same with minor differences. This paper describes the complete idea to solve the problem from the two cases of login state or not.
Have a login state
Comparing the conventional approach is to have a user login mode, the user has read time entry to the background of user data information, when the content updates, update the content and the user has read time do contrast, if the user has read time earlier than content updates, at the entrance to the user prompt little red dot, says more updates unread.
1. Update data
The first step is to update the data, in addition to the regular data fields, we need to pay attention to the new update time field. In this way, the background compares the data update time with the read time when the user obtains data.
2. Obtain data
The second step is to obtain data. When obtaining data, the background will query the last read time of the user after receiving the request to determine whether the user has browsed the latest content, and thus obtain the user’s read or unread status.
If the last read time of the user is later than the last update time of the data, the user is in the unread state and the interface returns is_read: false. After receiving this field, the front end requests to set the read interface.
If the latest reading time of the user is later than the latest data update time, the user is in the read state. In this case, the content is not updated and the user is not prompted with a red dot.
No login state
When content needs to be pushed to a visitor status user, how do you know if that user has viewed the latest post?
1. Update data
Update data and login state of practice, the new update time field can be.
2. Obtain data
Obtaining data is a bit different. The data update time is still pulled from the background, while the latest reading time is obtained from the local cache localStorage of the browser. When a user enters the content page for the first time, the readTime field in localStorage is updated to indicate the readTime of the user.
When entering the content page again, compare the read time in localStorage with the data update time, and decide whether to update the read time in localStorage. In this way, you can realize the little red dot when the content is updated, and do not prompt when the content is not updated. However, because there is no login state, whether the user has read the latest content is determined by the client browser rather than by the user. This method is applicable to scenarios with weak binding.
conclusion
This article shares the content update prompt red dot solution idea, hope this article can let you know how to do the message notification – content update red dot prompt implementation process.