notification on boost

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/531/head
Maxence Lange 2019-06-28 09:47:44 -01:00
rodzic 45a068e9d2
commit 3343f6e9e4
5 zmienionych plików z 133 dodań i 12 usunięć

Wyświetl plik

@ -40,7 +40,6 @@ use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Interfaces\Internal\SocialAppNotificationInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;

Wyświetl plik

@ -129,9 +129,14 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
/**
* @param ACore $item
* @param ACore $notification
*/
public function update(ACore $item) {
public function update(ACore $notification) {
/** @var SocialAppNotification $notification */
$this->miscService->log(
'Updating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1
);
$this->streamRequest->update($notification);
}

Wyświetl plik

@ -32,17 +32,30 @@ namespace OCA\Social\Interfaces\Object;
use daita\MySmallPhpTools\Exceptions\CacheItemNotFoundException;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\AP;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Interfaces\Internal\SocialAppNotificationInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Undo;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Announce;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\StreamQueue;
@ -99,6 +112,15 @@ class AnnounceInterface implements IActivityPubInterface {
* @param ACore $item
*
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RedundancyLimitException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultNotJsonException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws UnauthorizedFediverseException
*/
public function activity(Acore $activity, ACore $item) {
$item->checkOrigin($activity->getId());
@ -148,6 +170,7 @@ class AnnounceInterface implements IActivityPubInterface {
* @throws Exception
*/
public function save(ACore $item) {
/** @var Announce $item */
try {
$knownItem =
@ -159,11 +182,12 @@ class AnnounceInterface implements IActivityPubInterface {
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$this->updateNotification($knownItem, $actor);
if (!$knownItem->hasCc($actor->getFollowers())) {
$knownItem->addCc($actor->getFollowers());
$this->streamRequest->update($knownItem);
}
} catch (StreamNotFoundException $e) {
$objectId = $item->getObjectId();
$item->addCacheItem($objectId);
@ -173,6 +197,7 @@ class AnnounceInterface implements IActivityPubInterface {
$item->getRequestToken(), StreamQueue::TYPE_CACHE, $item->getId()
);
}
}
@ -185,13 +210,29 @@ class AnnounceInterface implements IActivityPubInterface {
/**
* @param ACore $item
*
* @throws InvalidOriginException
* @throws InvalidResourceException
* @throws RedundancyLimitException
* @throws RequestContentException
* @throws RequestNetworkException
* @throws RequestResultNotJsonException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws UnauthorizedFediverseException
* @throws MalformedArrayException
*/
public function delete(ACore $item) {
try {
$knownItem =
$this->streamRequest->getStreamByObjectId($item->getObjectId(), Announce::TYPE);
$actor = $item->getActor();
if ($item->hasActor()) {
$actor = $item->getActor();
} else {
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$knownItem->removeCc($actor->getFollowers());
if (empty($knownItem->getCcArray())) {
@ -227,9 +268,71 @@ class AnnounceInterface implements IActivityPubInterface {
$this->streamRequest->updateAttributedTo($item->getId(), $to);
}
try {
if ($item->hasActor()) {
$actor = $item->getActor();
} else {
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$this->updateNotification($item, $actor);
} catch (Exception $e) {
}
break;
}
}
/**
* @param Stream $item
*
* @param Person $author
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function updateNotification(Stream $item, Person $author) {
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$notification = $this->streamRequest->getStreamByObjectId(
$item->getId(), SocialAppNotification::TYPE
);
$notification->addDetail('accounts', $author->getAccount());
$notificationInterface->update($notification);
} catch (StreamNotFoundException $e) {
try {
$post = $this->streamRequest->getStreamById($item->getObjectId());
} catch (StreamNotFoundException $e) {
return; // should not happens.
}
if (!$post->isLocal()) {
return;
}
/** @var SocialAppNotification $notification */
$notification = AP::$activityPub->getItemFromType(SocialAppNotification::TYPE);
// $notification->setDetail('url', '');
$notification->setDetailItem('post', $post);
$notification->addDetail('accounts', $author->getAccount());
$notification->setAttributedTo($author->getId())
->setId($item->getId() . '/notification')
->setSummary('{accounts} boosted your post')
->setObjectId($item->getId())
->setTo($item->getAttributedTo())
->setLocal(true);
$notificationInterface->save($notification);
}
}
}

Wyświetl plik

@ -53,7 +53,6 @@ use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Accept;
use OCA\Social\Model\ActivityPub\Activity\Reject;
use OCA\Social\Model\ActivityPub\Activity\Undo;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\InstancePath;
@ -147,7 +146,7 @@ class FollowInterface implements IActivityPubInterface {
$actor = $this->cacheActorService->getFromId($follow->getObjectId());
$this->accountService->cacheLocalActorDetailCount($actor);
$this->generateNotification($actor, $follow);
$this->generateNotification($follow);
} catch (Exception $e) {
$this->miscService->log(
'exception while confirmFollowRequest: ' . get_class($e) . ' - ' . $e->getMessage(),
@ -267,24 +266,29 @@ class FollowInterface implements IActivityPubInterface {
/**
* @param Person $actor
* @param Follow $follow
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function generateNotification(Person $actor, Follow $follow) {
private function generateNotification(Follow $follow) {
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$follower = $this->cacheActorService->getFromId($follow->getActorId());
} catch (Exception $e) {
return;
}
/** @var SocialAppNotification $notification */
$notification = AP::$activityPub->getItemFromType(SocialAppNotification::TYPE);
$notification->setDetail('account', $actor->getAccount());
$notification->setDetail('url', $actor->getId());
$notification->setDetail('url', $follower->getId());
$notification->setDetail('account', $follower->getAccount());
$notification->setAttributedTo($follow->getActorId())
->setId($follow->getId() . '/notification')
->setActorId($actor->getId())
->setActorId($follower->getId())
->setSummary('{account} is following you')
->setTo($follow->getObjectId())
->setLocal(true);

Wyświetl plik

@ -31,6 +31,8 @@ declare(strict_types=1);
namespace OCA\Social\Traits;
use OCA\Social\Model\ActivityPub\Item;
/**
* Trait TDetails
*
@ -89,6 +91,14 @@ trait TDetails {
$this->details[$detail] = $value;
}
/**
* @param string $detail
* @param Item $value
*/
public function setDetailItem(string $detail, Item $value) {
$this->details[$detail] = $value;
}
/**
* @param string $detail