From 2b3cbc638bb626141bce0a6cc9860700823bc24b Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 26 Oct 2018 09:53:56 +0200 Subject: notifications: fix unseen forum count --- Zotlabs/Module/Ping.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Module/Ping.php') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index bc6985301..2ad4f1277 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -634,18 +634,20 @@ class Ping extends \Zotlabs\Web\Controller { if($vnotify & VNOTIFY_FORUMS) { $forums = get_forum_channels(local_channel()); - if(! $forums) { - $result['forums'] = 0; - } - else { - + if($forums) { $perms_sql = item_permissions_sql(local_channel()) . item_normal(); $fcount = count($forums); $forums['total'] = 0; for($x = 0; $x < $fcount; $x ++) { + $ttype = TERM_FORUM; + $p = q("SELECT oid AS parent FROM term WHERE uid = " . intval(local_channel()) . " AND ttype = $ttype AND term = '" . dbesc($forums[$x]['xchan_name']) . "'"); + $p = ids_to_querystr($p, 'parent'); + + $pquery = (($p) ? "OR parent IN ( $p )" : ''); + $r = q("select sum(item_unseen) as unseen from item - where uid = %d and owner_xchan = '%s' and item_unseen = 1 $perms_sql ", + where uid = %d and ( owner_xchan = '%s' $pquery ) and item_unseen = 1 $perms_sql ", intval(local_channel()), dbesc($forums[$x]['xchan_hash']) ); -- cgit v1.2.3 From 96bed3a623bf6bb832778b6957cd278c2a946c20 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 27 Oct 2018 22:34:18 +0200 Subject: fix issues with forum handling in mod network and ping. also some code cleanup. --- Zotlabs/Module/Ping.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Module/Ping.php') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index 2ad4f1277..75e8843d6 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -635,20 +635,25 @@ class Ping extends \Zotlabs\Web\Controller { $forums = get_forum_channels(local_channel()); if($forums) { - $perms_sql = item_permissions_sql(local_channel()) . item_normal(); + $perms_sql = item_permissions_sql(local_channel()); + $item_normal = item_normal(); $fcount = count($forums); $forums['total'] = 0; for($x = 0; $x < $fcount; $x ++) { - $ttype = TERM_FORUM; - $p = q("SELECT oid AS parent FROM term WHERE uid = " . intval(local_channel()) . " AND ttype = $ttype AND term = '" . dbesc($forums[$x]['xchan_name']) . "'"); - $p = ids_to_querystr($p, 'parent'); + $p = q("SELECT oid AS parent FROM term WHERE uid = %d AND ttype = %d AND term = '%s'", + intval(local_channel()), + intval(TERM_FORUM), + dbesc($forums[$x]['xchan_hash']) + ); - $pquery = (($p) ? "OR parent IN ( $p )" : ''); + $p_str = ids_to_querystr($p, 'parent'); + $p_sql = (($p_str) ? "OR parent IN ( $p_str )" : ''); $r = q("select sum(item_unseen) as unseen from item - where uid = %d and ( owner_xchan = '%s' $pquery ) and item_unseen = 1 $perms_sql ", + where uid = %d and ( owner_xchan = '%s' OR author_xchan = '%s' $p_sql ) and item_unseen = 1 $perms_sql $item_normal", intval(local_channel()), + dbesc($forums[$x]['xchan_hash']), dbesc($forums[$x]['xchan_hash']) ); if($r[0]['unseen']) { -- cgit v1.2.3 From 1eac4db491e6c597b56752b7915fdcafc529ed5e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 29 Oct 2018 23:01:13 +0100 Subject: fix forum ping results - the term query requires xchan_name instead of xchan_hash. also improve the query itself - item_permission_sql() is redundant here since we always deal with local_channel() and use count(id) instead of sum(item_unseen) to get the unseen count --- Zotlabs/Module/Ping.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module/Ping.php') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index 75e8843d6..cf5b2e004 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -635,7 +635,6 @@ class Ping extends \Zotlabs\Web\Controller { $forums = get_forum_channels(local_channel()); if($forums) { - $perms_sql = item_permissions_sql(local_channel()); $item_normal = item_normal(); $fcount = count($forums); $forums['total'] = 0; @@ -644,14 +643,14 @@ class Ping extends \Zotlabs\Web\Controller { $p = q("SELECT oid AS parent FROM term WHERE uid = %d AND ttype = %d AND term = '%s'", intval(local_channel()), intval(TERM_FORUM), - dbesc($forums[$x]['xchan_hash']) + dbesc($forums[$x]['xchan_name']) ); $p_str = ids_to_querystr($p, 'parent'); $p_sql = (($p_str) ? "OR parent IN ( $p_str )" : ''); - $r = q("select sum(item_unseen) as unseen from item - where uid = %d and ( owner_xchan = '%s' OR author_xchan = '%s' $p_sql ) and item_unseen = 1 $perms_sql $item_normal", + $r = q("select count(id) as unseen from item + where uid = %d and ( owner_xchan = '%s' OR author_xchan = '%s' $p_sql ) and item_unseen = 1 $item_normal", intval(local_channel()), dbesc($forums[$x]['xchan_hash']), dbesc($forums[$x]['xchan_hash']) -- cgit v1.2.3