burning

Solutions for user notifications on front-end

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

intercooler.js (which I may have mentioned before :rolleyes:) has beta support for Server Sent Events. I haven't tried SSE, but I'm a big fan of intercooler generally.

  • Like 3

Share this post


Link to post
Share on other sites

Thanks for the suggestions guys.

Another question; how do i store these 'notifications' in my processwire installation, and how do i check whether they are 'read or seen' by the user, and thus delete them?

Share this post


Link to post
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

Share this post


Link to post
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. 

Share this post


Link to post
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.

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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 :-) 

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By louisstephens
      I have been using the wiresmtpmail module in a few installs for sending out automated emails etc etc, and it works flawlessly. However, I now need to send an email when a user submits a form, and for the life of me I can not figure out how to get the form to submit.
      if(isset($_POST['Submit'])) { $mail = wireMail(); // calling an empty wireMail() returns a wireMail object $toName = $sanitizer->text($input->post->fullname); $toEmail = $sanitizer->email($input->post->email); $phone = $sanitizer->text($input->post->phone); $comments = $sanitizer->text($input->post->comments); $subject = $page->store_name . $page->title; $numSent = wireMail($toName, '', $subject, $textBody, $options); } If I remove the if statement, the form submits just fine, however you can just refresh the page (without adding anything to the fields), and it will submit a blank email every refresh. Has anyone gotten this working with a submit button?
    • By modifiedcontent
      I have one central website, with membership registration and content etc., and then several related websites with their own URL/domains, each on Processwire, all on the same server.
      I would like to access the database of the central website from the sister websites. How would I do that?
      You can't bootstrap one PW installation into another. You can include template parts from one in the other by just using the server path, but whatever you try to get/post just comes/goes to the database of the site you are on.
      Could you switch databases by including the config.php from another PW installation somewhere?
      What is the correct, secure way to do this?
    • By celfred
      Hello,
      I have a feeling I'm missing an easy thing here (again...). If I trash a page from API with :
      mypage->trash()
      Is there a simple way to restore it if needed ? I can do it in back-end, but I'd like to do it through API with something like
      mypage->restore()
       but this doesn't exit  
      So if you can give me a little help on that, I'd appreciate. Thanks in advance !
    • By jrtderonde
      Hey,
      I'm working around a module that adds pages in my ProcessWire installation. The pages are added based on a JSON array that will be imported through a page save. Everything works fine except for when the pages are added. I get the following error
      Integrity constraint violation: 1062 Duplicate entry '3e215ecd6774fd99c2b0eb5cadf36a07-1269' for key 'name_parent_id' I'm using the following code/loop to generate the pages.
      // Loop through the files foreach ($p->importFile as $file) { // Set the file location $name = $file->data["basename"]; $path = $p->importFile->path; $location = $path . $name; // Get the file $json = file_get_contents($location); $json = json_decode($json); // Loop through the rows of the import foreach ($json->ttEntityDelAddrLink as $client) { // Create new page $new = new Page(); // Create unique hash $unique = md5(date("Y-m-d H:i:s") . "-" . $client->CustomerCode); // Set some variables for the new page $new->setOutputFormatting(false); $new->template = "_client"; $new->parent = $p; // Create hash $new->title = $client->DelAddressName; $new->name = $unique; // Page specific fields $new->company = $client->DelAddressName; $new->companyId = $client->CustomerCode; $new->city = $client->DelAddressCity; $new->address = $client->DelAddressStreet; $new->postcode = $client->DelAddressZipCode; $new->country = $countries[$client->DelAddressCountryCode]; // Save the page $new->save(); } // Exit for debugging exit; }
      Does anybody know what's wrong?
    • By prestoav
      Hi folks,
      I have a marketplace site built on PW which I'd like to tie to a subscription payment system for those selling. The user accounts currently use specific PW user accounts. I'm looking closely at PayWhirl to manage payments and subscriptions as it looks ideal for subscriptions. Their API seems to work well too from initial testing.
      I wondered if anyone else in this super forum had used PayWhirl and had any advice or tips & tricks?
      Thanks.
      https://app.paywhirl.com/