2018-12-29 13:49:31 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2018-12-29 13:49:31 +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-29 13:49:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Interfaces\Internal;
|
|
|
|
|
2019-05-16 17:46:06 +00:00
|
|
|
use OCA\Social\Db\StreamRequest;
|
2022-04-15 16:13:33 +00:00
|
|
|
use OCA\Social\Interfaces\Activity\AbstractActivityPubInterface;
|
2018-12-29 13:49:31 +00:00
|
|
|
use OCA\Social\Interfaces\IActivityPubInterface;
|
|
|
|
use OCA\Social\Model\ActivityPub\ACore;
|
|
|
|
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
|
2019-07-03 15:46:09 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\Stream;
|
2018-12-29 13:49:31 +00:00
|
|
|
use OCA\Social\Service\MiscService;
|
|
|
|
|
2022-04-15 16:13:33 +00:00
|
|
|
class SocialAppNotificationInterface extends AbstractActivityPubInterface implements IActivityPubInterface {
|
2022-04-15 11:01:18 +00:00
|
|
|
private StreamRequest $streamRequest;
|
|
|
|
private MiscService $miscService;
|
2018-12-29 13:49:31 +00:00
|
|
|
|
2022-04-15 16:13:33 +00:00
|
|
|
public function __construct(StreamRequest $streamRequest, MiscService $miscService) {
|
2019-05-16 17:46:06 +00:00
|
|
|
$this->streamRequest = $streamRequest;
|
2018-12-29 13:49:31 +00:00
|
|
|
$this->miscService = $miscService;
|
|
|
|
}
|
|
|
|
|
2022-04-15 16:13:33 +00:00
|
|
|
public function save(ACore $item): void {
|
2019-01-02 17:07:42 +00:00
|
|
|
/** @var SocialAppNotification $notification */
|
2022-04-15 13:01:27 +00:00
|
|
|
$notification = $item;
|
2019-01-02 17:07:42 +00:00
|
|
|
if ($notification->getId() === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-28 12:53:06 +00:00
|
|
|
$notification->setPublished(date('c'));
|
2019-05-18 01:07:09 +00:00
|
|
|
$notification->convertPublished();
|
|
|
|
|
2019-06-20 23:59:40 +00:00
|
|
|
$this->miscService->log(
|
|
|
|
'Generating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1
|
|
|
|
);
|
2019-05-16 17:46:06 +00:00
|
|
|
$this->streamRequest->save($notification);
|
2018-12-29 13:49:31 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 16:13:33 +00:00
|
|
|
public function update(ACore $item): void {
|
2019-06-28 10:47:44 +00:00
|
|
|
/** @var SocialAppNotification $notification */
|
2022-04-15 13:01:27 +00:00
|
|
|
$notification = $item;
|
2019-06-28 10:47:44 +00:00
|
|
|
$this->miscService->log(
|
|
|
|
'Updating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1
|
|
|
|
);
|
2022-12-07 00:14:12 +00:00
|
|
|
$this->streamRequest->update($notification, true);
|
2018-12-29 13:49:31 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 16:13:33 +00:00
|
|
|
public function delete(ACore $item): void {
|
2019-07-03 15:46:09 +00:00
|
|
|
/** @var Stream $item */
|
2019-08-22 21:49:27 +00:00
|
|
|
$this->streamRequest->deleteById($item->getId(), SocialAppNotification::TYPE);
|
2018-12-29 13:49:31 +00:00
|
|
|
}
|
|
|
|
}
|