$n ? $fn($n) : $n, null); } public static function delete(string $id): void { @unlink(self::path($id)); } /** 投稿のURL(オブジェクトのID) */ public static function url(array $note): string { return Fedi::noteUrl($note['author'], $note['id']); } /** 投稿のページ(HTML) */ public static function htmlUrl(string $objectId): string { return Fedi::base().'/microblog/note?id='.rawurlencode($objectId); } /** * ActivityPubのNote */ public static function toObject(array $note): array { $url = self::url($note); $obj = [ '@context' => Fedi::CONTEXT, 'id' => $url, 'type' => 'Note', 'attributedTo' => Fedi::actorUrl($note['author']), 'content' => $note['content'], 'source' => ['content' => $note['source'], 'mediaType' => 'text/markdown'], 'to' => $note['to'], 'cc' => $note['cc'], 'published' => $note['published'], 'url' => self::htmlUrl($url), 'sensitive' => (bool)$note['sensitive'], 'tag' => $note['tags'], // 「path」は削除用の内部の項目なので外す 'attachment' => array_map(fn($a) => array_diff_key($a, ['path' => 1]), $note['attachments']), 'replies' => [ 'id' => "{$url}/replies", 'type' => 'Collection', 'totalItems' => count($note['replies'] ?? []), ], 'likes' => ['id' => "{$url}/likes", 'type' => 'Collection', 'totalItems' => count($note['likes'] ?? [])], 'shares' => ['id' => "{$url}/shares", 'type' => 'Collection', 'totalItems' => count($note['boosts'] ?? [])], ]; if (($note['summary'] ?? '') !== '') $obj['summary'] = $note['summary']; if (!empty($note['inReplyTo'])) $obj['inReplyTo'] = $note['inReplyTo']; if (!empty($note['updated'])) $obj['updated'] = $note['updated']; return $obj; } /** Createアクティビティ */ public static function toCreate(array $note): array { $obj = self::toObject($note); unset($obj['@context']); return [ '@context' => Fedi::CONTEXT, 'id' => self::url($note).'/activity', 'type' => 'Create', 'actor' => Fedi::actorUrl($note['author']), 'published' => $note['published'], 'to' => $note['to'], 'cc' => $note['cc'], 'object' => $obj, ]; } }