From 213c8a6eeccc16c34d3a34229a810bd213837c56 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 25 Jan 2023 13:06:50 +0000 Subject: according to spec this should be id instead of href --- Zotlabs/Lib/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 1a1031909..940280572 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -595,9 +595,9 @@ class Activity { foreach ($item['term'] as $t) { switch ($t['ttype']) { case TERM_HASHTAG: - // href is required so if we don't have a url in the taxonomy, ignore it and keep going. + // id is required so if we don't have a url in the taxonomy, ignore it and keep going. if ($t['url']) { - $ret[] = ['type' => 'Hashtag', 'href' => $t['url'], 'name' => '#' . $t['term']]; + $ret[] = ['type' => 'Hashtag', 'id' => $t['url'], 'name' => '#' . $t['term']]; } break; -- cgit v1.2.3 From 7839b931f1ec66ea576593f58f7141e8097bb201 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 16 Feb 2023 13:12:22 +0100 Subject: make sure we provide a created timestamp for likes and remove the workaround which returned the wrong date format --- Zotlabs/Lib/Activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 940280572..68ac320ba 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -822,7 +822,8 @@ class Activity { ]; } - $ret['published'] = ((isset($i['created'])) ? datetime_convert('UTC', 'UTC', $i['created'], ATOM_TIME) : datetime_convert()); + $ret['published'] = datetime_convert('UTC', 'UTC', $i['created'], ATOM_TIME); + if (isset($i['created'], $i['edited']) && $i['created'] !== $i['edited']) { $ret['updated'] = datetime_convert('UTC', 'UTC', $i['edited'], ATOM_TIME); if ($ret['type'] === 'Create') { -- cgit v1.2.3 From 352713726414d2e1dac1c06040bedbb84bb77db6 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 22 Feb 2023 10:47:11 +0000 Subject: Activity: set xchan_pubforum if we deal with a group actor --- Zotlabs/Lib/Activity.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 68ac320ba..a17648147 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1691,6 +1691,8 @@ class Activity { } } + $group_actor = ($person_obj['type'] === 'Group'); + $r = q("select * from xchan join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s'", dbesc($url) ); @@ -1709,11 +1711,12 @@ class Activity { ); // update existing xchan record - q("update xchan set xchan_name = '%s', xchan_pubkey = '%s', xchan_addr = '%s', xchan_network = 'activitypub', xchan_name_date = '%s' where xchan_hash = '%s'", + q("update xchan set xchan_name = '%s', xchan_pubkey = '%s', xchan_addr = '%s', xchan_network = 'activitypub', xchan_name_date = '%s', xchan_pubforum = %d where xchan_hash = '%s'", dbesc(escape_tags($name)), dbesc(escape_tags($pubkey)), dbesc(escape_tags($webfinger_addr)), dbescdate(datetime_convert()), + intval($group_actor), dbesc($url) ); @@ -1740,7 +1743,8 @@ class Activity { 'xchan_url' => $profile, 'xchan_name' => escape_tags($name), 'xchan_name_date' => datetime_convert(), - 'xchan_network' => 'activitypub' + 'xchan_network' => 'activitypub', + 'xchan_pubforum' => intval($group_actor) ] ); @@ -2219,7 +2223,6 @@ class Activity { ) { return false; } - // Within our family of projects, Follow/Unfollow of a thread is an internal activity which should not be transmitted, // hence if we receive it - ignore or reject it. // Unfollow is not defined by ActivityStreams, which prefers Undo->Follow. -- cgit v1.2.3 From ca7bd4996403fac432f1594d8552c727c44b360a Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 22 Feb 2023 11:20:32 +0000 Subject: Activity: do not force new thread if the announce is from a group actor --- Zotlabs/Lib/Activity.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index a17648147..93432c5ee 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2518,7 +2518,11 @@ class Activity { if ($act->type === 'Announce') { $s['author_xchan'] = self::get_attributed_to_actor_url($act); $s['mid'] = $act->obj['id']; - $s['parent_mid'] = $act->obj['id']; + + // Do not force new thread if the announce is from a group actor + if ($act->actor['type'] !== 'Group') { + $s['parent_mid'] = $act->obj['id']; + } } // we will need a hook here to extract magnet links e.g. peertube -- cgit v1.2.3 From f032bcc5f2abccd66308e7eb9491d01d7382375b Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 27 Feb 2023 08:42:13 +0000 Subject: Default owner_xchan to $observer (sender) in Activity::store() - this is because in case where an announce holds a relayed activity we drop the announce and process the relayed activity only. In that case actor.id as set in Activity::decode_note() will not be the correct owner. In other cases actor.id and sender should be identical. --- Zotlabs/Lib/Activity.php | 1 + 1 file changed, 1 insertion(+) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 93432c5ee..dc868c93e 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2852,6 +2852,7 @@ class Activity { } $allowed = false; + $item['owner_xchan'] = $observer_hash; // TODO: not implemented // $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel,$item)); -- cgit v1.2.3 From da034045cc1bba74287b7c3e83f4a94ff5359150 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 2 Mar 2023 21:15:19 +0000 Subject: some work on bringing bang tags back for forums --- Zotlabs/Lib/Activity.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index dc868c93e..60284c56d 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -570,7 +570,12 @@ class Activity { break; case 'Mention': - $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])]; + $mention_type = substr($t['name'], 0, 1); + if ($mention_type === '!') { + $ret[] = ['ttype' => TERM_FORUM, 'url' => $t['href'], 'term' => escape_tags(substr($t['name'], 1))]; + } else { + $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])]; + } break; case 'Bookmark': @@ -605,6 +610,10 @@ class Activity { $ret[] = ['type' => 'Mention', 'href' => $t['url'], 'name' => '@' . $t['term']]; break; + case TERM_FORUM: + $ret[] = ['type' => 'Mention', 'href' => $t['url'], 'name' => '!' . $t['term']]; + break; + case TERM_BOOKMARK: $ret[] = ['type' => 'Bookmark', 'href' => $t['url'], 'name' => $t['term']]; break; @@ -936,7 +945,7 @@ class Activity { if (!$t['url']) { continue; } - if ($t['ttype'] == TERM_MENTION) { + if (in_array($t['ttype'], [TERM_MENTION, TERM_FORUM])) { $url = self::lookup_term_url($t['url']); $list[] = (($url) ? $url : $t['url']); } -- cgit v1.2.3 From ec3ba87f3a6cb9cda5f094bb1e62ed6b746f087f Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 3 Mar 2023 08:49:18 +0000 Subject: Revert "some work on bringing bang tags back for forums" This reverts commit da034045cc1bba74287b7c3e83f4a94ff5359150. --- Zotlabs/Lib/Activity.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 60284c56d..dc868c93e 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -570,12 +570,7 @@ class Activity { break; case 'Mention': - $mention_type = substr($t['name'], 0, 1); - if ($mention_type === '!') { - $ret[] = ['ttype' => TERM_FORUM, 'url' => $t['href'], 'term' => escape_tags(substr($t['name'], 1))]; - } else { - $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])]; - } + $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])]; break; case 'Bookmark': @@ -610,10 +605,6 @@ class Activity { $ret[] = ['type' => 'Mention', 'href' => $t['url'], 'name' => '@' . $t['term']]; break; - case TERM_FORUM: - $ret[] = ['type' => 'Mention', 'href' => $t['url'], 'name' => '!' . $t['term']]; - break; - case TERM_BOOKMARK: $ret[] = ['type' => 'Bookmark', 'href' => $t['url'], 'name' => $t['term']]; break; @@ -945,7 +936,7 @@ class Activity { if (!$t['url']) { continue; } - if (in_array($t['ttype'], [TERM_MENTION, TERM_FORUM])) { + if ($t['ttype'] == TERM_MENTION) { $url = self::lookup_term_url($t['url']); $list[] = (($url) ? $url : $t['url']); } -- cgit v1.2.3 From 972d6917ac9e23d4032f375e2aec8f1839581b06 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 3 Mar 2023 14:59:48 +0000 Subject: add fixme --- Zotlabs/Lib/Activity.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index dc868c93e..817d2851d 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1773,6 +1773,10 @@ class Activity { dbesc($url) ); if (!$zx) { + // FIXME: we might need to fetch and store this url immediately + // otherwise at least the first post of a yet unknown author might + // be stored with the activitypub url instead of the portable id. + // Another solution could be to fix the items after Gprobe has done its work. Master::Summon(['Gprobe', bin2hex($url)]); } } -- cgit v1.2.3 From 198751783623cdcd65701314a81e9c3b75b5dd2e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 9 Mar 2023 18:31:43 +0000 Subject: only set owner to observer if the item is not fetched otherwise the comment author could end up as owner --- Zotlabs/Lib/Activity.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 817d2851d..171c0150e 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2855,8 +2855,11 @@ class Activity { $is_child_node = true; } + if (empty($item['item_fetched'])) { + $item['owner_xchan'] = $observer_hash; + } + $allowed = false; - $item['owner_xchan'] = $observer_hash; // TODO: not implemented // $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel,$item)); @@ -2932,7 +2935,7 @@ class Activity { // The $item['item_fetched'] flag is set in fetch_and_store_parents(). // In this case we should check against author permissions because sender is not owner. - if (perm_is_allowed($channel['channel_id'], ((isset($item['item_fetched']) && $item['item_fetched']) ? $item['author_xchan'] : $observer_hash), 'send_stream') || $is_sys_channel) { + if (perm_is_allowed($channel['channel_id'], ((!empty($item['item_fetched'])) ? $item['author_xchan'] : $observer_hash), 'send_stream') || $is_sys_channel) { $allowed = true; } // TODO: not implemented @@ -3241,7 +3244,7 @@ class Activity { $item = $hookinfo['item']; if ($item) { - $item['item_fetched'] = 1; + $item['item_fetched'] = true; if (intval($channel['channel_system']) && intval($item['item_private'])) { $p = []; @@ -3355,7 +3358,7 @@ class Activity { return false; } - */ + static public function fetch_and_store_replies($channel, $arr) { logger('fetching replies'); @@ -3412,6 +3415,7 @@ class Activity { } } +*/ /* this is deprecated and not used anymore static function announce_note($channel, $observer_hash, $act) { -- cgit v1.2.3 From 7e4721e4c75a4dd480c6f7cc1a8d70507c6d1b97 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 14 Mar 2023 10:35:01 +0000 Subject: work around friendica img attachment has different href than body which results in duplicate images --- Zotlabs/Lib/Activity.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib/Activity.php') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 171c0150e..226f50636 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -700,6 +700,13 @@ class Activity { if (array_key_exists('name', $att) && $att['name']) { $entry['name'] = html2plain(purify_html($att['name']), 256); } + // Friendica attachments don't match the URL in the body. + // This makes it more difficult to detect image duplication in bb_attach() + // which adds images to plaintext microblog software. For these we need to examine both the + // url and image properties. + if (isset($att['image']) && is_string($att['image']) && isset($att['url']) && $att['image'] !== $att['url']) { + $entry['image'] = $att['image']; + } if ($entry) { $ret[] = $entry; } @@ -2601,13 +2608,13 @@ class Activity { if ($mps) { usort($mps,[ '\Zotlabs\Lib\Activity', 'vid_sort' ]); foreach ($mps as $m) { - if (intval($m['height']) < 500 && Activity::media_not_in_body($m['href'],$s['body'])) { + if (intval($m['height']) < 500 && self::media_not_in_body($m['href'],$s['body'])) { $s['body'] = $tag . $m['href'] . '[/video]' . "\r\n" . $s['body']; break; } } } - elseif (is_string($act->obj['url']) && Activity::media_not_in_body($act->obj['url'],$s['body'])) { + elseif (is_string($act->obj['url']) && self::media_not_in_body($act->obj['url'],$s['body'])) { $s['body'] = $tag . $act->obj['url'] . '[/video]' . "\r\n" . $s['body']; } @@ -3691,7 +3698,21 @@ class Activity { if ($a['type'] === 'image/svg+xml' && strpos($item['body'], '[/svg]')) { continue; } - if (self::media_not_in_body($a['href'], $item['body'])) { + // Friendica attachment weirdness + // Check both the attachment image and href since they can be different and the one in the href is a different link with different resolution. + // Otheriwse you'll get duplicated images + if (isset($a['image'])) { + if (self::media_not_in_body($a['image'], $item['body']) && self::media_not_in_body($a['href'], $item['body'])) { + if (isset($a['name']) && $a['name']) { + $alt = htmlspecialchars($a['name'], ENT_QUOTES); + $item['body'] = '[img=' . $a['href'] . ']' . $alt . '[/img]' . "\r\n" . $item['body']; + } else { + $item['body'] = '[img]' . $a['href'] . '[/img]' . "\r\n" . $item['body']; + } + } + continue; + } + elseif (self::media_not_in_body($a['href'], $item['body'])) { if (isset($a['name']) && $a['name']) { $alt = htmlspecialchars($a['name'], ENT_QUOTES); $item['body'] = '[img=' . $a['href'] . ']' . $alt . '[/img]' . "\r\n" . $item['body']; -- cgit v1.2.3