From 04cda104caf1e3c714aec772f363135ae3f6be53 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 22 Apr 2015 08:39:27 +0200 Subject: [PATCH] New function that will prevent notifications from deleted posts --- mod/ping.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/mod/ping.php b/mod/ping.php index 82265530db..f907506d5b 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -29,6 +29,11 @@ select notify.id, notify.type, iid, visible, deleted, CASE notify.iid WHEN 0 THE $t = q("select count(*) as `total` from `notify` where `uid` = %d and `seen` = 0 AND `msg` != '' GROUP BY `parent`", intval(local_user()) ); + + $z = ping_get_notifications(local_user()); + $sysnotify = 0; // we will update this in a moment + +/* if($t && intval($t[0]['total']) > 49) { $z = q("select * from notify where uid = %d AND `msg` != '' and seen = 0 GROUP BY `parent` order by date desc limit 0, 50", @@ -50,7 +55,7 @@ select notify.id, notify.type, iid, visible, deleted, CASE notify.iid WHEN 0 THE $z = array_merge($z1,$z2); $sysnotify = 0; // we will update this in a moment } - +*/ $tags = array(); @@ -309,7 +314,7 @@ select notify.id, notify.type, iid, visible, deleted, CASE notify.iid WHEN 0 THE } unset($_SESSION['sysmsg_info']); } - + echo " "; echo" "; @@ -317,3 +322,48 @@ select notify.id, notify.type, iid, visible, deleted, CASE notify.iid WHEN 0 THE killme(); } +function ping_get_notifications($uid) { + + $result = array(); + $offset = 0; + $seen = false; + $seensql = "NOT"; + $quit = false; + + do { + $r = q("SELECT `notify`.*, `item`.`visible`, `item`.`spam`, `item`.`deleted` + FROM `notify` LEFT JOIN `item` ON `item`.`id` = `notify`.`iid` + WHERE `notify`.`uid` = %d AND `notify`.`msg` != '' + AND $seensql `notify`.`seen` ORDER BY `notify`.`date` DESC LIMIT %d, 50", + intval($uid), intval($offset) + ); + + if (!$r AND !$seen) { + $seen = true; + $seensql = ""; + $offset = 0; + } elseif (!$r) + $quit = true; + else + $offset += 50; + + foreach ($r AS $notification) { + if (is_null($notification["visible"])) + $notification["visible"] = true; + + if (is_null($notification["spam"])) + $notification["spam"] = 0; + + if (is_null($notification["deleted"])) + $notification["deleted"] = 0; + + if ($notification["visible"] AND !$notification["spam"] AND + !$notification["deleted"] AND !is_array($result[$notification["parent"]])) + $result[$notification["parent"]] = $notification; + } + + } while ((count($result) < 50) AND !$quit); + + return($result); +} +