diff --git a/js/main.js b/js/main.js index 23e759ef3..b812e2508 100644 --- a/js/main.js +++ b/js/main.js @@ -182,42 +182,32 @@ 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(""+e.attr('name')+""); 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('→ ','').format(e.attr('name'))); var notification = new Notification(document.title, { body: e.text().replace('→ ','').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){ diff --git a/mod/ping.php b/mod/ping.php index 97a3070d8..a5f23e1eb 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -1,7 +1,7 @@ 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', "→ ".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',"→ ".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', "→ ".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'] ? '' : '→ ') .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); } diff --git a/view/global.css b/view/global.css index 673dbcd45..9bcd30229 100644 --- a/view/global.css +++ b/view/global.css @@ -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 diff --git a/view/theme/quattro/templates/nav.tpl b/view/theme/quattro/templates/nav.tpl index 2c646306a..c77ed99e4 100644 --- a/view/theme/quattro/templates/nav.tpl +++ b/view/theme/quattro/templates/nav.tpl @@ -109,7 +109,7 @@
{{$langselector}}
diff --git a/view/theme/vier/templates/nav.tpl b/view/theme/vier/templates/nav.tpl index ec1be842c..4ef640080 100644 --- a/view/theme/vier/templates/nav.tpl +++ b/view/theme/vier/templates/nav.tpl @@ -97,7 +97,7 @@