| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-04-15 11:34:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-09-08 13:46:22 +00:00
										 |  |  |  * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors | 
					
						
							|  |  |  |  * SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace OCA\Social\Service; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Exception; | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | use OCA\Social\Db\StreamRequest; | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | use OCA\Social\Exceptions\InvalidOriginException; | 
					
						
							| 
									
										
										
										
											2018-12-29 14:07:57 +00:00
										 |  |  | use OCA\Social\Exceptions\InvalidResourceException; | 
					
						
							|  |  |  | use OCA\Social\Exceptions\ItemUnknownException; | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | use OCA\Social\Exceptions\RedundancyLimitException; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | use OCA\Social\Exceptions\SocialAppConfigException; | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | use OCA\Social\Exceptions\StreamNotFoundException; | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | use OCA\Social\Exceptions\UnauthorizedFediverseException; | 
					
						
							| 
									
										
										
										
											2018-12-19 19:55:54 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\ACore; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\Actor\Person; | 
					
						
							|  |  |  | use OCA\Social\Model\ActivityPub\Object\Note; | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\OrderedCollection; | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | use OCA\Social\Model\ActivityPub\Stream; | 
					
						
							| 
									
										
										
										
											2023-03-08 01:17:31 +00:00
										 |  |  | use OCA\Social\Model\Client\Options\ProbeOptions; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | use OCA\Social\Model\InstancePath; | 
					
						
							| 
									
										
										
										
											2022-11-18 20:13:02 +00:00
										 |  |  | use OCA\Social\Tools\Exceptions\DateTimeException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\MalformedArrayException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\RequestContentException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\RequestNetworkException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\RequestResultNotJsonException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\RequestResultSizeException; | 
					
						
							|  |  |  | use OCA\Social\Tools\Exceptions\RequestServerException; | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | use OCA\Social\Tools\Traits\TArrayTools; | 
					
						
							|  |  |  | use OCP\IURLGenerator; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | class StreamService { | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | 	use TArrayTools; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private IUrlGenerator $urlGenerator; | 
					
						
							| 
									
										
										
										
											2023-01-16 16:19:26 +00:00
										 |  |  | 	private StreamRequest $streamRequest; | 
					
						
							| 
									
										
										
										
											2022-04-15 11:01:18 +00:00
										 |  |  | 	private ActivityService $activityService; | 
					
						
							|  |  |  | 	private CacheActorService $cacheActorService; | 
					
						
							|  |  |  | 	private ConfigService $configService; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:21:02 +00:00
										 |  |  | 	private const ANCESTOR_LIMIT = 5; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public function __construct( | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | 		IUrlGenerator $urlGenerator, | 
					
						
							| 
									
										
										
										
											2023-01-16 16:19:26 +00:00
										 |  |  | 		StreamRequest $streamRequest, | 
					
						
							|  |  |  | 		ActivityService $activityService, | 
					
						
							|  |  |  | 		CacheActorService $cacheActorService, | 
					
						
							|  |  |  | 		ConfigService $configService | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | 		$this->urlGenerator = $urlGenerator; | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | 		$this->streamRequest = $streamRequest; | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		$this->activityService = $activityService; | 
					
						
							|  |  |  | 		$this->cacheActorService = $cacheActorService; | 
					
						
							|  |  |  | 		$this->configService = $configService; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param Person $viewer | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	public function setViewer(Person $viewer) { | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | 		$this->streamRequest->setViewer($viewer); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @param ACore $stream | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param Person $actor | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @param string $type | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @throws SocialAppConfigException | 
					
						
							| 
									
										
										
										
											2019-03-13 13:19:19 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-03-06 11:52:18 +00:00
										 |  |  | 	public function assignItem(Acore $stream, Person $actor, string $type) { | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 		$stream->setId($this->configService->generateId('@' . $actor->getPreferredUsername())); | 
					
						
							|  |  |  | 		$stream->setPublished(date("c")); | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 		$this->setRecipient($stream, $actor, $type); | 
					
						
							|  |  |  | 		$stream->setLocal(true); | 
					
						
							| 
									
										
										
										
											2019-03-13 13:19:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 		if ($stream instanceof Stream) { | 
					
						
							|  |  |  | 			$this->assignStream($stream); | 
					
						
							| 
									
										
										
										
											2019-03-13 13:19:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param Stream $stream | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-06-17 13:41:58 +00:00
										 |  |  | 	public function assignStream(Stream $stream) { | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 		$stream->convertPublished(); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @param ACore $stream | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * @param Person $actor | 
					
						
							|  |  |  | 	 * @param string $type | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	private function setRecipient(ACore $stream, Person $actor, string $type) { | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		switch ($type) { | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | 			case Stream::TYPE_UNLISTED: | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 				$stream->setTo($actor->getFollowers()); | 
					
						
							|  |  |  | 				$stream->addInstancePath( | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 					new InstancePath( | 
					
						
							|  |  |  | 						$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, | 
					
						
							|  |  |  | 						InstancePath::PRIORITY_LOW | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 				$stream->addCc(ACore::CONTEXT_PUBLIC); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | 			case Stream::TYPE_FOLLOWERS: | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 				$stream->setTo($actor->getFollowers()); | 
					
						
							|  |  |  | 				$stream->addInstancePath( | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 					new InstancePath( | 
					
						
							|  |  |  | 						$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, | 
					
						
							|  |  |  | 						InstancePath::PRIORITY_LOW | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | 			case Stream::TYPE_ANNOUNCE: | 
					
						
							|  |  |  | 				$stream->addInstancePath( | 
					
						
							|  |  |  | 					new InstancePath( | 
					
						
							|  |  |  | 						$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, | 
					
						
							|  |  |  | 						InstancePath::PRIORITY_LOW | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				$stream->addCc($actor->getFollowers()); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case Stream::TYPE_DIRECT: | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 				$stream->setTo(ACore::CONTEXT_PUBLIC); | 
					
						
							|  |  |  | 				$stream->addCc($actor->getFollowers()); | 
					
						
							|  |  |  | 				$stream->addInstancePath( | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 					new InstancePath( | 
					
						
							|  |  |  | 						$actor->getFollowers(), InstancePath::TYPE_FOLLOWERS, | 
					
						
							|  |  |  | 						InstancePath::PRIORITY_LOW | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param $stream | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function detectType(Stream $stream) { | 
					
						
							|  |  |  | 		if (in_array(ACore::CONTEXT_PUBLIC, $stream->getToAll())) { | 
					
						
							| 
									
										
										
										
											2019-08-15 13:56:29 +00:00
										 |  |  | 			$stream->setTimeline(Stream::TYPE_PUBLIC); | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (in_array(ACore::CONTEXT_PUBLIC, $stream->getCcArray())) { | 
					
						
							|  |  |  | 			$stream->setType(Stream::TYPE_UNLISTED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			$actor = $this->cacheActorService->getFromId($stream->getAttributedTo()); | 
					
						
							|  |  |  | 			echo json_encode($actor) . "\n"; | 
					
						
							|  |  |  | 		} catch (Exception $e) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param Stream $stream | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * @param string $type | 
					
						
							|  |  |  | 	 * @param string $account | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	public function addRecipient(Stream $stream, string $type, string $account) { | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		if ($account === '') { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2020-08-22 02:41:38 +00:00
										 |  |  | 			$actor = $this->cacheActorService->getFromAccount($account, true); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		} catch (Exception $e) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$instancePath = new InstancePath( | 
					
						
							|  |  |  | 			$actor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_MEDIUM | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | 		if ($type === Stream::TYPE_DIRECT) { | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 			$instancePath->setPriority(InstancePath::PRIORITY_HIGH); | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 			$stream->addToArray($actor->getId()); | 
					
						
							| 
									
										
										
										
											2020-08-22 02:41:38 +00:00
										 |  |  | 			$stream->setFilterDuplicate(true); // TODO: really needed ?
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 			$stream->addCc($actor->getId()); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 		$stream->addTag( | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 			[ | 
					
						
							|  |  |  | 				'type' => 'Mention', | 
					
						
							| 
									
										
										
										
											2019-01-02 23:31:25 +00:00
										 |  |  | 				'href' => $actor->getId(), | 
					
						
							|  |  |  | 				'name' => '@' . $account | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 		$stream->addInstancePath($instancePath); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 23:31:25 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Note $note | 
					
						
							|  |  |  | 	 * @param string $hashtag | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function addHashtag(Note $note, string $hashtag) { | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			$note->addTag( | 
					
						
							|  |  |  | 				[ | 
					
						
							|  |  |  | 					'type' => 'Hashtag', | 
					
						
							| 
									
										
										
										
											2023-01-16 16:19:26 +00:00
										 |  |  | 					'href' => $this->configService->getSocialUrl() . 'tag/' . strtolower($hashtag), | 
					
						
							| 
									
										
										
										
											2019-01-02 23:31:25 +00:00
										 |  |  | 					'name' => '#' . $hashtag | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} catch (SocialAppConfigException $e) { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param Stream $stream | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * @param string $type | 
					
						
							|  |  |  | 	 * @param array $accounts | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	public function addRecipients(Stream $stream, string $type, array $accounts) { | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		foreach ($accounts as $account) { | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 			$this->addRecipient($stream, $type, $account); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 23:31:25 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Note $note | 
					
						
							|  |  |  | 	 * @param array $hashtags | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function addHashtags(Note $note, array $hashtags) { | 
					
						
							| 
									
										
										
										
											2019-01-11 08:33:01 +00:00
										 |  |  | 		$note->setHashtags($hashtags); | 
					
						
							| 
									
										
										
										
											2019-01-02 23:31:25 +00:00
										 |  |  | 		foreach ($hashtags as $hashtag) { | 
					
						
							|  |  |  | 			$this->addHashtag($note, $hashtag); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Note $note | 
					
						
							|  |  |  | 	 * @param string $replyTo | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @throws InvalidOriginException | 
					
						
							|  |  |  | 	 * @throws InvalidResourceException | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | 	 * @throws ItemUnknownException | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 * @throws MalformedArrayException | 
					
						
							|  |  |  | 	 * @throws RedundancyLimitException | 
					
						
							| 
									
										
										
										
											2018-12-29 14:07:57 +00:00
										 |  |  | 	 * @throws RequestContentException | 
					
						
							|  |  |  | 	 * @throws RequestNetworkException | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | 	 * @throws RequestResultNotJsonException | 
					
						
							| 
									
										
										
										
											2018-12-29 14:07:57 +00:00
										 |  |  | 	 * @throws RequestResultSizeException | 
					
						
							|  |  |  | 	 * @throws RequestServerException | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 * @throws SocialAppConfigException | 
					
						
							| 
									
										
										
										
											2019-08-12 10:57:25 +00:00
										 |  |  | 	 * @throws StreamNotFoundException | 
					
						
							|  |  |  | 	 * @throws UnauthorizedFediverseException | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function replyTo(Note $note, string $replyTo) { | 
					
						
							|  |  |  | 		if ($replyTo === '') { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 		$author = $this->getAuthorFromPostId($replyTo); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		$note->setInReplyTo($replyTo); | 
					
						
							|  |  |  | 		// TODO - type can be NOT public !
 | 
					
						
							|  |  |  | 		$note->addInstancePath( | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 			new InstancePath( | 
					
						
							|  |  |  | 				$author->getSharedInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_HIGH | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-05-06 14:32:31 +00:00
										 |  |  | 	 * @param Stream $item | 
					
						
							| 
									
										
										
										
											2019-05-06 19:45:09 +00:00
										 |  |  | 	 * @param string $type | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @throws Exception | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-06 19:45:09 +00:00
										 |  |  | 	public function deleteLocalItem(Stream $item, string $type = '') { | 
					
						
							| 
									
										
										
										
											2019-05-06 14:32:31 +00:00
										 |  |  | 		if (!$item->isLocal()) { | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 14:32:31 +00:00
										 |  |  | 		$item->setActorId($item->getAttributedTo()); | 
					
						
							|  |  |  | 		$this->activityService->deleteActivity($item); | 
					
						
							| 
									
										
										
										
											2019-08-22 21:49:27 +00:00
										 |  |  | 		$this->streamRequest->deleteById($item->getId(), $type); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $id | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * @param bool $asViewer | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2019-05-06 08:29:07 +00:00
										 |  |  | 	 * @return Stream | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | 	 * @throws StreamNotFoundException | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-11-21 16:48:39 +00:00
										 |  |  | 	public function getStreamById( | 
					
						
							|  |  |  | 		string $id, | 
					
						
							|  |  |  | 		bool $asViewer = false, | 
					
						
							|  |  |  | 		int $format = ACore::FORMAT_ACTIVITYPUB | 
					
						
							|  |  |  | 	): Stream { | 
					
						
							|  |  |  | 		return $this->streamRequest->getStreamById($id, $asViewer, $format); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:21:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $nid | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return array | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-02-23 12:06:39 +00:00
										 |  |  | 	public function getContextByNid(int $nid): array { | 
					
						
							| 
									
										
										
										
											2023-03-09 12:21:02 +00:00
										 |  |  | 		$curr = $post = $this->streamRequest->getStreamByNid($nid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$ancestors = []; | 
					
						
							|  |  |  | 		for ($i = 0; $i < self::ANCESTOR_LIMIT; $i++) { | 
					
						
							|  |  |  | 			if ($curr->getInReplyTo() === '') { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-03 15:45:32 +00:00
										 |  |  | 			try { | 
					
						
							|  |  |  | 				$curr = $this->streamRequest->getStreamById($curr->getInReplyTo(), true); | 
					
						
							|  |  |  | 				$curr->setExportFormat(ACore::FORMAT_LOCAL); | 
					
						
							|  |  |  | 				$ancestors[] = $curr; | 
					
						
							|  |  |  | 			} catch (StreamNotFoundException $e) { | 
					
						
							|  |  |  | 				break; // ancestor might be out of range for viewer
 | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-03-09 12:21:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-23 12:06:39 +00:00
										 |  |  | 		return [ | 
					
						
							| 
									
										
										
										
											2023-03-09 12:21:02 +00:00
										 |  |  | 			'ancestors' => array_reverse($ancestors), | 
					
						
							|  |  |  | 			'descendants' => $this->streamRequest->getDescendants($post->getId()) | 
					
						
							| 
									
										
										
										
											2023-02-23 12:06:39 +00:00
										 |  |  | 		]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-17 09:22:37 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $id | 
					
						
							|  |  |  | 	 * @param bool $asViewer | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Stream | 
					
						
							|  |  |  | 	 * @throws StreamNotFoundException | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamByNid(int $nid): Stream { | 
					
						
							|  |  |  | 		return $this->streamRequest->getStreamByNid($nid); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $id | 
					
						
							| 
									
										
										
										
											2019-09-12 12:49:51 +00:00
										 |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | 	 * @param bool $asViewer | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Stream[] | 
					
						
							|  |  |  | 	 * @throws StreamNotFoundException | 
					
						
							| 
									
										
										
										
											2020-06-17 13:41:58 +00:00
										 |  |  | 	 * @throws DateTimeException | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | 	public function getRepliesByParentId( | 
					
						
							|  |  |  | 		string $id, | 
					
						
							|  |  |  | 		int $since = 0, | 
					
						
							|  |  |  | 		int $limit = 5, | 
					
						
							|  |  |  | 		bool $asViewer = false | 
					
						
							| 
									
										
										
										
											2020-06-17 13:41:58 +00:00
										 |  |  | 	): array { | 
					
						
							| 
									
										
										
										
											2019-09-12 12:49:51 +00:00
										 |  |  | 		return $this->streamRequest->getRepliesByParentId($id, $since, $limit, $asViewer); | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							| 
									
										
										
										
											2020-08-25 03:06:43 +00:00
										 |  |  | 	 * @param int $format | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2020-08-25 03:06:43 +00:00
										 |  |  | 	 * @throws DateTimeException | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2022-11-18 20:13:02 +00:00
										 |  |  | 	public function getStreamHome( | 
					
						
							|  |  |  | 		int $since = 0, | 
					
						
							|  |  |  | 		int $limit = 5, | 
					
						
							|  |  |  | 		int $format = Stream::FORMAT_ACTIVITYPUB | 
					
						
							| 
									
										
										
										
											2020-08-28 02:35:57 +00:00
										 |  |  | 	): array { | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineHome_dep($since, $limit, $format); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-03-08 01:17:31 +00:00
										 |  |  | 	 * @param ProbeOptions $options | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-03-08 01:17:31 +00:00
										 |  |  | 	public function getTimeline(ProbeOptions $options): array { | 
					
						
							| 
									
										
										
										
											2022-11-04 13:46:23 +00:00
										 |  |  | 		return $this->streamRequest->getTimeline($options); | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-06-17 13:41:58 +00:00
										 |  |  | 	public function getStreamNotifications(int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2022-12-03 16:55:34 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineNotifications_dep($since, $limit); | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $actorId | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2023-01-16 16:19:26 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineAccount_dep($actorId, $since, $limit); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-08 19:52:36 +00:00
										 |  |  | 	public function getStreamDirect(int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2022-11-18 20:13:02 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineDirect_dep($since, $limit); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2020-09-03 18:49:55 +00:00
										 |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2020-10-22 13:01:15 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineGlobal_dep($since, $limit, true); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 19:42:58 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $hashtag | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2019-01-04 19:42:58 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-01 10:18:20 +00:00
										 |  |  | 	public function getStreamLocalTag(string $hashtag, int $since = 0, int $limit = 5): array { | 
					
						
							|  |  |  | 		return $this->streamRequest->getTimelineTag($hashtag, $since, $limit); | 
					
						
							| 
									
										
										
										
											2019-01-04 19:42:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamInternalTimeline(int $since = 0, int $limit = 5): array { | 
					
						
							|  |  |  | 		// TODO - admin should be able to provide a list of 'friendly/internal' instance of ActivityPub
 | 
					
						
							|  |  |  | 		return []; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-19 10:59:15 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-02-23 00:04:00 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							| 
									
										
										
										
											2019-04-08 16:52:03 +00:00
										 |  |  | 	 * @throws Exception | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamGlobalTimeline(int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2020-10-22 13:01:15 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineGlobal_dep($since, $limit, false); | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-19 10:59:15 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param int $since | 
					
						
							|  |  |  | 	 * @param int $limit | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Note[] | 
					
						
							|  |  |  | 	 * @throws Exception | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getStreamLiked(int $since = 0, int $limit = 5): array { | 
					
						
							| 
									
										
										
										
											2019-07-20 19:21:26 +00:00
										 |  |  | 		return $this->streamRequest->getTimelineLiked($since, $limit); | 
					
						
							| 
									
										
										
										
											2019-07-19 10:59:15 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param $noteId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return Person | 
					
						
							| 
									
										
										
										
											2018-12-29 14:07:57 +00:00
										 |  |  | 	 * @throws InvalidOriginException | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 * @throws InvalidResourceException | 
					
						
							|  |  |  | 	 * @throws MalformedArrayException | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | 	 * @throws StreamNotFoundException | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 * @throws RedundancyLimitException | 
					
						
							| 
									
										
										
										
											2018-12-29 14:07:57 +00:00
										 |  |  | 	 * @throws SocialAppConfigException | 
					
						
							|  |  |  | 	 * @throws ItemUnknownException | 
					
						
							|  |  |  | 	 * @throws RequestContentException | 
					
						
							|  |  |  | 	 * @throws RequestNetworkException | 
					
						
							|  |  |  | 	 * @throws RequestResultSizeException | 
					
						
							|  |  |  | 	 * @throws RequestServerException | 
					
						
							| 
									
										
										
										
											2019-01-15 13:30:02 +00:00
										 |  |  | 	 * @throws RequestResultNotJsonException | 
					
						
							| 
									
										
										
										
											2019-06-20 23:59:40 +00:00
										 |  |  | 	 * @throws UnauthorizedFediverseException | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-01-04 23:38:23 +00:00
										 |  |  | 	public function getAuthorFromPostId(string $noteId) { | 
					
						
							| 
									
										
										
										
											2019-05-16 17:46:06 +00:00
										 |  |  | 		$note = $this->streamRequest->getStreamById($noteId); | 
					
						
							| 
									
										
										
										
											2018-12-19 01:13:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return $this->cacheActorService->getFromId($note->getAttributedTo()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-04-07 12:08:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param Person $actor | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return OrderedCollection | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getOutboxCollection(Person $actor): OrderedCollection { | 
					
						
							|  |  |  | 		$collection = new OrderedCollection(); | 
					
						
							|  |  |  | 		$collection->setId($actor->getOutbox()); | 
					
						
							|  |  |  | 		$collection->setTotalItems($this->getInt('post', $actor->getDetails('count'))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$link = $this->urlGenerator->linkToRouteAbsolute( | 
					
						
							|  |  |  | 			'social.ActivityPub.outbox', | 
					
						
							|  |  |  | 			['username' => $actor->getPreferredUsername()] | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$collection->setFirst($link . '?page=1'); | 
					
						
							|  |  |  | 		$collection->setLast($link . '?page=1&min_id=0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $collection; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-12-17 09:12:27 +00:00
										 |  |  | } |