Merge pull request #531 from nextcloud/feature/noid/notifications

new notification timeline
pull/598/head
Maxence Lange 2019-07-04 10:53:56 -01:00 zatwierdzone przez GitHub
commit 5ec02bf5f2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
21 zmienionych plików z 1223 dodań i 178 usunięć

Wyświetl plik

@ -43,7 +43,7 @@ use OCA\Social\Interfaces\Activity\CreateInterface;
use OCA\Social\Interfaces\Activity\DeleteInterface;
use OCA\Social\Interfaces\Actor\ServiceInterface;
use OCA\Social\Interfaces\Object\FollowInterface;
use OCA\Social\Interfaces\Activity\LikeInterface;
use OCA\Social\Interfaces\Object\LikeInterface;
use OCA\Social\Interfaces\Activity\RejectInterface;
use OCA\Social\Interfaces\Activity\RemoveInterface;
use OCA\Social\Interfaces\Activity\UndoInterface;
@ -63,7 +63,7 @@ use OCA\Social\Model\ActivityPub\Activity\Create;
use OCA\Social\Model\ActivityPub\Activity\Delete;
use OCA\Social\Model\ActivityPub\Actor\Service;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\ActivityPub\Activity\Like;
use OCA\Social\Model\ActivityPub\Object\Like;
use OCA\Social\Model\ActivityPub\Activity\Reject;
use OCA\Social\Model\ActivityPub\Activity\Remove;
use OCA\Social\Model\ActivityPub\Activity\Undo;

Wyświetl plik

@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools;
use DateTime;
use Exception;
use OCA\Social\Exceptions\ActionDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Like;
use OCP\DB\QueryBuilder\IQueryBuilder;
/**
* Class ActionsRequest
*
* @package OCA\Social\Db
*/
class ActionsRequest extends ActionsRequestBuilder {
use TArrayTools;
/**
* Insert a new Note in the database.
*
* @param ACore $like
*/
public function save(ACore $like) {
$qb = $this->getActionsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($like->getId()))
->setValue('actor_id', $qb->createNamedParameter($like->getActorId()))
->setValue('type', $qb->createNamedParameter($like->getType()))
->setValue('object_id', $qb->createNamedParameter($like->getObjectId()));
try {
$qb->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
} catch (Exception $e) {
}
$this->generatePrimaryKey($qb, $like->getId());
$qb->execute();
}
/**
* @param string $actorId
* @param string $objectId
*
* @param string $type
*
* @return ACore
* @throws ActionDoesNotExistException
*/
public function getAction(string $actorId, string $objectId, string $type): ACore {
$qb = $this->getActionsSelectSql();
$this->limitToActorId($qb, $actorId);
$this->limitToObjectId($qb, $objectId);
$this->limitToType($qb, $type);
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
throw new ActionDoesNotExistException();
}
return $this->parseActionsSelectSql($data);
}
/**
* @param string $objectId
* @param string $type
*
* @return int
*/
public function countActions(string $objectId, string $type): int {
$qb = $this->countActionsSelectSql();
$this->limitToObjectId($qb, $objectId);
$this->limitToType($qb, $type);
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
return $this->getInt('count', $data, 0);
}
/**
* @param string $objectId
*
* @return Like[]
*/
public function getByObjectId(string $objectId): array {
$qb = $this->getActionsSelectSql();
$this->limitToObjectId($qb, $objectId);
$this->leftJoinCacheActors($qb, 'actor_id');
$likes = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$likes[] = $this->parseActionsSelectSql($data);
}
$cursor->closeCursor();
return $likes;
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
$qb = $this->getActionsDeleteSql();
$this->limitToIdString($qb, $item->getId());
$qb->execute();
}
/**
* @param string $objectId
*/
public function deleteLikes(string $objectId) {
$qb = $this->getActionsDeleteSql();
$this->limitToObjectId($qb, $objectId);
$qb->execute();
}
}

Wyświetl plik

@ -0,0 +1,145 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\ACore;
use OCP\DB\QueryBuilder\IQueryBuilder;
/**
* Class ActionsRequestBuilder
*
* @package OCA\Social\Db
*/
class ActionsRequestBuilder extends CoreRequestBuilder {
use TArrayTools;
/**
* Base of the Sql Insert request
*
* @return IQueryBuilder
*/
protected function getActionsInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert(self::TABLE_ACTIONS);
return $qb;
}
/**
* Base of the Sql Update request
*
* @return IQueryBuilder
*/
protected function getActionsUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->update(self::TABLE_ACTIONS);
return $qb;
}
/**
* Base of the Sql Select request for Shares
*
* @return IQueryBuilder
*/
protected function getActionsSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select('a.id', 'a.type', 'a.actor_id', 'a.object_id', 'a.creation')
->from(self::TABLE_ACTIONS, 'a');
$this->defaultSelectAlias = 'a';
return $qb;
}
/**
* Base of the Sql Select request for Shares
*
* @return IQueryBuilder
*/
protected function countActionsSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')
->from(self::TABLE_ACTIONS, 'a');
$this->defaultSelectAlias = 'a';
return $qb;
}
/**
* Base of the Sql Delete request
*
* @return IQueryBuilder
*/
protected function getActionsDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_ACTIONS);
return $qb;
}
/**
* @param array $data
*
* @return ACore
*/
protected function parseActionsSelectSql($data): ACore {
$item = new ACore();
$item->importFromDatabase($data);
try {
$actor = $this->parseCacheActorsLeftJoin($data);
$actor->setCompleteDetails(true);
$item->setActor($actor);
} catch (InvalidResourceException $e) {
}
return $item;
}
}

Wyświetl plik

@ -76,6 +76,7 @@ class CoreRequestBuilder {
const TABLE_STREAMS = 'social_a2_stream';
const TABLE_HASHTAGS = 'social_a2_hashtags';
const TABLE_FOLLOWS = 'social_a2_follows';
const TABLE_ACTIONS = 'social_a2_actions';
const TABLE_CACHE_ACTORS = 'social_a2_cache_actors';
const TABLE_CACHE_DOCUMENTS = 'social_a2_cache_documts';
@ -200,6 +201,26 @@ class CoreRequestBuilder {
}
/**
* Limit the request to the sub-type
*
* @param IQueryBuilder $qb
* @param string $subType
*/
protected function limitToSubType(IQueryBuilder &$qb, string $subType) {
$this->limitToDBField($qb, 'subtype', $subType);
}
/**
* @param IQueryBuilder $qb
* @param string $type
*/
protected function filterType(IQueryBuilder $qb, string $type) {
$this->filterDBField($qb, 'type', $type);
}
/**
* Limit the request to the Preferred Username
*
@ -484,14 +505,29 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param string $field
* @param string $value
* @param bool $eq
* @param bool $cs - case sensitive
* @param string $alias
*/
protected function filterDBField(
IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = ''
) {
$expr = $this->exprLimitToDBField($qb, $field, $value, false, $cs, $alias);
$qb->andWhere($expr);
}
/**
* @param IQueryBuilder $qb
* @param string $field
* @param string $value
* @param bool $eq - true = limit, false = filter
* @param bool $cs
* @param string $alias
*
* @return string
*/
protected function exprLimitToDBField(
IQueryBuilder &$qb, string $field, string $value, bool $eq = true, bool $cs = true,
IQueryBuilder &$qb, string $field, string $value, bool $eq, bool $cs = true,
string $alias = ''
): string {
$expr = $qb->expr();
@ -502,9 +538,8 @@ class CoreRequestBuilder {
}
$field = $pf . $field;
if ($eq) {
$comp = 'eq';
} else {
$comp = 'eq';
if (!$eq) {
$comp = 'neq';
}

Wyświetl plik

@ -42,6 +42,7 @@ use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
@ -213,15 +214,16 @@ class StreamRequest extends StreamRequestBuilder {
/**
* @param string $type
* @param string $objectId
* @param string $type
* @param string $subType
*
* @return Stream
* @throws StreamNotFoundException
* @throws ItemUnknownException
* @throws SocialAppConfigException
* @throws StreamNotFoundException
*/
public function getStreamByObjectId(string $objectId, string $type): Stream {
public function getStreamByObjectId(string $objectId, string $type, string $subType = ''): Stream {
if ($objectId === '') {
throw new StreamNotFoundException('missing objectId');
};
@ -229,6 +231,7 @@ class StreamRequest extends StreamRequestBuilder {
$qb = $this->getStreamSelectSql();
$this->limitToObjectId($qb, $objectId);
$this->limitToType($qb, $type);
$this->limitToSubType($qb, $subType);
$cursor = $qb->execute();
$data = $cursor->fetch();
@ -321,6 +324,7 @@ class StreamRequest extends StreamRequestBuilder {
$this->limitPaginate($qb, $since, $limit);
$this->limitToRecipient($qb, $actor->getId(), false);
$this->limitToType($qb, SocialAppNotification::TYPE);
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@ -394,6 +398,7 @@ class StreamRequest extends StreamRequestBuilder {
$this->limitToRecipient($qb, $actor->getId(), true);
$this->filterRecipient($qb, ACore::CONTEXT_PUBLIC);
$this->filterRecipient($qb, $actor->getFollowers());
$this->filterType($qb, SocialAppNotification::TYPE);
// $this->filterHiddenOnTimeline($qb);
$this->leftJoinCacheActors($qb, 'attributed_to');
@ -577,6 +582,7 @@ class StreamRequest extends StreamRequestBuilder {
$qb = $this->getStreamInsertSql();
$qb->setValue('id', $qb->createNamedParameter($stream->getId()))
->setValue('type', $qb->createNamedParameter($stream->getType()))
->setValue('subtype', $qb->createNamedParameter($stream->getSubType()))
->setValue('to', $qb->createNamedParameter($stream->getTo()))
->setValue(
'to_array', $qb->createNamedParameter(

Wyświetl plik

@ -97,7 +97,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
's.type', 's.to', 's.to_array', 's.cc', 's.bcc', 's.content',
's.summary', 's.attachments', 's.published', 's.published_time', 's.cache',
's.object_id', 's.attributed_to', 's.in_reply_to', 's.source', 's.local',
's.instances', 's.creation', 's.hidden_on_timeline'
's.instances', 's.creation', 's.hidden_on_timeline', 's.details'
)
->from(self::TABLE_STREAMS, 's');
@ -244,9 +244,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
// all possible follow, but linked by followers (actor_id) and accepted follow
$crossFollows = $expr->andX();
$crossFollows->add($recipientFields);
$crossFollows->add(
$this->exprLimitToDBField($qb, 'actor_id', $actor->getId(), true, false, 'f')
);
$crossFollows->add($this->exprLimitToDBField($qb, 'actor_id', $actor->getId(),true, false, 'f'));
$crossFollows->add($this->exprLimitToDBFieldInt($qb, 'accepted', 1, 'f'));
$on->add($crossFollows);

Wyświetl plik

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Exceptions;
use Exception;
class ActionDoesNotExistException extends Exception {
}

Wyświetl plik

@ -1,130 +0,0 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
class LikeInterface implements IActivityPubInterface {
/** @var MiscService */
private $miscService;
/**
* LikeService constructor.
*
* @param MiscService $miscService
*/
public function __construct(MiscService $miscService) {
$this->miscService = $miscService;
}
/**
* @param ACore $item
*/
public function processIncomingRequest(ACore $item) {
if (!$item->gotObject()) {
return;
}
$object = $item->getObject();
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
} catch (ItemUnknownException $e) {
}
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
}
/**
* @param string $id
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
throw new ItemNotFoundException();
}
/**
* @param ACore $item
*/
public function save(ACore $item) {
}
/**
* @param ACore $item
*/
public function update(ACore $item) {
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
}
/**
* @param ACore $item
* @param string $source
*/
public function event(ACore $item, string $source) {
}
/**
* @param ACore $activity
* @param ACore $item
*/
public function activity(ACore $activity, ACore $item) {
}
}

Wyświetl plik

@ -36,6 +36,7 @@ use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\CurlService;
use OCA\Social\Service\MiscService;
@ -129,9 +130,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);
}
@ -139,6 +145,8 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
* @param ACore $item
*/
public function delete(ACore $item) {
/** @var Stream $item */
$this->streamRequest->deleteStreamById($item->getId(), SocialAppNotification::TYPE);
}

Wyświetl plik

@ -32,17 +32,32 @@ 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\ActionsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\ActionDoesNotExistException;
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;
@ -65,6 +80,9 @@ class AnnounceInterface implements IActivityPubInterface {
/** @var StreamRequest */
private $streamRequest;
/** @var ActionsRequest */
private $actionsRequest;
/** @var StreamQueueService */
private $streamQueueService;
@ -79,15 +97,18 @@ class AnnounceInterface implements IActivityPubInterface {
* AnnounceInterface constructor.
*
* @param StreamRequest $streamRequest
* @param ActionsRequest $actionsRequest
* @param StreamQueueService $streamQueueService
* @param CacheActorService $cacheActorService
* @param MiscService $miscService
*/
public function __construct(
StreamRequest $streamRequest, StreamQueueService $streamQueueService,
CacheActorService $cacheActorService, MiscService $miscService
StreamRequest $streamRequest, ActionsRequest $actionsRequest,
StreamQueueService $streamQueueService, CacheActorService $cacheActorService,
MiscService $miscService
) {
$this->streamRequest = $streamRequest;
$this->actionsRequest = $actionsRequest;
$this->streamQueueService = $streamQueueService;
$this->cacheActorService = $cacheActorService;
$this->miscService = $miscService;
@ -96,16 +117,27 @@ class AnnounceInterface implements IActivityPubInterface {
/**
* @param ACore $activity
* @param ACore $item
* @param ACore $announce
*
* @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());
public function activity(Acore $activity, ACore $announce) {
/** @var Announce $announce */
if ($activity->getType() === Undo::TYPE) {
$item->checkOrigin($item->getId());
$this->delete($item);
$activity->checkOrigin($announce->getId());
$activity->checkOrigin($announce->getActorId());
$this->undoAnnounceAction($announce);
$this->delete($announce);
}
}
@ -120,6 +152,7 @@ class AnnounceInterface implements IActivityPubInterface {
/** @var Stream $item */
$item->checkOrigin($item->getId());
$this->actionsRequest->save($item);
$this->save($item);
}
@ -148,6 +181,7 @@ class AnnounceInterface implements IActivityPubInterface {
* @throws Exception
*/
public function save(ACore $item) {
/** @var Announce $item */
try {
$knownItem =
@ -163,7 +197,15 @@ class AnnounceInterface implements IActivityPubInterface {
$knownItem->addCc($actor->getFollowers());
$this->streamRequest->update($knownItem);
}
try {
$post = $this->streamRequest->getStreamById($item->getObjectId());
} catch (StreamNotFoundException $e) {
return; // should not happens.
}
$this->updateDetails($post);
$this->generateNotification($post, $actor);
} catch (StreamNotFoundException $e) {
$objectId = $item->getObjectId();
$item->addCacheItem($objectId);
@ -173,6 +215,7 @@ class AnnounceInterface implements IActivityPubInterface {
$item->getRequestToken(), StreamQueue::TYPE_CACHE, $item->getId()
);
}
}
@ -185,13 +228,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 +286,140 @@ class AnnounceInterface implements IActivityPubInterface {
$this->streamRequest->updateAttributedTo($item->getId(), $to);
}
try {
if ($item->hasActor()) {
$actor = $item->getActor();
} else {
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$post = $this->streamRequest->getStreamById($item->getObjectId());
$this->updateDetails($post);
$this->generateNotification($post, $actor);
} catch (Exception $e) {
}
break;
}
}
/**
* @param Announce $announce
*/
private function undoAnnounceAction(Announce $announce) {
try {
$this->actionsRequest->getAction(
$announce->getActorId(), $announce->getObjectId(), Announce::TYPE
);
$this->actionsRequest->delete($announce);
} catch (ActionDoesNotExistException $e) {
}
try {
if ($announce->hasActor()) {
$actor = $announce->getActor();
} else {
$actor = $this->cacheActorService->getFromId($announce->getActorId());
}
$post = $this->streamRequest->getStreamById($announce->getObjectId());
$this->updateDetails($post);
$this->cancelNotification($post, $actor);
} catch (Exception $e) {
}
}
/**
* @param Stream $post
*/
private function updateDetails(Stream $post) {
if (!$post->isLocal()) {
return;
}
$post->setDetailInt(
'boosts', $this->actionsRequest->countActions($post->getId(), Announce::TYPE)
);
$this->streamRequest->update($post);
}
/**
* @param Stream $post
* @param Person $author
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function generateNotification(Stream $post, Person $author) {
if (!$post->isLocal()) {
return;
}
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$notification = $this->streamRequest->getStreamByObjectId(
$post->getId(), SocialAppNotification::TYPE, Announce::TYPE
);
$notification->addDetail('accounts', $author->getAccount());
$notificationInterface->update($notification);
} catch (StreamNotFoundException $e) {
/** @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())
->setSubType(Announce::TYPE)
->setId($post->getId() . '/notification+boost')
->setSummary('{accounts} boosted your post')
->setObjectId($post->getId())
->setTo($post->getAttributedTo())
->setLocal(true);
$notificationInterface->save($notification);
}
}
/**
* @param Stream $post
* @param Person $author
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function cancelNotification(Stream $post, Person $author) {
if (!$post->isLocal()) {
return;
}
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$notification = $this->streamRequest->getStreamByObjectId(
$post->getId(), SocialAppNotification::TYPE, Announce::TYPE
);
$notification->removeDetail('accounts', $author->getAccount());
if (empty($notification->getDetails('accounts'))) {
$notificationInterface->delete($notification);
} else {
$notificationInterface->update($notification);
}
} catch (StreamNotFoundException $e) {
}
}
}

Wyświetl plik

@ -276,11 +276,22 @@ class FollowInterface implements IActivityPubInterface {
$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('url', $follower->getId());
$notification->setDetail('account', $follower->getAccount());
$notification->setDetailItem('actor', $follower);
$notification->setAttributedTo($follow->getActorId())
->setId($follow->getId() . '/notification')
->setSummary('{actor} is following you')
->setSubType(Follow::TYPE)
->setActorId($follower->getId())
->setSummary('{account} is following you')
->setTo($follow->getObjectId())
->setLocal(true);

Wyświetl plik

@ -0,0 +1,304 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Interfaces\Object;
use Exception;
use OCA\Social\AP;
use OCA\Social\Db\ActionsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\ActionDoesNotExistException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
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\Like;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\MiscService;
/**
* Class LikeInterface
*
* @package OCA\Social\Interfaces\Object
*/
class LikeInterface implements IActivityPubInterface {
/** @var ActionsRequest */
private $actionsRequest;
/** @var StreamRequest */
private $streamRequest;
/** @var CacheActorService */
private $cacheActorService;
/** @var MiscService */
private $miscService;
/**
* LikeService constructor.
*
* @param ActionsRequest $actionsRequest
* @param StreamRequest $streamRequest
* @param CacheActorService $cacheActorService
* @param MiscService $miscService
*/
public function __construct(
ActionsRequest $actionsRequest, StreamRequest $streamRequest,
CacheActorService $cacheActorService, MiscService $miscService
) {
$this->actionsRequest = $actionsRequest;
$this->streamRequest = $streamRequest;
$this->cacheActorService = $cacheActorService;
$this->miscService = $miscService;
}
/**
* @param ACore $like
*
* @throws InvalidOriginException
*/
public function processIncomingRequest(ACore $like) {
/** @var Like $like */
$like->checkOrigin($like->getActorId());
try {
$this->actionsRequest->getAction($like->getActorId(), $like->getObjectId(), Like::TYPE);
} catch (ActionDoesNotExistException $e) {
$this->actionsRequest->save($like);
try {
if ($like->hasActor()) {
$actor = $like->getActor();
} else {
$actor = $this->cacheActorService->getFromId($like->getActorId());
}
$post = $this->streamRequest->getStreamById($like->getObjectId());
$this->updateDetails($post);
$this->generateNotification($post, $actor);
} catch (Exception $e) {
}
}
}
/**
* @param ACore $activity
* @param ACore $like
*
* @throws InvalidOriginException
*/
public function activity(ACore $activity, ACore $like) {
/** @var Like $like */
if ($activity->getType() === Undo::TYPE) {
$activity->checkOrigin($like->getId());
$activity->checkOrigin($like->getActorId());
$this->undoLike($like);
}
}
/**
* @param ACore $item
*/
public function processResult(ACore $item) {
}
/**
* @param string $id
*
* @return ACore
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
throw new ItemNotFoundException();
}
/**
* @param ACore $item
*/
public function save(ACore $item) {
}
/**
* @param ACore $item
*/
public function update(ACore $item) {
}
/**
* @param ACore $item
*/
public function delete(ACore $item) {
}
/**
* @param ACore $item
* @param string $source
*/
public function event(ACore $item, string $source) {
}
/**
* @param Like $like
*/
private function undoLike(Like $like) {
try {
$this->actionsRequest->getAction($like->getActorId(), $like->getObjectId(), Like::TYPE);
$this->actionsRequest->delete($like);
} catch (ActionDoesNotExistException $e) {
}
try {
if ($like->hasActor()) {
$actor = $like->getActor();
} else {
$actor = $this->cacheActorService->getFromId($like->getActorId());
}
$post = $this->streamRequest->getStreamById($like->getObjectId());
$this->updateDetails($post);
$this->cancelNotification($post, $actor);
} catch (Exception $e) {
}
}
/**
* @param Stream $post
*/
private function updateDetails(Stream $post) {
if (!$post->isLocal()) {
return;
}
$post->setDetailInt(
'likes', $this->actionsRequest->countActions($post->getId(), Like::TYPE)
);
$this->streamRequest->update($post);
}
/**
* @param Stream $post
* @param Person $author
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function generateNotification(Stream $post, Person $author) {
if (!$post->isLocal()) {
return;
}
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$notification = $this->streamRequest->getStreamByObjectId(
$post->getId(), SocialAppNotification::TYPE, Like::TYPE
);
$notification->addDetail('accounts', $author->getAccount());
$notificationInterface->update($notification);
} catch (StreamNotFoundException $e) {
/** @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())
->setSubType(Like::TYPE)
->setId($post->getId() . '/notification+like')
->setSummary('{accounts} liked your post')
->setObjectId($post->getId())
->setTo($post->getAttributedTo())
->setLocal(true);
$notificationInterface->save($notification);
}
}
/**
* @param Stream $post
* @param Person $author
*
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function cancelNotification(Stream $post, Person $author) {
if (!$post->isLocal()) {
return;
}
/** @var SocialAppNotificationInterface $notificationInterface */
$notificationInterface =
AP::$activityPub->getInterfaceFromType(SocialAppNotification::TYPE);
try {
$notification = $this->streamRequest->getStreamByObjectId(
$post->getId(), SocialAppNotification::TYPE, Like::TYPE
);
$notification->removeDetail('accounts', $author->getAccount());
if (empty($notification->getDetails('accounts'))) {
$notificationInterface->delete($notification);
} else {
$notificationInterface->update($notification);
}
} catch (StreamNotFoundException $e) {
}
}
}

Wyświetl plik

@ -0,0 +1,159 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Migration;
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Type;
use Exception;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Class Version0002Date20190226000001
*
* @package OCA\Social\Migration
*/
class Version0002Date20190629000001 extends SimpleMigrationStep {
/** @var IDBConnection */
private $connection;
/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @return ISchemaWrapper
* @throws SchemaException
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options
): ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if ($schema->hasTable('social_a2_stream')) {
$table = $schema->getTable('social_a2_stream');
if (!$table->hasColumn('subtype')) {
$table->addColumn(
'subtype', Type::STRING,
[
'notnull' => false,
'length' => 31,
]
);
}
}
if (!$schema->hasTable('social_a2_actions')) {
$table = $schema->createTable('social_a2_actions');
$table->addColumn(
'id', 'string',
[
'notnull' => false,
'length' => 1000
]
);
$table->addColumn(
'id_prim', 'string',
[
'notnull' => false,
'length' => 128
]
);
$table->addColumn(
'type', 'string',
[
'notnull' => false,
'length' => 31,
]
);
$table->addColumn(
'actor_id', 'string',
[
'notnull' => true,
'length' => 1000,
]
);
$table->addColumn(
'object_id', 'string',
[
'notnull' => true,
'length' => 1000,
]
);
$table->addColumn(
'creation', 'datetime',
[
'notnull' => false,
]
);
$table->setPrimaryKey(['id_prim']);
}
return $schema;
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @throws Exception
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
$qb = $this->connection->getQueryBuilder();
$qb->delete('social_a2_stream');
$expr = $qb->expr();
$qb->where($expr->eq('type', $qb->createNamedParameter('SocialAppNotification')));
$qb->execute();
}
}

Wyświetl plik

@ -56,6 +56,9 @@ class Item {
/** @var string */
private $type = '';
/** @var string */
private $subType = '';
/** @var string */
private $url = '';
@ -149,10 +152,27 @@ class Item {
* @return Item
*/
public function setType(string $type): Item {
// if ($type !== '') {
$this->type = $type;
// }
return $this;
}
/**
* @return string
*/
public function getSubType(): string {
return $this->subType;
}
/**
* @param string $type
*
* @return Item
*/
public function setSubType(string $type): Item {
$this->subType = $type;
return $this;
}
@ -667,6 +687,7 @@ class Item {
}
}

Wyświetl plik

@ -28,7 +28,7 @@ declare(strict_types=1);
*/
namespace OCA\Social\Model\ActivityPub\Activity;
namespace OCA\Social\Model\ActivityPub\Object;
use JsonSerializable;
@ -38,7 +38,7 @@ use OCA\Social\Model\ActivityPub\ACore;
/**
* Class Like
*
* @package OCA\Social\Model\ActivityPub\Activity
* @package OCA\Social\Model\ActivityPub\Object
*/
class Like extends ACore implements JsonSerializable {

Wyświetl plik

@ -31,6 +31,8 @@ declare(strict_types=1);
namespace OCA\Social\Traits;
use OCA\Social\Model\ActivityPub\Item;
/**
* Trait TDetails
*
@ -57,6 +59,7 @@ trait TDetails {
$this->details = $details;
}
/**
* @param string $detail
* @param string $value
@ -89,6 +92,28 @@ 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
*
* @return array
*/
public function getDetails(string $detail): array {
if (!array_key_exists($detail, $this->details) || !is_array($this->details[$detail])) {
return [];
}
return $this->details[$detail];
}
/**
* @param string $detail
@ -139,5 +164,53 @@ trait TDetails {
}
/**
* @param string $detail
* @param string $value
*/
public function removeDetail(string $detail, string $value) {
if (!array_key_exists($detail, $this->details) || !is_array($this->details[$detail])) {
return;
}
$this->details[$detail] = array_diff($this->details[$detail], [$value]);
}
/**
* @param string $detail
* @param int $value
*/
public function removeDetailInt(string $detail, int $value) {
if (!array_key_exists($detail, $this->details) || !is_array($this->details[$detail])) {
return;
}
$this->details[$detail] = array_diff($this->details, [$value]);
}
/**
* @param string $detail
* @param array $value
*/
public function removeDetailArray(string $detail, array $value) {
if (!array_key_exists($detail, $this->details) || !is_array($this->details[$detail])) {
return;
}
$this->details[$detail] = array_diff($this->details, [$value]);
}
/**
* @param string $detail
* @param bool $value
*/
public function removeDetailBool(string $detail, bool $value) {
if (!array_key_exists($detail, $this->details) || !is_array($this->details[$detail])) {
return;
}
$this->details[$detail] = array_diff($this->details, [$value]);
}
}

Wyświetl plik

@ -136,6 +136,16 @@ export default {
icon: 'icon-comment',
text: t('social', 'Direct messages')
},
// {
// id: 'social-notifications',
// classes: [],
// router: {
// name: 'timeline',
// params: { type: 'notifications' }
// },
// icon: 'icon-comment',
// text: t('social', 'Notifications')
// },
{
id: 'social-account',
classes: [],

Wyświetl plik

@ -1,5 +1,8 @@
<template>
<div v-if="noDuplicateBoost" class="timeline-entry">
<div class="timeline-entry">
<div v-if="item.type === 'SocialAppNotification'">
{{ actionSummary }}
</div>
<div v-if="item.type === 'Announce'" class="boost">
<div class="container-icon-boost">
<span class="icon-boost" />
@ -16,17 +19,20 @@
</a>
{{ boosted }}
</div>
<timeline-content :item="entryContent" :parent-announce="isBoost" />
<timeline-post v-if="(item.type === 'Note' || item.type === 'Announce')" :item="entryContent" :parent-announce="isBoost" />
<user-entry v-if="item.type === 'SocialAppNotificationUser'" :key="user.id" :item="user" />
</div>
</template>
<script>
import TimelineContent from './TimelineContent.vue'
import TimelinePost from './TimelinePost'
import UserEntry from './UserEntry'
export default {
name: 'TimelineEntry',
components: {
TimelineContent
TimelinePost,
UserEntry
},
props: {
item: { type: Object, default: () => {} }
@ -52,15 +58,13 @@ export default {
boosted() {
return t('social', 'boosted')
},
noDuplicateBoost() {
if (this.item.type === 'Announce') {
for (var e in this.$store.state.timeline.timeline) {
if (this.item.cache[this.item.object].object.id === e) {
return false
}
}
actionSummary() {
let summary = this.item.summary
for (var key in this.item.details) {
let keyword = '{' + key + '}'
summary = summary.replace(keyword, JSON.stringify(this.item.details[key]))
}
return true
return summary
}
},
methods: {

Wyświetl plik

@ -57,9 +57,9 @@
<script>
import InfiniteLoading from 'vue-infinite-loading'
import TimelineEntry from './../components/TimelineEntry'
import TimelineEntry from './TimelineEntry'
import CurrentUserMixin from './../mixins/currentUserMixin'
import EmptyContent from './../components/EmptyContent'
import EmptyContent from './EmptyContent'
export default {
name: 'Timeline',
@ -69,6 +69,9 @@ export default {
EmptyContent
},
mixins: [CurrentUserMixin],
props: {
type: { type: String, default: () => 'home' }
},
data: function() {
return {
infoHidden: false,

Wyświetl plik

@ -58,7 +58,7 @@ pluginTag(linkify)
pluginMention(linkify)
export default {
name: 'TimelineContent',
name: 'TimelinePost',
components: {
Avatar
},

Wyświetl plik

@ -21,11 +21,11 @@
</div>
</div>
</transition>
<composer />
<composer v-if="type !== 'notifications'" />
<h2 v-if="type === 'tags'">
#{{ this.$route.params.tag }}
</h2>
<timeline-list />
<timeline-list :type="type" />
</div>
</template>