2019-08-12 11:00:40 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2019-08-12 11:00:40 +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
|
2019-08-12 11:00:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Service;
|
|
|
|
|
2019-08-15 13:56:29 +00:00
|
|
|
use OC;
|
2019-08-12 11:00:40 +00:00
|
|
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
2023-05-25 20:45:28 +00:00
|
|
|
//use OC\Push\Model\Helper\PushCallback;
|
2019-08-15 13:56:29 +00:00
|
|
|
use OCA\Social\Exceptions\StreamNotFoundException;
|
2019-08-12 11:00:40 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCA\Social\Tools\Traits\TAsync;
|
2019-08-12 11:00:40 +00:00
|
|
|
use OCP\AppFramework\QueryException;
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2020-06-12 12:35:33 +00:00
|
|
|
//use OCP\Push\Exceptions\PushInstallException;
|
|
|
|
//use OCP\Push\IPushManager;
|
|
|
|
//use OCP\Push\Model\IPushWrapper;
|
2019-08-12 11:00:40 +00:00
|
|
|
|
2019-08-12 18:37:21 +00:00
|
|
|
|
2019-08-12 11:00:40 +00:00
|
|
|
/**
|
|
|
|
* Class PushService
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Service
|
|
|
|
*/
|
|
|
|
class PushService {
|
|
|
|
use TAsync;
|
|
|
|
|
2022-04-15 11:34:01 +00:00
|
|
|
private DetailsService $detailsService;
|
2022-04-15 11:01:18 +00:00
|
|
|
private StreamService $streamService;
|
|
|
|
private MiscService $miscService;
|
2019-08-12 11:00:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-22 12:04:25 +00:00
|
|
|
* PushService constructor.
|
2019-08-12 11:00:40 +00:00
|
|
|
*/
|
2019-08-15 13:56:29 +00:00
|
|
|
public function __construct(
|
2024-10-28 12:53:06 +00:00
|
|
|
DetailsService $detailsService, StreamService $streamService, MiscService $miscService,
|
2019-08-15 13:56:29 +00:00
|
|
|
) {
|
2019-08-12 11:00:40 +00:00
|
|
|
$this->detailsService = $detailsService;
|
2019-08-15 13:56:29 +00:00
|
|
|
$this->streamService = $streamService;
|
2019-08-12 11:00:40 +00:00
|
|
|
$this->miscService = $miscService;
|
|
|
|
|
2019-08-22 12:04:25 +00:00
|
|
|
// FIX ME: nc18/push
|
2023-05-25 20:45:28 +00:00
|
|
|
// if ($this->miscService->getNcVersion() >= 19) {
|
|
|
|
// try {
|
|
|
|
// $this->pushManager = OC::$server->query(IPushManager::class);
|
|
|
|
// } catch (QueryException $e) {
|
|
|
|
// $miscService->log('QueryException while loading IPushManager - ' . $e->getMessage());
|
|
|
|
// }
|
|
|
|
// }
|
2019-08-12 11:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-15 13:56:29 +00:00
|
|
|
* @param string $streamId
|
2019-08-12 11:00:40 +00:00
|
|
|
*/
|
2019-08-15 13:56:29 +00:00
|
|
|
public function onNewStream(string $streamId) {
|
2020-06-12 12:35:33 +00:00
|
|
|
return;
|
2023-05-25 20:45:28 +00:00
|
|
|
// if ($this->miscService->getNcVersion() < 19) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (!$this->pushManager->isAvailable()) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// $stream = $this->streamService->getStreamById($streamId);
|
|
|
|
// } catch (StreamNotFoundException $e) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// $pushHelper = $this->pushManager->getPushHelper();
|
|
|
|
// $details = $this->detailsService->generateDetailsFromStream($stream);
|
|
|
|
// } catch (PushInstallException $e) {
|
|
|
|
// return;
|
|
|
|
// } catch (SocialAppConfigException $e) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $home = array_map(
|
|
|
|
// function(Person $item): string {
|
|
|
|
// return $item->getUserId();
|
|
|
|
// }, $details->getHomeViewers()
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// $callback = new PushCallback('social', 'timeline.home');
|
|
|
|
// $callback->setPayloadSerializable($stream);
|
|
|
|
// $callback->addUsers($home);
|
|
|
|
// $pushHelper->toCallback($callback);
|
|
|
|
//
|
|
|
|
// $direct = array_map(
|
|
|
|
// function(Person $item): string {
|
|
|
|
// return $item->getUserId();
|
|
|
|
// }, $details->getDirectViewers()
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// $callback = new PushCallback('social', 'timeline.direct');
|
|
|
|
// $callback->addUsers($direct);
|
|
|
|
// $callback->setPayloadSerializable($stream);
|
|
|
|
// $pushHelper->toCallback($callback);
|
2019-08-12 11:00:40 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 12:16:23 +00:00
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * @param $userId
|
|
|
|
// *
|
|
|
|
// * @return IPushWrapper
|
|
|
|
// * @throws PushInstallException
|
|
|
|
// */
|
|
|
|
// public function testOnAccount(string $userId): IPushWrapper {
|
|
|
|
//// $pushHelper = $this->pushManager->getPushHelper();
|
|
|
|
////
|
|
|
|
//// return $pushHelper->test($userId);
|
|
|
|
// }
|
2019-08-12 11:00:40 +00:00
|
|
|
}
|