Trying to add a "mark read" option for individual notifications.

Michieal ~ Coder ~ Posted in Component Development 3 years ago

What am I missing here?
in the section for echoing out the notification, I am wanting to place effectively a Mark As Read icon, that a person can click or tap, to mark the individual notification as read. I'd really like to add in a delete notification so that users can delete useless notifications, such as "like comments" etc. to save on space... but...

The problem is that $params['notifications'] in the foreach statement doesn't have anything in 'guid', 'subject-guid' or 'item-guid'. How do I reference the individual notification to get the id number to pass to 'notifications/read/' or to the 'notifications/delete/' when I make the link using ossn-site-url(...)?

Thank you for your help!
-Michieal.

EDIT: replaced the _'s with -'s because it was doing weird italics.

Replies
Indonesian Arsalan Shah Replied 3 years ago

Now that is where you Job is started :) Its now up to you about how you can handle these.

us Michieal ~ Coder ~ Replied 3 years ago

Okay, so I have fixed the double appearance.
I now have it looking pretty cool...
The last thing to conquer is it actually doing what it says it does, and also not take the user to a 'page not found' error. But, it's getting there!

:D

Indonesian Arsalan Shah Replied 3 years ago

Well 404 means URL didn't exists and that make sense there is no such a URL exists. Regarding double appearance.

I don't understand also why $version == "6.0" and 5.6 have different URLS? I didn't meant 6.0 codes to these I mean the notification types I mentioned are some from 6.0

You need to check if you didn't added that component twice in the system or it didn't exists twice in components table.

us Michieal ~ Coder ~ Replied 3 years ago

@Arsalan, Thank you!!!

I have the code in a new component, tentatively dubbed "MarkNotification". I'm encountering a couple of things, that I didn't expect.
First: it pops it in twice. (I have no idea why, but...
And secondly, both the code that you gave me, and recreating the notification's code both redirect to 404 error: page not found. It does mark it -- as the badge number goes down; but instead of refreshing to where they were (REF) or home ('home') it always goes to a 404 error page.
And the delete doesn't delete...
In the image, "Mark ✔️" marks the notification, and "❌ " deletes the notification. (Supposed to, anyways.)

Code:

 $version = $Ossn->siteSettings->site_version; //may be off, because hand writing it here from memory; Uses the code from getsettings function.
 $location = urlencode(ossn_site_url('home'));
          ... 
      if ($version <= "5.6") {
            $frag->appendXml("<a href='notification/read/{$notification_guid}?notification={$location}' style='position:relative;float:right;' title='{$notif_title}'>Mark ✔️</a>");
      } elseif ($version == "6.0") {
            $frag->appendXml("<a href='read?guid={$notification_guid}' style='position:relative;float:right;' title='{$notif_title}'>Mark ✔️</a>");
      } else {
            return; // exit if not an appropriate version.
      }
      $div->appendChild($frag);

enter image description here

Thoughts?
-Michieal.

Indonesian Arsalan Shah Replied 3 years ago

Create a new component and add following in your ossn_com.php file

<?php
function ossn_notifications_custom_init(){
        $alltypes = array(
                'like:annotation',
                'like:entity',
                'comments:post',
                'ossnpoke:poke',
                'like:entity:file:profile:photo',
                'comments:entity:file:profile:photo',
                'like:entity:file:profile:cover',
                'comments:entity:file:profile:cover',
                'wall:friends:tag',
                'like:post:businesspage:wall',
                'comments:post:businesspage:wall',
                'event:relation:going',
                'event:relation:interested',
                'event:relation:nointerested',
                'comments:entity:event:wall',
                'like:post:businesspage:wall',
                'like:entity:event:wall',
                'like:annotation',
                'groupinvite',
                'group:joinrequest',
                'like:annotation:comments:post',
                'like:annotation:comments:entity',
        );
        foreach ($alltypes as $type){
                ossn_add_hook('notification:view', $type, 'notificaiton_insert_custom_html');
        }
}
function notificaiton_insert_custom_html($hook, $htype, $return, $params){
        $notification_guid = $params->guid;
        if(!empty($return)){
                $doc = new DOMDocument();
                $doc->loadHTML($return, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

                $div = $doc->getElementsByTagName('a')->item(0);

                $frag = $doc->createDocumentFragment();
                $frag->appendXml("<a href='read?guid={$notification_guid}'><input type='radio' /></a>");
                $div->appendChild($frag);

                return $doc->saveHTML();
        }
        return $return;
}
ossn_register_callback('ossn', 'init', 'ossn_notifications_custom_init');

Right now each notification type template is handled via component file. The only way is to write a notification:view hooks again for each type but you can avoid that by above code just insert a new tag for each notification template.

NOTE The types will change in OSSN 6.0 and I tried to include new types from v6.0 in above code also.

enter image description here

You can adjust the style and position the element as per your need.

in Nik Fury Replied 3 years ago

Hello Michieal~Coder~ . Can u provide me your email address? I have some queries regarding attachments in 1:1 messages. I can pay you if you can solve those issues. My email id is : [email protected]

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions