aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorM. Dent <dentm42@gmail.com>2019-09-23 10:11:27 +0200
committerMario <mario@mariovavti.com>2019-09-23 10:11:27 +0200
commit7c5cfe66973a8e529c01c3a214e9f8b791c89c23 (patch)
tree6ef8f96a07a0bbff51b1712dbaf4cda9e3e9b623
parentd1fd69337fa87ec10264919ffcb0bbe57f8873d2 (diff)
downloadvolse-hubzilla-7c5cfe66973a8e529c01c3a214e9f8b791c89c23.tar.gz
volse-hubzilla-7c5cfe66973a8e529c01c3a214e9f8b791c89c23.tar.bz2
volse-hubzilla-7c5cfe66973a8e529c01c3a214e9f8b791c89c23.zip
Notify on custom items - rework hooks
-rw-r--r--Zotlabs/Daemon/Notifier.php17
-rw-r--r--Zotlabs/Lib/Activity.php56
-rw-r--r--doc/hook/activity_decode_mapper.bb1
-rw-r--r--doc/hook/activity_mapper.bb1
-rw-r--r--doc/hook/activity_obj_decode_mapper.bb1
-rw-r--r--doc/hook/activity_obj_mapper.bb1
-rw-r--r--doc/hook/encode_object.bb1
-rw-r--r--doc/hook/fetch_and_store.bb1
-rw-r--r--doc/hooklist.bb18
-rwxr-xr-xinclude/items.php21
10 files changed, 88 insertions, 30 deletions
diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php
index 15dc08908..1d0be10d9 100644
--- a/Zotlabs/Daemon/Notifier.php
+++ b/Zotlabs/Daemon/Notifier.php
@@ -285,8 +285,21 @@ class Notifier {
}
if(! in_array(intval($target_item['item_type']), [ ITEM_TYPE_POST ] )) {
- logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG);
- return;
+ $hookinfo=[
+ 'targetitem'=>$target_item,
+ 'deliver'=>false
+ ];
+ if (intval($target_item['item_type'] == ITEM_TYPE_CUSTOM)) {
+ call_hooks('customitem_deliver',$hookinfo);
+ }
+
+ if (!$hookinfo['deliver']) {
+ logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG);
+ return;
+ }
+
+ $target_item = $hookinfo['targetitem'];
+
}
// Check for non published items, but allow an exclusion for transmitting hidden file activities
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 771c6875b..bcf017286 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -42,6 +42,8 @@ class Activity {
if($x['type'] === ACTIVITY_OBJ_PHOTO) {
return self::fetch_image($x);
}
+
+ call_hooks('encode_object',$x);
}
return $x;
@@ -806,6 +808,7 @@ class Activity {
'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept'
];
+ call_hooks('activity_mapper',$acts);
if(array_key_exists($verb,$acts) && $acts[$verb]) {
return $acts[$verb];
@@ -851,6 +854,7 @@ class Activity {
'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept'
];
+ call_hooks('activity_decode_mapper',$acts);
foreach($acts as $k => $v) {
if($verb === $v) {
@@ -884,6 +888,8 @@ class Activity {
];
+ call_hooks('activity_obj_decode_mapper',$objs);
+
foreach($objs as $k => $v) {
if($obj === $v) {
return $k;
@@ -921,6 +927,8 @@ class Activity {
];
+ call_hooks('activity_obj_mapper',$objs);
+
if(array_key_exists($obj,$objs)) {
return $objs[$obj];
}
@@ -1941,6 +1949,15 @@ class Activity {
set_iconfig($s,'activitypub','rawmsg',$act->raw,1);
}
+ $hookinfo = [
+ 'act' => $act,
+ 's' => $s
+ ];
+
+ call_hooks('decode_note',$hookinfo);
+
+ $s = $hookinfo['s'];
+
return $s;
}
@@ -2130,16 +2147,25 @@ class Activity {
break;
}
- if(! $item) {
- break;
- }
- array_unshift($p,[ $a, $item, $replies]);
+ $hookinfo = [
+ 'a' => $a,
+ 'item' => $item
+ ];
+
+ call_hooks('fetch_and_store',$hookinfo);
- if($item['parent_mid'] === $item['mid'] || count($p) > 20) {
- break;
- }
+ $item = $hookinfo['item'];
+ if($item) {
+
+ array_unshift($p,[ $a, $item, $replies]);
+
+ if($item['parent_mid'] === $item['mid'] || count($p) > 20) {
+ break;
+ }
+
+ }
$current_act = $a;
$current_item = $item;
}
@@ -2188,11 +2214,19 @@ class Activity {
default:
break;
}
- if(! $item) {
- break;
- }
- array_unshift($p,[ $a, $item ]);
+ $hookinfo = [
+ 'a' => $a,
+ 'item' => $item
+ ];
+
+ call_hooks('fetch_and_store',$hookinfo);
+
+ $item = $hookinfo['item'];
+
+ if($item) {
+ array_unshift($p,[ $a, $item ]);
+ }
}
diff --git a/doc/hook/activity_decode_mapper.bb b/doc/hook/activity_decode_mapper.bb
new file mode 100644
index 000000000..43d08a136
--- /dev/null
+++ b/doc/hook/activity_decode_mapper.bb
@@ -0,0 +1 @@
+[h2]activity_decode_mapper[/h2]
diff --git a/doc/hook/activity_mapper.bb b/doc/hook/activity_mapper.bb
new file mode 100644
index 000000000..db65fadc4
--- /dev/null
+++ b/doc/hook/activity_mapper.bb
@@ -0,0 +1 @@
+[h2]activity_mapper[/h2]
diff --git a/doc/hook/activity_obj_decode_mapper.bb b/doc/hook/activity_obj_decode_mapper.bb
new file mode 100644
index 000000000..a96b32eee
--- /dev/null
+++ b/doc/hook/activity_obj_decode_mapper.bb
@@ -0,0 +1 @@
+[h2]activity_obj_decode_mapper[/h2]
diff --git a/doc/hook/activity_obj_mapper.bb b/doc/hook/activity_obj_mapper.bb
new file mode 100644
index 000000000..7c14a1b81
--- /dev/null
+++ b/doc/hook/activity_obj_mapper.bb
@@ -0,0 +1 @@
+[h2]activity_obj_mapper[/h2]
diff --git a/doc/hook/encode_object.bb b/doc/hook/encode_object.bb
new file mode 100644
index 000000000..0c8e86458
--- /dev/null
+++ b/doc/hook/encode_object.bb
@@ -0,0 +1 @@
+[h2]encode_object[/h2]
diff --git a/doc/hook/fetch_and_store.bb b/doc/hook/fetch_and_store.bb
new file mode 100644
index 000000000..afece11a6
--- /dev/null
+++ b/doc/hook/fetch_and_store.bb
@@ -0,0 +1 @@
+[h2]fetch_and_store[/h2]
diff --git a/doc/hooklist.bb b/doc/hooklist.bb
index 5a804c819..e11bf1c6f 100644
--- a/doc/hooklist.bb
+++ b/doc/hooklist.bb
@@ -34,6 +34,18 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/activity_filter]activity_filter[/zrl]
Called when generating the list of filters for the network page
+[zrl=[baseurl]/help/hook/activity_filter]activity_mapper[/zrl]
+ Called when determining the activity type for transmission.
+
+[zrl=[baseurl]/help/hook/activity_filter]activity_decode_mapper[/zrl]
+ Called when determining the activity type for transmission.
+
+[zrl=[baseurl]/help/hook/activity_filter]activity_obj_mapper[/zrl]
+ Called when determining the object type for transmission.
+
+[zrl=[baseurl]/help/hook/activity_filter]activity_obj_decode_mapper[/zrl]
+ Called when determining the object type for transmission.
+
[zrl=[baseurl]/help/hook/activity_order]activity_order[/zrl]
Called when generating the list of order options for the network page
@@ -232,6 +244,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/drop_item]drop_item[/zrl]
called when an 'item' is removed
+[zrl=[baseurl]/help/hook/encode_object]encode_object[/zrl]
+ called when encoding an object for transmission.
+
[zrl=[baseurl]/help/hook/enotify]enotify[/zrl]
called before any notification
@@ -262,6 +277,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/feature_settings_post]feature_settings_post[/zrl]
called from settings page when posting from 'addon/feature settings'
+[zrl=[baseurl]/help/hook/fetch_and_store]fetch_and_store[/zrl]
+ called to allow filtering of 'decoded' items before storage.
+
[zrl=[baseurl]/help/hook/file_thumbnail]file_thumbnail[/zrl]
called when generating thumbnail images for cloud page in 'view tiles' mode
diff --git a/include/items.php b/include/items.php
index 84bfc263b..6786b8b05 100755
--- a/include/items.php
+++ b/include/items.php
@@ -1640,20 +1640,14 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
'allow_exec' => $allow_exec
];
- if ($arr['item_type']==ITEM_TYPE_CUSTOM) {
- /* Custom items are not stored by default
- because they require an addon to process. */
- $d['item']['cancel']=true;
-
- call_hooks('item_custom',$d);
- }
/**
* @hooks item_store
* Called when item_store() stores a record of type item.
* * \e array \b item
* * \e boolean \b allow_exec
*/
- call_hooks('item_store', $d);
+ call_hooks('item_store_before', $d);
+
$arr = $d['item'];
$allow_exec = $d['allow_exec'];
@@ -1961,6 +1955,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
*/
call_hooks('item_store', $arr);
+
/**
* @hooks post_remote
* Called when an activity arrives from another site.
@@ -2129,14 +2124,6 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
'allow_exec' => $allow_exec
];
- if ($arr['item_type']==ITEM_TYPE_CUSTOM) {
- /* Custom items are not stored by default
- because they require an addon to process. */
- $d['item']['cancel']=true;
-
- call_hooks('item_custom_update',$d);
- }
-
/**
* @hooks item_store_update
* Called when item_store_update() is called to update a stored item. It
@@ -2144,7 +2131,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
* * \e array \b item
* * \e boolean \b allow_exec
*/
- call_hooks('item_store_update', $d);
+ call_hooks('item_store_update_before', $d);
$arr = $d['item'];
$allow_exec = $d['allow_exec'];