Browse Source

notifications order, unseen css class

ping return notfications ordered by notification id
notifications list get seen/unseen class from ping xml
global.css define 'notify-unseen'
pull/1692/head
Fabrixxm 6 years ago
parent
commit
e29d05ce4a
5 changed files with 34 additions and 31 deletions
  1. +10
    -20
      js/main.js
  2. +18
    -8
      mod/ping.php
  3. +4
    -1
      view/global.css
  4. +1
    -1
      view/theme/quattro/templates/nav.tpl
  5. +1
    -1
      view/theme/vier/templates/nav.tpl

+ 10
- 20
js/main.js View File

@ -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("<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){


+ 18
- 8
mod/ping.php View 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);
}

+ 4
- 1
view/global.css View File

@ -173,4 +173,7 @@ span.oembed, h4 {
/* fields help text */
.field .field_help {
clear: left;
}
}
/* notifications unseen */
.notify-unseen { background-color: #cceeFF; }

+ 1
- 1
view/theme/quattro/templates/nav.tpl View File

@ -109,7 +109,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 style="position: fixed; top: 3px; left: 5px; z-index:9999">{{$langselector}}</div>

+ 1
- 1
view/theme/vier/templates/nav.tpl View 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>


Loading…
Cancel
Save