From f7be610629a32eaca5f5ca2d22f90b5b5eb9e63a Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 3 Sep 2022 13:32:41 +0000
Subject: [PATCH] Fix logger warmings/errors

---
 src/Protocol/ActivityPub/Processor.php   | 4 +++-
 src/Protocol/ActivityPub/Transmitter.php | 4 ++--
 src/Protocol/Diaspora.php                | 8 ++++----
 src/Worker/Notifier.php                  | 5 +++++
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index 5889d9f6e0..e16e2e9539 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -1966,7 +1966,9 @@ class Processor
 					$name = $tag['name'];
 				}
 
-				$body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body);
+				if (Network::isValidHttpUrl($tag['href'])) {
+					$body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body);
+				}
 			}
 
 			return $body;
diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php
index ba4baa267b..ce107414a6 100644
--- a/src/Protocol/ActivityPub/Transmitter.php
+++ b/src/Protocol/ActivityPub/Transmitter.php
@@ -648,7 +648,7 @@ class Transmitter
 		}
 
 		$parent = Post::selectFirst(['causer-link', 'post-reason'], ['id' => $item['parent']]);
-		if (($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
+		if (!empty($parent) && ($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
 			$profile = APContact::getByURL($parent['causer-link'], false);
 			$is_forum_thread = isset($profile['type']) && $profile['type'] == 'Group';
 		} else {
@@ -1610,7 +1610,7 @@ class Transmitter
 		$data['url'] = $link ?? $item['plink'];
 		$data['attributedTo'] = $item['author-link'];
 		$data['sensitive'] = self::isSensitive($item['uri-id']);
-		$data['conversation'] = $data['context'] = $item['conversation'];
+		$data['conversation'] = $data['context'] = ($item['conversation'] ?? '');
 
 		if (!empty($item['title'])) {
 			$data['name'] = BBCode::toPlaintext($item['title'], false);
diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php
index 45798cc579..886e1574dc 100644
--- a/src/Protocol/Diaspora.php
+++ b/src/Protocol/Diaspora.php
@@ -2001,11 +2001,11 @@ class Diaspora
 		Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
 
 		// Send all existing comments and likes to the requesting server
-		$comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb'],
+		$comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'],
 			['parent' => $toplevel_parent_item['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_ACTIVITY]]);
 		while ($comment = Post::fetch($comments)) {
-			if (in_array($comment['verb'], [Activity::FOLLOW, Activity::TAG])) {
-				Logger::info('participation messages are not relayed', ['item' => $comment['id']]);
+			if (($comment['gravity'] == GRAVITY_ACTIVITY) && !in_array($comment['verb'], [Activity::LIKE, Activity::DISLIKE])) {
+				Logger::info('Unsupported activities are not relayed', ['item' => $comment['id'], 'verb' => $comment['verb']]);
 				continue;
 			}
 
@@ -2020,7 +2020,7 @@ class Diaspora
 			}
 
 			Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $author_contact['cid']]);
-			if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $author_contact['cid'])) {
+			if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['uri-id'], $author_contact['cid'], $datarray['uid'])) {
 				Post\DeliveryData::incrementQueueCount($comment['uri-id'], 1);
 			}
 		}
diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php
index d06dfead61..7921097d4a 100644
--- a/src/Worker/Notifier.php
+++ b/src/Worker/Notifier.php
@@ -502,6 +502,11 @@ class Notifier
 		$a = DI::app();
 		$delivery_queue_count = 0;
 
+		if ($target_item['verb'] == Activity::ANNOUNCE) {
+			Logger::notice('Announces are only delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'uri' => $target_item['uri']]);
+			return 0;
+		}
+
 		foreach ($contacts as $contact) {
 			// Direct delivery of local contacts
 			if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::DELETION, Delivery::MAIL]) && $target_uid = User::getIdForURL($contact['url'])) {
-- 
2.39.5