From 555856208ebbf09ce99333ffe118c6b145e4ae57 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 9 Sep 2020 16:54:18 +0000 Subject: [PATCH 1/3] Issue 9167: Adding more direction indicators --- include/conversation.php | 14 ++++++++------ view/theme/frio/templates/sub/direction.tpl | 4 ++++ view/theme/vier/templates/sub/direction.tpl | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 1d374c5ca..9af80e168 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -741,13 +741,15 @@ function conversation_fetch_comments($thread_items, $pinned) { $direction = ['direction' => 5, 'title' => DI::l10n()->t('%s commented on this.', $row['author-name'])]; } - if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) - && !Contact::isSharing($row['author-id'], $row['uid'])) { - if ($row['post-type'] == Item::PT_TAG) { - $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')]; + if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])) { + if (!Contact::isSharing($row['author-id'], $row['uid'])) { + if ($row['post-type'] == Item::PT_TAG) { + $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')]; + } + $parentlines[] = $lineno; + } else { + $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])]; } - - $parentlines[] = $lineno; } if ($row['gravity'] == GRAVITY_PARENT) { diff --git a/view/theme/frio/templates/sub/direction.tpl b/view/theme/frio/templates/sub/direction.tpl index 671272cd0..abcd51797 100644 --- a/view/theme/frio/templates/sub/direction.tpl +++ b/view/theme/frio/templates/sub/direction.tpl @@ -11,6 +11,10 @@ {{elseif $direction.direction == 5}} + {{elseif $direction.direction == 6}} + + {{elseif $direction.direction == 7}} + {{/if}} {{/if}} diff --git a/view/theme/vier/templates/sub/direction.tpl b/view/theme/vier/templates/sub/direction.tpl index 08f40c3a3..939623c1e 100644 --- a/view/theme/vier/templates/sub/direction.tpl +++ b/view/theme/vier/templates/sub/direction.tpl @@ -11,6 +11,10 @@ {{elseif $direction.direction == 5}} + {{elseif $direction.direction == 6}} + + {{elseif $direction.direction == 7}} + {{/if}} {{/if}} From d64c910f6970973fa12f9ba7c4aedd2977e08737 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 9 Sep 2020 16:55:14 +0000 Subject: [PATCH 2/3] Reworked receiver detection --- src/Protocol/ActivityPub/Receiver.php | 35 ++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index d59a5da0e..c7d3ac675 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -207,8 +207,6 @@ class Receiver $uid = self::getFirstUserFromReceivers($receivers); } - Logger::log('Receivers: ' . $uid . ' - ' . json_encode($receivers), Logger::DEBUG); - $object_id = JsonLD::fetchElement($activity, 'as:object', '@id'); if (empty($object_id)) { Logger::log('No object found', Logger::DEBUG); @@ -539,19 +537,7 @@ class Receiver $receivers['uid:-1'] = -1; } - if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) { - // This will most likely catch all OStatus connections to Mastodon - $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND] - , 'archive' => false, 'pending' => false]; - $contacts = DBA::select('contact', ['uid'], $condition); - while ($contact = DBA::fetch($contacts)) { - if ($contact['uid'] != 0) { - $receivers['uid:' . $contact['uid']] = $contact['uid']; - } - } - DBA::close($contacts); - } - + // Fetch the receivers for the public and the followers collection if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) { $receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags)); continue; @@ -599,12 +585,23 @@ class Receiver * @return array with receivers (user id) * @throws \Exception */ - public static function getReceiverForActor($actor, $tags) + private static function getReceiverForActor($actor, $tags) { $receivers = []; - $networks = Protocol::FEDERATED; - $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER], - 'network' => $networks, 'archive' => false, 'pending' => false]; + $basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER], + 'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false]; + + $condition = DBA::mergeConditions($basecondition, ['nurl' => Strings::normaliseLink($actor)]); + $contacts = DBA::select('contact', ['uid', 'rel'], $condition); + while ($contact = DBA::fetch($contacts)) { + if (self::isValidReceiverForActor($contact, $actor, $tags)) { + $receivers['uid:' . $contact['uid']] = $contact['uid']; + } + } + DBA::close($contacts); + + // The queries are split because of performance issues + $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?)", Strings::normaliseLink($actor), $actor]); $contacts = DBA::select('contact', ['uid', 'rel'], $condition); while ($contact = DBA::fetch($contacts)) { if (self::isValidReceiverForActor($contact, $actor, $tags)) { From 5c3cc76acffa20545a76061f38354855f7513385 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Sep 2020 20:03:14 +0200 Subject: [PATCH 3/3] Update include/conversation.php Co-authored-by: Hypolite Petovan --- include/conversation.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 9af80e168..4afc7c699 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -742,13 +742,14 @@ function conversation_fetch_comments($thread_items, $pinned) { } if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])) { - if (!Contact::isSharing($row['author-id'], $row['uid'])) { + if (Contact::isSharing($row['author-id'], $row['uid'])) { + $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])]; + } else { if ($row['post-type'] == Item::PT_TAG) { $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')]; } $parentlines[] = $lineno; - } else { - $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])]; + } }