hello there is a website

any users have the opportunity to add news to your page, there is an opportunity to subscribe and like

The subscription database structure is as follows: there is a user_subscr table in it: user ID, and user ID to which the previous ID is subscribed

DB structure of likes: a table from user’s id

How about a small notification system can be implemented? like "User has subscribed to you", "news from iDi 123 liked 10 people" and so on

    1 answer 1

    You can connect browser push notifications , for example: https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web
    Or a web service like: https://sendpulse.com

    And if you want to organize live notifications on the site , then the decision here depends on whether you are hosting the project or on the server.

    For example, if on the server, you can use this solution, without third-party web services: https://github.com/centrifugal/centrifugo

    And if on a hosting, then you better choose one of the web services. For example: https://pusher.com/

    Regarding the internal implementation in the project, create a events table with fields:

    • ID - event id
    • resource_type - the name of the resource table to which the notification relates (news, likes, etc.)
    • resource_id - resource ID
    • initiator_id - ID of the user who caused the event
    • timestamp - event timestamp

    Next, when initiating an event, use one of the above solutions, choosing the one that suits you best.

    And then it's up to the implementation of logic.

    For example, to implement notifications such as “User has subscribed to you”, it is enough to make a push notification when this event is initiated.

    "news from iDi 123 like 10 people" - set the condition that with every Like or Schedule (use cron, if possible) check the bundle of events in the events table by the grouping of the fields: resource_type , resource_id . If you have typed, for example, 10 new likes, then send a push-notification.

    Accordingly, you will need a JS listener for the frontend. But, I think you should have no problems with the implementation here. Use WebSocket. https://learn.javascript.ru/websockets