+ /**
+ * Test if incoming relay messages should be accepted
+ *
+ * @param array $activity activity array
+ * @param string $id object ID
+ * @return boolean true if message is accepted
+ */
+ private static function acceptIncomingMessage(array $activity, string $id)
+ {
+ if (empty($activity['as:object'])) {
+ Logger::info('No object field in activity - accepted', ['id' => $id]);
+ return true;
+ }
+
+ $replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
+ $uriid = ItemURI::getIdByURI($replyto);
+ if (Post::exists(['uri-id' => $uriid])) {
+ Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'uri-id' => $uriid, 'replyto' => $replyto]);
+ return true;
+ }
+
+ $attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
+ $authorid = Contact::getIdForURL($attributed_to);
+
+ $body = HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value'));
+
+ $messageTags = [];
+ $tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []);
+ if (!empty($tags)) {
+ foreach ($tags as $tag) {
+ if ($tag['type'] != 'Hashtag') {
+ continue;
+ }
+ $messageTags[] = ltrim(mb_strtolower($tag['name']), '#');
+ }
+ }
+
+ return Relay::isSolicitedPost($messageTags, $body, $authorid, $id, Protocol::ACTIVITYPUB);
+ }
+