diff options
author | Mario <mario@mariovavti.com> | 2019-09-23 10:10:56 +0200 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-09-23 10:10:56 +0200 |
commit | d1fd69337fa87ec10264919ffcb0bbe57f8873d2 (patch) | |
tree | 62bac44e09c7bdd617a8f6b6a427fd7fc8bacc24 /Zotlabs | |
parent | c385b808073fbe9e4422dc0af4c58149e5d6e9d5 (diff) | |
parent | 3fc218111adecf59df695e1f6e4f63f361b3dd34 (diff) | |
download | volse-hubzilla-d1fd69337fa87ec10264919ffcb0bbe57f8873d2.tar.gz volse-hubzilla-d1fd69337fa87ec10264919ffcb0bbe57f8873d2.tar.bz2 volse-hubzilla-d1fd69337fa87ec10264919ffcb0bbe57f8873d2.zip |
Merge branch 'encode-comment-policy' into 'dev'
Encode comment policy into AS(Z6) packets.
See merge request hubzilla/core!1729
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Lib/Activity.php | 12 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 51 |
2 files changed, 63 insertions, 0 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index ed29bfe6d..771c6875b 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2,6 +2,7 @@ namespace Zotlabs\Lib; +use Zotlabs\Access\PermissionLimits; use Zotlabs\Daemon\Master; use Zotlabs\Web\HTTPSig; @@ -339,10 +340,21 @@ class Activity { } } + if (intval($i['item_wall']) && $i['mid'] === $i['parent_mid']) { + $ret['commentPolicy'] = map_scope(PermissionLimits::Get($i['uid'],'post_comments')); + } + if (intval($i['item_private']) === 2) { $ret['directMessage'] = true; } + if (array_key_exists('comments_closed',$i) && $i['comments_closed'] !== EMPTY_STR && $i['comments_closed'] !== NULL_DATE) { + if($ret['commentPolicy']) { + $ret['commentPolicy'] .= ' '; + } + $ret['commentPolicy'] .= 'until=' . datetime_convert('UTC','UTC',$i['comments_closed'],ATOM_TIME); + } + $ret['attributedTo'] = $i['author']['xchan_url']; if($i['id'] != $i['parent']) { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 2a13744a3..0c90ff34d 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1223,9 +1223,39 @@ class Libzot { if($private) { $arr['item_private'] = true; } + + if ($arr['mid'] === $arr['parent_mid']) { + if (is_array($AS->obj) && array_key_exists('commentPolicy',$AS->obj)) { + $p = strstr($AS->obj['commentPolicy'],'until='); + if($p !== false) { + $arr['comments_closed'] = datetime_convert('UTC','UTC', substr($p,6)); + $arr['comment_policy'] = trim(str_replace($p,'',$AS->obj['commentPolicy'])); + } + else { + $arr['comment_policy'] = $AS->obj['commentPolicy']; + } + } + } + + /// @FIXME - spoofable if($AS->data['hubloc']) { $arr['item_verified'] = true; + + if (! array_key_exists('comment_policy',$arr)) { + // set comment policy depending on source hub. Unknown or osada is ActivityPub. + // Anything else we'll say is zot - which could have a range of project names + $s = q("select site_project from site where site_url = '%s' limit 1", + dbesc($r[0]['hubloc_url']) + ); + + if ((! $s) || (in_array($s[0]['site_project'],[ '', 'osada' ]))) { + $arr['comment_policy'] = 'authenticated'; + } + else { + $arr['comment_policy'] = 'contacts'; + } + } } if($AS->data['signed_data']) { IConfig::Set($arr,'activitystreams','signed_data',$AS->data['signed_data'],false); @@ -1819,6 +1849,10 @@ class Libzot { $ret = []; + $signer = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", + dbesc($a['signature']['signer']) + ); + foreach($a['data']['orderedItems'] as $activity) { $AS = new ActivityStreams($activity); @@ -1877,6 +1911,23 @@ class Libzot { if($AS->data['hubloc']) { $arr['item_verified'] = true; } + + // set comment policy depending on source hub. Unknown or osada is ActivityPub. + // Anything else we'll say is zot - which could have a range of project names + + if ($signer) { + $s = q("select site_project from site where site_url = '%s' limit 1", + dbesc($signer[0]['hubloc_url']) + ); + if ((! $s) || (in_array($s[0]['site_project'],[ '', 'osada' ]))) { + $arr['comment_policy'] = 'authenticated'; + } + else { + $arr['comment_policy'] = 'contacts'; + } + } + + if($AS->data['signed_data']) { IConfig::Set($arr,'activitystreams','signed_data',$AS->data['signed_data'],false); } |