From: Art4 Date: Thu, 9 Jan 2025 20:30:39 +0000 (+0000) Subject: Extract handleToplevelParent into own method X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=53f046a74db949ca77706597dd2793be433e497d;p=friendica.git Extract handleToplevelParent into own method --- diff --git a/src/Model/Item.php b/src/Model/Item.php index 40fe7dbd42..fce67de4bf 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -949,50 +949,9 @@ class Item return 0; } - $parent_id = $toplevel_parent['id']; - $item['parent-uri'] = $toplevel_parent['uri']; - $item['parent-uri-id'] = $toplevel_parent['uri-id']; - $item['deleted'] = $toplevel_parent['deleted']; - $item['wall'] = $toplevel_parent['wall']; - - // Reshares have to keep their permissions to allow groups to work - if (!$defined_permissions && (!$item['origin'] || ($item['verb'] != Activity::ANNOUNCE))) { - // Don't store the permissions on pure AP posts - $store_permissions = ($item['network'] != Protocol::ACTIVITYPUB) || $item['origin'] || !empty($item['diaspora_signed_text']); - $item['allow_cid'] = $store_permissions ? $toplevel_parent['allow_cid'] : ''; - $item['allow_gid'] = $store_permissions ? $toplevel_parent['allow_gid'] : ''; - $item['deny_cid'] = $store_permissions ? $toplevel_parent['deny_cid'] : ''; - $item['deny_gid'] = $store_permissions ? $toplevel_parent['deny_gid'] : ''; - } - + $parent_id = (int) $toplevel_parent['id']; + $item = self::handleToplevelParent($item, $toplevel_parent, $defined_permissions); $parent_origin = $toplevel_parent['origin']; - - // Don't federate received participation messages - if ($item['verb'] != Activity::FOLLOW) { - $item['wall'] = $toplevel_parent['wall']; - } else { - $item['wall'] = false; - // Participations are technical messages, so they are set to "seen" automatically - $item['unseen'] = false; - } - - /* - * If the parent is private, force privacy for the entire conversation - * This differs from the above settings as it subtly allows comments from - * email correspondents to be private even if the overall thread is not. - */ - if (!$defined_permissions && $toplevel_parent['private']) { - $item['private'] = $toplevel_parent['private']; - } - - // If its a post that originated here then tag the thread as "mention" - if ($item['origin'] && $item['uid']) { - DBA::update('post-thread-user', ['mention' => true], ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]); - Logger::info('tagged thread as mention', ['parent' => $parent_id, 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]); - } - - // Update the contact relations - Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']); } else { $parent_id = 0; $parent_origin = $item['origin']; @@ -1504,6 +1463,54 @@ class Item return $item; } + private static function handleToplevelParent(array $item, array $toplevel_parent, bool $defined_permissions): array + { + $parent_id = (int) $toplevel_parent['id']; + $item['parent-uri'] = $toplevel_parent['uri']; + $item['parent-uri-id'] = $toplevel_parent['uri-id']; + $item['deleted'] = $toplevel_parent['deleted']; + $item['wall'] = $toplevel_parent['wall']; + + // Reshares have to keep their permissions to allow groups to work + if (!$defined_permissions && (!$item['origin'] || ($item['verb'] != Activity::ANNOUNCE))) { + // Don't store the permissions on pure AP posts + $store_permissions = ($item['network'] != Protocol::ACTIVITYPUB) || $item['origin'] || !empty($item['diaspora_signed_text']); + $item['allow_cid'] = $store_permissions ? $toplevel_parent['allow_cid'] : ''; + $item['allow_gid'] = $store_permissions ? $toplevel_parent['allow_gid'] : ''; + $item['deny_cid'] = $store_permissions ? $toplevel_parent['deny_cid'] : ''; + $item['deny_gid'] = $store_permissions ? $toplevel_parent['deny_gid'] : ''; + } + + // Don't federate received participation messages + if ($item['verb'] != Activity::FOLLOW) { + $item['wall'] = $toplevel_parent['wall']; + } else { + $item['wall'] = false; + // Participations are technical messages, so they are set to "seen" automatically + $item['unseen'] = false; + } + + /* + * If the parent is private, force privacy for the entire conversation + * This differs from the above settings as it subtly allows comments from + * email correspondents to be private even if the overall thread is not. + */ + if (!$defined_permissions && $toplevel_parent['private']) { + $item['private'] = $toplevel_parent['private']; + } + + // If its a post that originated here then tag the thread as "mention" + if ($item['origin'] && $item['uid']) { + DBA::update('post-thread-user', ['mention' => true], ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]); + Logger::info('tagged thread as mention', ['parent' => $parent_id, 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]); + } + + // Update the contact relations + Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']); + + return $item; + } + private static function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool { if (empty($restrictions) || ($author_id == $item['author-id'])) {