X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FTransmitter.php;h=81b8bc1de310a98d6020adc559de339423868926;hb=fa1f48e1711c64d42ddb0f72c7670fa28f56482d;hp=1b36241ca90456c3ec0fce231235f64bc415c842;hpb=f3c2eb5b115928402648a8a9582b7cf44f184319;p=friendica.git diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 1b36241ca9..81b8bc1de3 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -21,6 +21,7 @@ use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Plaintext; +use Friendica\Util\XML; use Friendica\Util\JsonLD; use Friendica\Util\LDSignature; use Friendica\Model\Profile; @@ -435,12 +436,12 @@ class Transmitter $data['to'][] = $profile['url']; } else { $data['cc'][] = $profile['url']; - if (!$item['private']) { + if (!$item['private'] && !empty($actor_profile['followers'])) { $data['cc'][] = $actor_profile['followers']; } } } else { - // Public thread parent post always are directed to the followes + // Public thread parent post always are directed to the followers if (!$item['private'] && !$forum_mode) { $data['cc'][] = $actor_profile['followers']; } @@ -647,6 +648,12 @@ class Transmitter $reply = DBA::selectFirst('mail', ['uri'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]); + // Making the post more compatible for Mastodon by: + // - Making it a note and not an article (no title) + // - Moving the title into the "summary" field that is used as a "content warning" + $mail['body'] = '[abstract]' . $mail['title'] . "[/abstract]\n" . $mail['body']; + $mail['title'] = ''; + $mail['author-link'] = $mail['owner-link'] = $mail['from-url']; $mail['allow_cid'] = '<'.$mail['contact-id'].'>'; $mail['allow_gid'] = ''; @@ -766,6 +773,8 @@ class Transmitter $type = 'TentativeAccept'; } elseif ($item['verb'] == ACTIVITY_FOLLOW) { $type = 'Follow'; + } elseif ($item['verb'] == ACTIVITY_TAG) { + $type = 'Add'; } else { $type = ''; } @@ -869,6 +878,8 @@ class Transmitter if (in_array($data['type'], ['Create', 'Update', 'Delete'])) { $data['object'] = self::createNote($item); + } elseif ($data['type'] == 'Add') { + $data = self::createAddTag($item, $data); } elseif ($data['type'] == 'Announce') { $data = self::createAnnounce($item, $data); } elseif ($data['type'] == 'Follow') { @@ -1130,7 +1141,7 @@ class Transmitter { $event = []; $event['name'] = $item['event-summary']; - $event['content'] = BBCode::convert($item['event-desc'], false, 7); + $event['content'] = BBCode::convert($item['event-desc'], false, 9); $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM); if (!$item['event-nofinish']) { @@ -1220,7 +1231,7 @@ class Transmitter $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body); - $data['content'] = BBCode::convert($body, false, 7); + $data['content'] = BBCode::convert($body, false, 9); } $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; @@ -1245,6 +1256,30 @@ class Transmitter return $data; } + /** + * Creates an an "add tag" entry + * + * @param array $item + * @param array $data activity data + * + * @return array with activity data for adding tags + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private static function createAddTag($item, $data) + { + $object = XML::parseString($item['object'], false); + $target = XML::parseString($item["target"], false); + + $data['diaspora:guid'] = $item['guid']; + $data['actor'] = $item['author-link']; + $data['target'] = (string)$target->id; + $data['summary'] = BBCode::toPlaintext($item['body']); + $data['object'] = ['id' => (string)$object->id, 'type' => 'tag', 'name' => (string)$object->title, 'content' => (string)$object->content]; + + return $data; + } + /** * Creates an announce object entry * @@ -1532,13 +1567,16 @@ class Transmitter 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Accept', 'actor' => $owner['url'], - 'object' => ['id' => $id, 'type' => 'Follow', + 'object' => [ + 'id' => (string)$id, + 'type' => 'Follow', 'actor' => $profile['url'], - 'object' => $owner['url']], + 'object' => $owner['url'] + ], 'instrument' => self::getService(), 'to' => [$profile['url']]]; - Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG); + Logger::debug('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id); $signed = LDSignature::sign($data, $owner); HTTPSignature::transmit($signed, $profile['inbox'], $uid); @@ -1562,13 +1600,16 @@ class Transmitter 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Reject', 'actor' => $owner['url'], - 'object' => ['id' => $id, 'type' => 'Follow', + 'object' => [ + 'id' => (string)$id, + 'type' => 'Follow', 'actor' => $profile['url'], - 'object' => $owner['url']], + 'object' => $owner['url'] + ], 'instrument' => self::getService(), 'to' => [$profile['url']]]; - Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG); + Logger::debug('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id); $signed = LDSignature::sign($data, $owner); HTTPSignature::transmit($signed, $profile['inbox'], $uid);