]> git.mxchange.org Git - friendica.git/commitdiff
notifications order, unseen css class
authorFabrixxm <fabrix.xm@gmail.com>
Wed, 24 Jun 2015 14:10:06 +0000 (16:10 +0200)
committerFabrixxm <fabrix.xm@gmail.com>
Wed, 24 Jun 2015 14:10:06 +0000 (16:10 +0200)
ping return notfications ordered by notification id
notifications list get seen/unseen class from ping xml
global.css define 'notify-unseen'

js/main.js
mod/ping.php
view/global.css
view/theme/quattro/templates/nav.tpl
view/theme/vier/templates/nav.tpl

index 23e759ef3a1f7cffcc24f495eef0dc5f9d642100..b812e25089f5d18ca5174673ce24f4f803f0b293 100644 (file)
                                nnm.html(notifications_all + notifications_mark);
                                //nnm.attr('popup','true');
 
-                               var notification_lastitem = localStorage.getItem("notification-lastitem");
-                               var notification_first_id = 0;
-                               var notification_id;
+                               var notification_lastitem = parseInt(localStorage.getItem("notification-lastitem"));
+                               var notification_id = 0;
                                eNotif.children("note").each(function(){
                                        e = $(this);
                                        text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
                                        html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
                                        nnm.append(html);
-                                       
-                                       notification_id = e.attr('href').match(/\d+$/)[0];
-                                       if (notification_lastitem!== null && notification_id!=notification_lastitem) {
-                                               if (notification_first_id===0) notification_first_id = notification_id;
+                               });
+                               $(eNotif.children("note").get().reverse()).each(function(){
+                                       e = $(this);
+                                       notification_id = parseInt(e.attr('href').match(/\d+$/)[0]);
+                                       if (notification_lastitem!== null && notification_id > notification_lastitem) {
                                                if (getNotificationPermission()==="granted") {
-                                                       console.log("notification", e.text().replace('&rarr; ','').format(e.attr('name')));
                                                        var notification = new Notification(document.title, {
                                                                                          body: e.text().replace('&rarr; ','').format(e.attr('name')),
                                                                                          icon: e.attr('photo'),
-                                                                                         data: e.attr('href')
                                                                                         });
-                                                       // close notification after 5 secs.
-                                                       // see https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API#Closing_notifications
-                                                       //setTimeout(notification.close.bind(notification), 5000);
-                                                       
+                                                       notification['url'] = e.attr('href');
                                                        notification.addEventListener("click", function(ev){
-                                                               window.location = ev.target.data;
+                                                               window.location = ev.target.url;
                                                        });
                                                }
                                        }
-                                       if (notification_id == notification_lastitem) {
-                                               if (notification_first_id===0) notification_first_id = notification_id;
-                                               notification_lastitem = null;
-                                       }
-                               
                                        
                                });
-                               if (notification_first_id!==0) notification_lastitem = notification_first_id;
+                               notification_lastitem = notification_id;
                                localStorage.setItem("notification-lastitem", notification_lastitem)
 
                                $("img[data-src]", nnm).each(function(i, el){
index 97a3070d8486fdfcb0e76946f428d68b25a4ae3e..a5f23e1eb9f23dac5fedbe692a4294606acae91f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 require_once("include/datetime.php");
 require_once('include/bbcode.php');
-
+require_once("mod/proxy.php");
 
 function ping_init(&$a) {
 
@@ -164,7 +164,6 @@ function ping_init(&$a) {
 
 
                function xmlize($href, $name, $url, $photo, $date, $seen, $message){
-                       require_once("mod/proxy.php");
                        $photo = proxy_url($photo);
 
                        $message = html_entity_decode($message, ENT_COMPAT | ENT_HTML401, "UTF-8");
@@ -216,23 +215,23 @@ function ping_init(&$a) {
 
                        if ($intro>0){
                                foreach ($intros as $i) {
-                                       echo xmlize($a->get_baseurl().'/notifications/intros/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), 'notify-unseen', "&rarr; ".t("{0} wants to be your friend"));
+                                       echo xmlize($a->get_baseurl().'/notifications/intros/'.$i['id'], $i['name'], $i['url'], $i['photo'], relative_date($i['datetime']), 'notify-unseen', t("{0} wants to be your friend"));
                                };
                        }
                        if ($mail>0){
                                foreach ($mails as $i) {
-                                       echo xmlize($a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen',"&rarr; ".t("{0} sent you a message"));
+                                       echo xmlize($a->get_baseurl().'/message/'.$i['id'], $i['from-name'], $i['from-url'], $i['from-photo'], relative_date($i['created']), 'notify-unseen', t("{0} sent you a message"));
                                };
                        }
                        if ($register>0){
                                foreach ($regs as $i) {
-                                       echo xmlize($a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen', "&rarr; ".t("{0} requested registration"));
+                                       echo xmlize($a->get_baseurl().'/admin/users/', $i['name'], $i['url'], $i['micro'], relative_date($i['created']), 'notify-unseen', t("{0} requested registration"));
                                };
                        }
 
                        if(count($z)) {
                                foreach($z as $zz) {
-                                       echo xmlize($a->get_baseurl() . '/notify/view/' . $zz['id'], $zz['name'],$zz['url'],$zz['photo'],relative_date($zz['date']), ($zz['seen'] ? 'notify-seen' : 'notify-unseen'), ($zz['seen'] ? '' : '&rarr; ') .strip_tags(bbcode($zz['msg'])));
+                                       echo xmlize($a->get_baseurl() . '/notify/view/' . $zz['id'], $zz['name'],$zz['url'],$zz['photo'],relative_date($zz['date']), ($zz['seen'] ? 'notify-seen' : 'notify-unseen'), strip_tags(bbcode($zz['msg'])));
                                }
                        }
                }
@@ -322,7 +321,7 @@ function ping_get_notifications($uid) {
        $offset = 0;
        $seen = false;
        $seensql = "NOT";
-       $order = "";
+       $order = "DESC";
        $quit = false;
 
        $a = get_app();
@@ -348,6 +347,7 @@ function ping_get_notifications($uid) {
                        $quit = true;
                else
                        $offset += 50;
+                       
 
                foreach ($r AS $notification) {
                        if (is_null($notification["visible"]))
@@ -370,11 +370,21 @@ function ping_get_notifications($uid) {
                                $notification["msg"] = substr_replace($notification["msg"],"{0}",$pos,strlen($notification["name"]));
 
                        if ($notification["visible"] AND !$notification["spam"] AND
-                               !$notification["deleted"] AND !is_array($result[$notification["parent"]]))
+                               !$notification["deleted"] AND !is_array($result[$notification["parent"]])) {
                                $result[$notification["parent"]] = $notification;
+                       }
                }
 
        } while ((count($result) < 50) AND !$quit);
 
+       // sort result by $[]['id'], inversed
+       $sort_function = function($a, $b) {
+               if ($a['id'] == $b['id']) {
+                       return 0;
+               }
+               return ($a['id'] < $b['id']) ? 1 : -1;
+       };
+       usort($result, $sort_function);
+       
        return($result);
 }
index 673dbcd457ed512a337636a8fcba952aa0ec9959..9bcd30229633fdaad828451efcee5293c13189c2 100644 (file)
@@ -173,4 +173,7 @@ span.oembed, h4 {
 /* fields help text */
 .field .field_help {
     clear: left;
-}
\ No newline at end of file
+}
+
+/* notifications unseen */
+.notify-unseen { background-color: #cceeFF; }
\ No newline at end of file
index 2c646306ad3b2f014cbe8d3052f3ece7a8056342..c77ed99e457b80f4da2d17cf25263237874a9a13 100644 (file)
 
 </nav>
 <ul id="nav-notifications-template" style="display:none;" rel="template">
-       <li><a href="{0}"><img data-src="{1}">{2} <span class="notif-when">{3}</span></a></li>
+       <li class="{4}"><a href="{0}"><img data-src="{1}">{2} <span class="notif-when">{3}</span></a></li>
 </ul>
 
 <div style="position: fixed; top: 3px; left: 5px; z-index:9999">{{$langselector}}</div>
index ec1be842c6fa2d45aadbe08fe92ef9659d7c2e1a..4ef6400809f33c8c3bec5719e83425496a004a18 100644 (file)
@@ -97,7 +97,7 @@
 
 </nav>
 <ul id="nav-notifications-template" style="display:none;" rel="template">
-       <li><a href="{0}"><img data-src="{1}">{2} <span class="notif-when">{3}</span></a></li>
+       <li class="{4}"><a href="{0}"><img data-src="{1}">{2} <span class="notif-when">{3}</span></a></li>
 </ul>
 <!--
 <div class="icon-flag" style="position: fixed; bottom: 10px; left: 20px; z-index:9;">{{$langselector}}</div>