Jump to content

Solutions for user notifications on front-end


burning
 Share

Recommended Posts

Hi all,

Im currently building a photo sharing website and have a first version finished. Next step is to incorporate notifications in the website if a user likes one of your photo's, or comments on a photo you posted.

Just like the notification bell at the top of the forums. Any idea how to approach this functionality?

Thanks in advance.

Link to comment
Share on other sites

  • Send AJAX requests to poll the server for updates. Easy to implement but puts strain on the server. 
  • Use long polling (reply to a request only when there's an update on the server). A bit more difficult, but fewer unnecessary requests. 
  • Use websockets (Socket.io, Pushy for push notifications) or SSR (server sent events). Ideal, but a bit more involved to implement.
  • Like 2
Link to comment
Share on other sites

You'd have to represent each reaction (e.g. seen, read) using a Page with a user (Page Reference) and a timestamp field (using `created` may suffice) and relate it to an action (e.g. X posted a new picture).

Using simple image fields for storing images probably wouldn't be enough. Because images now have to hold a lot more data than they were designed for (when was this image posted, who reacted to it, what was the reaction). You'd need a more complex data structure (using Pages and fields, or custom fieldtypes) to represent all actions, reactions and events.

In short: it's not trivial. Or I'm making this complicated in my head.

  • Like 1
Link to comment
Share on other sites

3 minutes ago, abdus said:

In short: it's not trivial. Or I'm making this complicated in my head.

Absolutely right, it's not trivial and it can very quickly become properly complicated.  @abdus has very quickly pretty much nailed my current thinking on this kind of functionality.

I'm currently working on just such a system (with the added extra of location-aware messages), but by breaking it down into manageable bits (I'm hoping) it becomes feasible. 

Link to comment
Share on other sites

Thanks.

I already have a sort of page structure with images and users. So when a user likes a image, the image id is stored in a field in the user template so i can keep track on which user likes which image. The image itself is a page containing data of the image (title, description, exif data of the image, user_id who added the image, etc).

Of course I can add the user_ids to a field to the image page itself, but that doesn't keep track if the user of which the image belongs to has 'seen' the notification.

 

Link to comment
Share on other sites

I *think* you could replace the field in the user template (a user is a page, right?) with a repeater or a PageTable (best bet) and use this to store references to 'reactions'. These being pages, could then contain fields for image/page id, kind of reaction (like/share whatever), and that the image poster has been notified of that reaction.

Link to comment
Share on other sites

  • 6 months later...
On 19.10.2017 at 1:21 PM, burning said:

Ah that indeed would be a good start i guess. Thanks for your replies. I will make a start of the functionality tonight and keep u updated with the progress :-) 

How did you do it in the end?

I'm thinking about how to implement such a feature as well. But instead of additional fields I'm thinking to save some variables in the user session and compare them with the actual data.

I have to do some more research to see if that really is an option.

Link to comment
Share on other sites

  • 1 month later...
On 4/27/2018 at 7:46 PM, Schwab said:

How did you do it in the end?

I'm thinking about how to implement such a feature as well. But instead of additional fields I'm thinking to save some variables in the user session and compare them with the actual data.

I have to do some more research to see if that really is an option.

I ended up having a repeater in each userPage, when someone likes a photo, a Ajax request is sent and adding an item to the repeater, storing userId and the action (eg. like, follow comment oid). Then i built a simple notification window, which reads the repeater in the user-specific page and displays the correct message.

Link to comment
Share on other sites

On 6/16/2018 at 2:12 PM, burning said:

I ended up having a repeater in each userPage, when someone likes a photo, a Ajax request is sent and adding an item to the repeater, storing userId and the action (eg. like, follow comment oid). Then i built a simple notification window, which reads the repeater in the user-specific page and displays the correct message.

Yes I see. It depends on what notifications you want to have and who you want to notify.

I ultimately made it with an additional field on the page the user created. That field stores a MD5 Hash of the page content. When there is a change in the content, the hash changes. On the users dashboard I compare the page hash with the saved hash, if they differ, the user gets notified. When the user loads the page, his hash gets updated. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...