aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Activity.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Activity.php')
-rw-r--r--Zotlabs/Lib/Activity.php135
1 files changed, 110 insertions, 25 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 96b747c30..cacf4d979 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -886,10 +886,6 @@ class Activity {
else
return [];
- if (strpos($i['body'], '[/share]') !== false) {
- $i['obj'] = null;
- }
-
if ($i['obj']) {
if (!is_array($i['obj'])) {
$i['obj'] = json_decode($i['obj'], true);
@@ -899,8 +895,10 @@ class Activity {
}
$obj = self::encode_object($i['obj']);
- if ($obj)
+
+ if ($obj) {
$ret['object'] = $obj;
+ }
else
return [];
}
@@ -1042,7 +1040,7 @@ class Activity {
$tmp = expand_acl($i['allow_cid']);
$list = stringify_array($tmp, true);
if ($list) {
- $details = q("select hubloc_id_url from hubloc where hubloc_hash in (" . $list . ") and hubloc_id_url != ''");
+ $details = q("select hubloc_id_url from hubloc where hubloc_hash in (" . $list . ") and hubloc_id_url != '' and hubloc_deleted = 0");
if ($details) {
foreach ($details as $d) {
$ret[] = $d['hubloc_id_url'];
@@ -1089,10 +1087,11 @@ class Activity {
$ret['type'] = 'Person';
if ($c) {
- $role = get_pconfig($c['channel_id'], 'system', 'permissions_role');
- if (strpos($role, 'forum') !== false) {
+ if (get_pconfig($c['channel_id'], 'system', 'group_actor')) {
$ret['type'] = 'Group';
}
+
+ $ret['manuallyApprovesFollowers'] = ((get_pconfig($c['channel_id'], 'system', 'autoperms')) ? false : true);
}
if ($c) {
@@ -1115,7 +1114,33 @@ class Activity {
'height' => 300,
'width' => 300,
];
- $ret['url'] = $p['xchan_url'];
+
+/* This could be used to distinguish actors by protocol instead of tags,
+ * array urls are not supported by some AP projects (pixelfed) though.
+ *
+ $ret['url'] = [
+ [
+ 'type' => 'Link',
+ 'rel' => 'alternate',
+ 'mediaType' => 'application/x-zot+json',
+ 'href' => $p['xchan_url']
+ ],
+ [
+ 'type' => 'Link',
+ 'rel' => 'alternate',
+ 'mediaType' => 'application/activity+json',
+ 'href' => $p['xchan_url']
+ ],
+ [
+ 'type' => 'Link',
+ 'rel' => 'alternate', // 'me'?
+ 'mediaType' => 'text/html',
+ 'href' => $p['xchan_url']
+ ]
+ ];
+*/
+
+ $ret['url'] = $p['xchan_url'];
$ret['publicKey'] = [
'id' => $p['xchan_url'],
@@ -1124,6 +1149,12 @@ class Activity {
];
if ($c) {
+ $ret['tag'][] = [
+ 'type' => 'PropertyValue',
+ 'name' => 'Protocol',
+ 'value' => 'zot6'
+ ];
+
$ret['outbox'] = z_root() . '/outbox/' . $c['channel_address'];
}
@@ -1488,7 +1519,7 @@ class Activity {
'type' => NOTIFY_INTRO,
'from_xchan' => $ret['xchan_hash'],
'to_xchan' => $channel['channel_hash'],
- 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'],
+ 'link' => z_root() . '/connections#' . $new_connection[0]['abook_id'],
]
);
@@ -1522,9 +1553,9 @@ class Activity {
/* If there is a default group for this channel and permissions are automatic, add this member to it */
if ($channel['channel_default_group'] && $automatic) {
- $g = Group::rec_byhash($channel['channel_id'], $channel['channel_default_group']);
+ $g = AccessList::by_hash($channel['channel_id'], $channel['channel_default_group']);
if ($g)
- Group::member_add($channel['channel_id'], '', $ret['xchan_hash'], $g['id']);
+ AccessList::member_add($channel['channel_id'], '', $ret['xchan_hash'], $g['id']);
}
@@ -1625,6 +1656,19 @@ class Activity {
$name = t('Unknown');
}
+ $webfinger_addr = '';
+
+ $m = parse_url($url);
+ if ($m) {
+ $hostname = $m['host'];
+ $baseurl = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : '');
+ $site_url = $m['scheme'] . '://' . $m['host'];
+ }
+
+ if (!empty($person_obj['preferredUsername']) && isset($parsed_url['host'])) {
+ $webfinger_addr = escape_tags($person_obj['preferredUsername']) . '@' . $hostname;
+ }
+
$icon = z_root() . '/' . get_default_profile_photo(300);
if ($person_obj['icon']) {
if (is_array($person_obj['icon'])) {
@@ -1659,7 +1703,7 @@ class Activity {
if ($links) {
foreach ($links as $link) {
- if (array_key_exists('mediaType', $link) && $link['mediaType'] === 'text/html') {
+ if (is_array($link) && array_key_exists('mediaType', $link) && $link['mediaType'] === 'text/html') {
$profile = $link['href'];
}
}
@@ -1684,13 +1728,6 @@ class Activity {
}
}
- $m = parse_url($url);
- if ($m) {
- $hostname = $m['host'];
- $baseurl = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : '');
- $site_url = $m['scheme'] . '://' . $m['host'];
- }
-
$r = q("select * from xchan join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s'",
dbesc($url)
);
@@ -1709,17 +1746,19 @@ class Activity {
);
// update existing xchan record
- q("update xchan set xchan_name = '%s', xchan_guid = '%s', xchan_pubkey = '%s', xchan_network = 'activitypub', xchan_name_date = '%s' where xchan_hash = '%s'",
+ q("update xchan set xchan_name = '%s', xchan_guid = '%s', xchan_pubkey = '%s', xchan_addr = '%s', xchan_network = 'activitypub', xchan_name_date = '%s' where xchan_hash = '%s'",
dbesc(escape_tags($name)),
dbesc(escape_tags($url)),
dbesc(escape_tags($pubkey)),
+ dbesc(escape_tags($webfinger_addr)),
dbescdate(datetime_convert()),
dbesc($url)
);
// update existing hubloc record
- q("update hubloc set hubloc_guid = '%s', hubloc_network = 'activitypub', hubloc_url = '%s', hubloc_host = '%s', hubloc_callback = '%s', hubloc_updated = '%s', hubloc_id_url = '%s' where hubloc_hash = '%s'",
+ q("update hubloc set hubloc_guid = '%s', hubloc_addr = '%s', hubloc_network = 'activitypub', hubloc_url = '%s', hubloc_host = '%s', hubloc_callback = '%s', hubloc_updated = '%s', hubloc_id_url = '%s' where hubloc_hash = '%s'",
dbesc(escape_tags($url)),
+ dbesc(escape_tags($webfinger_addr)),
dbesc(escape_tags($baseurl)),
dbesc(escape_tags($hostname)),
dbesc(escape_tags($inbox)),
@@ -1736,7 +1775,7 @@ class Activity {
'xchan_hash' => escape_tags($url),
'xchan_guid' => escape_tags($url),
'xchan_pubkey' => escape_tags($pubkey),
- 'xchan_addr' => '',
+ 'xchan_addr' => $webfinger_addr,
'xchan_url' => escape_tags($profile),
'xchan_name' => escape_tags($name),
'xchan_name_date' => datetime_convert(),
@@ -1748,7 +1787,7 @@ class Activity {
[
'hubloc_guid' => escape_tags($url),
'hubloc_hash' => escape_tags($url),
- 'hubloc_addr' => '',
+ 'hubloc_addr' => $webfinger_addr,
'hubloc_network' => 'activitypub',
'hubloc_url' => escape_tags($baseurl),
'hubloc_host' => escape_tags($hostname),
@@ -1760,6 +1799,19 @@ class Activity {
);
}
+ // We store all ActivityPub actors we can resolve. Some of them may be able to communicate over Zot6. Find them.
+ // Adding zot discovery urls to the actor record will cause federation to fail with the 20-30 projects which don't accept arrays in the url field.
+
+ $actor_protocols = self::get_actor_protocols($person_obj);
+ if (in_array('zot6', $actor_protocols)) {
+ $zx = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6'",
+ dbesc($url)
+ );
+ if (!$zx && $webfinger_addr) {
+ Master::Summon(['Gprobe', bin2hex($webfinger_addr)]);
+ }
+ }
+
$photos = import_xchan_photo($icon, $url);
q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
dbescdate(datetime_convert('UTC', 'UTC', $photos[5])),
@@ -2063,6 +2115,7 @@ class Activity {
}
static function update_poll($item, $post) {
+
$multi = false;
$mid = $post['mid'];
$content = $post['title'];
@@ -2147,7 +2200,8 @@ class Activity {
dbesc(datetime_convert()),
intval($item['id'])
);
- Master::Summon(['Notifier', 'wall-new', $item['id']]);
+
+ Master::Summon(['Notifier', 'wall-new', $item['id'], $post['mid'] /* trick queueworker de-duplication */ ]);
return true;
}
@@ -2639,6 +2693,17 @@ class Activity {
// set the owner to the owner of the parent
$item['owner_xchan'] = $p[0]['owner_xchan'];
+ // quietly reject group comment boosts by group owner
+ // (usually only sent via ActivityPub so groups will work on microblog platforms)
+ // This catches those activities if they slipped in via a conversation fetch
+
+ if ($p[0]['parent_mid'] !== $item['parent_mid']) {
+ if ($item['verb'] === 'Announce' && $item['author_xchan'] === $item['owner_xchan']) {
+ logger('group boost activity by group owner rejected');
+ return;
+ }
+ }
+
// check permissions against the author, not the sender
$allowed = perm_is_allowed($channel['channel_id'], $item['author_xchan'], 'post_comments');
if ((!$allowed)/* && $permit_mentions*/) {
@@ -3633,4 +3698,24 @@ class Activity {
return $ret;
}
+
+
+ static function get_actor_protocols($actor) {
+ $ret = [];
+
+ if (!array_key_exists('tag', $actor) || empty($actor['tag']) || !is_array($actor['tag'])) {
+ return $ret;
+ }
+
+ foreach ($tag as $t) {
+ if ((isset($t['type']) && $t['type'] === 'PropertyValue') &&
+ (isset($t['name']) && $t['name'] === 'Protocol') &&
+ (isset($t['value']) && in_array($t['value'], ['zot6', 'activitypub', 'diaspora']))
+ ) {
+ $ret[] = $t['value'];
+ }
+ }
+
+ return $ret;
+ }
}