From 9359f9fe4d77de392660c2bf6f1df8becc9fa6bf Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 1 Aug 2017 22:25:55 -0700 Subject: plugin hook for update_unseen --- Zotlabs/Module/Channel.php | 10 +++++++--- Zotlabs/Module/Network.php | 13 +++++++++---- Zotlabs/Module/Notify.php | 16 ++++++++++------ doc/hook/update_unseen.bb | 9 +++++++++ doc/hooklist.bb | 3 +++ 5 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 doc/hook/update_unseen.bb diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index a44984c97..c006d65d4 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -358,9 +358,13 @@ class Channel extends \Zotlabs\Web\Controller { } if($is_owner && $update_unseen) { - $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", - intval(local_channel()) - ); + $x = [ 'channel_id' => local_channel(), 'update' => 'unset' ]; + call_hooks('update_unseen',$x); + if($x['update'] === 'unset' || intval($x['update'])) { + $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", + intval(local_channel()) + ); + } } diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index 597ba084b..1954df549 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -545,10 +545,15 @@ class Network extends \Zotlabs\Web\Controller { } } - if(($update_unseen) && (! $firehose)) - $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d $update_unseen ", - intval(local_channel()) - ); + if(($update_unseen) && (! $firehose)) { + $x = [ 'channel_id' => local_channel(), 'update' => 'unset' ]; + call_hooks('update_unseen',$x); + if($x['update'] === 'unset' || intval($x['update'])) { + $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d $update_unseen ", + intval(local_channel()) + ); + } + } $mode = (($nouveau) ? 'network-new' : 'network'); diff --git a/Zotlabs/Module/Notify.php b/Zotlabs/Module/Notify.php index f592f6f37..3d6e1c2e7 100644 --- a/Zotlabs/Module/Notify.php +++ b/Zotlabs/Module/Notify.php @@ -15,12 +15,16 @@ class Notify extends \Zotlabs\Web\Controller { intval(local_channel()) ); if($r) { - q("update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d", - dbesc($r[0]['parent']), - dbesc($r[0]['otype']), - dbesc($r[0]['link']), - intval(local_channel()) - ); + $x = [ 'channel_id' => local_channel(), 'update' => 'unset' ]; + call_hooks('update_unseen',$x); + if($x['update'] === 'unset' || intval($x['update'])) { + q("update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d", + dbesc($r[0]['parent']), + dbesc($r[0]['otype']), + dbesc($r[0]['link']), + intval(local_channel()) + ); + } goaway($r[0]['link']); } goaway(z_root()); diff --git a/doc/hook/update_unseen.bb b/doc/hook/update_unseen.bb new file mode 100644 index 000000000..8fb02c239 --- /dev/null +++ b/doc/hook/update_unseen.bb @@ -0,0 +1,9 @@ +[h3]update_unseen[/h3] + +Called prior to automatically marking items 'seen'; allowing a plugin the choice to not perform this action. + +hook data + +[ 'channel_id' => local_channel(), 'update' => 'unset' ]; + +If 'update' is set to 0 or false on return, the update operation is not performed. \ No newline at end of file diff --git a/doc/hooklist.bb b/doc/hooklist.bb index da4d9596b..9a17fdb91 100644 --- a/doc/hooklist.bb +++ b/doc/hooklist.bb @@ -572,6 +572,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the [zrl=[baseurl]/help/hook/tagged]tagged[/zrl] Called when a delivery is processed which results in you being tagged +[zrl=[baseurl]/help/hook/update_unseen]update_unseen[/zrl] + Called prior to automatically marking items seen which were loaded in the browser + [zrl=[baseurl]/help/hook/validate_channelname]validate_channelname[/zrl] Used to validate the names used by a channel -- cgit v1.2.3