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('→ ','').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){
<?php
require_once("include/datetime.php");
require_once('include/bbcode.php');
-
+require_once("mod/proxy.php");
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");
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', "→ ".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'])));
}
}
}
$offset = 0;
$seen = false;
$seensql = "NOT";
- $order = "";
+ $order = "DESC";
$quit = false;
$a = get_app();
$quit = true;
else
$offset += 50;
+
foreach ($r AS $notification) {
if (is_null($notification["visible"]))
$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);
}