Merge pull request #1685 from nextcloud/fix/noid/boost-2

reblog
pull/1688/head
Maxence Lange 2023-03-21 09:29:06 -01:00 zatwierdzone przez GitHub
commit a4ceb09068
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
15 zmienionych plików z 173 dodań i 57 usunięć

Wyświetl plik

@ -507,7 +507,7 @@ class ApiController extends Controller {
public function statusAction(int $nid, string $act): DataResponse {
try {
$this->initViewer(true);
$item = $this->actionService->action($this->viewer->getId(), $nid, $act);
$item = $this->actionService->action($this->viewer, $nid, $act);
if ($item === null) {
$item = $this->streamService->getStreamByNid($nid);

Wyświetl plik

@ -154,7 +154,7 @@ class ActionsRequestBuilder extends CoreRequestBuilder {
$item->importFromDatabase($data);
try {
$actor = $qb->parseLeftJoinCacheActors($data);
$actor = $qb->parseLeftJoinCacheActors($data, 'cacheactor_');
$actor->setCompleteDetails(true);
$item->setActor($actor);

Wyświetl plik

@ -105,7 +105,6 @@ class CoreRequestBuilder {
'following',
'followers',
'inbox',
'shared_index',
'outbox',
'featured',
'url',
@ -873,7 +872,7 @@ class CoreRequestBuilder {
* @param Person $author
* @param string $alias
*
* @deprecated ?
* @deprecated - use SocialCrossQueryBuilder:leftJoinCacheActor
*/
protected function leftJoinCacheActors(
IQueryBuilder &$qb, string $fieldActorId, Person $author = null, string $alias = ''

Wyświetl plik

@ -164,7 +164,7 @@ class FollowsRequestBuilder extends CoreRequestBuilder {
$follow->importFromDatabase($data);
try {
$actor = $qb->parseLeftJoinCacheActors($data);
$actor = $qb->parseLeftJoinCacheActors($data, 'cacheactor_');
$actor->setCompleteDetails(true);
$this->assignDetails($actor, $data);

Wyświetl plik

@ -30,12 +30,12 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use OCA\Social\Tools\Exceptions\RowNotFoundException;
use OCA\Social\Tools\Traits\TArrayTools;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Instance;
use OCA\Social\Tools\Exceptions\RowNotFoundException;
use OCA\Social\Tools\Traits\TArrayTools;
use OCP\DB\QueryBuilder\IQueryBuilder;
class InstancesRequestBuilder extends CoreRequestBuilder {
@ -147,7 +147,7 @@ class InstancesRequestBuilder extends CoreRequestBuilder {
$instance->importFromDatabase($data);
try {
$actor = $qb->parseLeftJoinCacheActors($data);
$actor = $qb->parseLeftJoinCacheActors($data, 'cacheactor_');
$actor->setExportFormat($qb->getFormat());
try {
$icon = $qb->parseLeftJoinCacheDocuments($data);

Wyświetl plik

@ -37,6 +37,7 @@ use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Image;
use OCA\Social\Model\ActivityPub\Stream;
use OCP\DB\QueryBuilder\ICompositeExpression;
/**
@ -129,7 +130,35 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
->selectAlias($pf . '.creation', 'cacheactor_creation')
->selectAlias($pf . '.local', 'cacheactor_local');
$this->leftJoinCacheDocuments('icon_id', $pf, 'cacheactor_', 'cacd');
$this->leftJoinCacheDocuments('icon_id', $pf, 'cacheactor_cachedocument_', 'cacd');
}
/**
* @param array $data
* @param string $prefix
*
* @return Stream
* @throws InvalidResourceException
*/
public function parseLeftJoinStream(array $data, string $prefix = ''): Stream {
$new = [];
foreach ($data as $k => $v) {
if (str_starts_with($k, $prefix)) {
$new[substr($k, strlen($prefix))] = $v;
}
}
$stream = new Stream();
$stream->importFromDatabase($new);
if ($stream->getId() === '') {
throw new InvalidResourceException();
}
$actor = $this->parseLeftJoinCacheActors($data, $prefix . 'cacheactor_');
$stream->setActor($actor);
return $stream;
}
@ -140,7 +169,6 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
* @throws InvalidResourceException
*/
public function parseLeftJoinCacheActors(array $data, string $prefix = ''): Person {
$prefix .= 'cacheactor_';
$new = [];
foreach ($data as $k => $v) {
@ -159,6 +187,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
try {
$icon = $this->parseLeftJoinCacheDocuments($data, $prefix);
$actor->setIcon($icon);
// TODO: store avatar/header within table cache_actor
$uuid = ($icon->getResizedCopy() === '') ? $icon->getLocalCopy() : $icon->getResizedCopy();
$actor->setAvatar(
$this->urlGenerator->linkToRouteAbsolute(
@ -180,17 +209,16 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
public function leftJoinCacheDocuments(
string $linkField,
string $linkAlias = '',
string $prefix = '',
string $prefix = 'cachedocument_',
string $alias = 'cd'
) {
if ($this->getType() !== QueryBuilder::SELECT) {
return;
}
$prefix .= 'cachedocument_';
$expr = $this->expr();
$pf = (($linkAlias === '') ? $this->getDefaultSelectAlias() : $linkAlias);
$this->selectAlias($alias . '.id', $prefix . 'id')
->selectAlias($alias . '.type', $prefix . 'type')
->selectAlias($alias . '.mime_type', $prefix . 'mime_type')
@ -202,8 +230,8 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
->selectAlias($alias . '.error', $prefix . 'error')
->selectAlias($alias . '.creation', $prefix . 'creation')
->leftJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, $alias,
$expr->eq($pf . '.' . $linkField, $alias . '.id_prim')
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, $alias,
$expr->eq($pf . '.' . $linkField, $alias . '.id_prim')
);
}
@ -235,6 +263,80 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
}
/**
* @param string $alias
*/
public function leftJoinObjectStatus(
string $link = 'object_id_prim',
string $alias = '',
string $leftAlias = 'os'
) {
if ($this->getType() !== QueryBuilder::SELECT) {
return;
}
$pf = (($alias === '') ? $this->getDefaultSelectAlias() : $alias) . '.';
foreach (CoreRequestBuilder::$tables[CoreRequestBuilder::TABLE_STREAM] as $field) {
$this->selectAlias($leftAlias . '.' . $field, 'objectstream_' . $field);
}
$this->leftJoin(
$this->getDefaultSelectAlias(),
CoreRequestBuilder::TABLE_STREAM,
$leftAlias,
$this->expr()->eq($pf . $link, $leftAlias . '.id_prim')
);
$this->leftJoinCacheActor(
'attributed_to_prim',
$leftAlias,
'osca',
'objectstream_'
);
}
/**
* @param string $link
* @param string $alias
* @param string $leftAlias
* @param string $prefix
* @param Person|null $author
*/
protected function leftJoinCacheActor(
string $link = 'attributed_to_prim',
string $alias = '',
string $leftAlias = 'ca',
string $prefix = '',
?Person $author = null
) {
if ($this->getType() !== QueryBuilder::SELECT) {
return;
}
$pf = (($alias === '') ? $this->getDefaultSelectAlias() : $alias);
foreach (CoreRequestBuilder::$tables[CoreRequestBuilder::TABLE_CACHE_ACTORS] as $field) {
$this->selectAlias($leftAlias . '.' . $field, $prefix . 'cacheactor_' . $field);
}
$this->leftJoin(
$this->getDefaultSelectAlias(),
CoreRequestBuilder::TABLE_CACHE_ACTORS,
$leftAlias,
$this->expr()->eq($pf . '.' . $link, $leftAlias . '.id_prim')
);
$this->leftJoinCacheDocuments(
'icon_id',
$leftAlias,
$prefix . 'cacheactor_cachedocument_',
$leftAlias . 'cacd'
);
}
/**
* @param string $alias
*/

Wyświetl plik

@ -38,9 +38,10 @@ namespace OCA\Social\Db;
*/
class SocialFiltersQueryBuilder extends SocialLimitsQueryBuilder {
/**
*
* @deprecated ?
*/
public function filterDuplicate() {
return;
if (!$this->hasViewer()) {
return;
}
@ -50,7 +51,7 @@ class SocialFiltersQueryBuilder extends SocialLimitsQueryBuilder {
$expr = $this->expr();
$filter = $expr->orX();
$filter->add($this->exprLimitToDBFieldInt('filter_duplicate', 0, 's'));
// $filter->add($this->exprLimitToDBFieldInt('filter_duplicate', 0, 's'));
$follower = $expr->andX();
$follower->add($this->exprLimitToDBField('attributed_to_prim', $this->prim($viewer->getId()), false));

Wyświetl plik

@ -435,6 +435,7 @@ class StreamRequest extends StreamRequestBuilder {
$this->timelineHomeLinkCacheActor($qb, 'ca', 'f');
$qb->leftJoinStreamAction('sa');
$qb->leftJoinObjectStatus();
$qb->filterDuplicate();
return $this->getStreamsFromRequest($qb);
@ -478,7 +479,7 @@ class StreamRequest extends StreamRequestBuilder {
private function getTimelineAccount(ProbeOptions $options): array {
$qb = $this->getStreamSelectSql($options->getFormat());
$qb->filterType(SocialAppNotification::TYPE);
$qb->limitToType(Note::TYPE);
$qb->paginate($options);
$actorId = $options->getAccountId();
@ -979,7 +980,7 @@ class StreamRequest extends StreamRequestBuilder {
$qb->limitToViewer('sd', 'f', true);
$qb->limitToInReplyTo($id, true);
$qb->filterDuplicate();
//$qb->filterDuplicate();
return $this->getStreamsFromRequest($qb);
}

Wyświetl plik

@ -89,15 +89,14 @@ class StreamRequestBuilder extends CoreRequestBuilder {
$qb = $this->getQueryBuilder();
$qb->setFormat($format);
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->selectDistinct('s.id')
->addSelect(
's.nid', 's.type', 's.subtype', 's.visibility', '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.filter_duplicate', 's.details', 's.hashtags'
)
->from(self::TABLE_STREAM, 's');
foreach (self::$tables[self::TABLE_STREAM] as $field) {
if ($field === 'id') {
continue;
}
$qb->addSelect('s.' . $field);
}
$qb->setDefaultSelectAlias('s');
@ -149,7 +148,8 @@ class StreamRequestBuilder extends CoreRequestBuilder {
$follow = $expr->andX();
$follow->add($expr->eq($aliasFollow . '.type', $qb->createNamedParameter('Follow')));
$follow->add($expr->eq($alias . '.id_prim', $aliasFollow . '.object_id_prim'));
// might be overkill to check object_id and also seems to filter boosted message
// $follow->add($expr->eq($alias . '.id_prim', $aliasFollow . '.object_id_prim'));
$orX->add($follow);
$loopback = $expr->andX();
@ -217,13 +217,19 @@ class StreamRequestBuilder extends CoreRequestBuilder {
}
try {
$actor = $qb->parseLeftJoinCacheActors($data);
$actor = $qb->parseLeftJoinCacheActors($data, 'cacheactor_');
$actor->setExportFormat($qb->getFormat());
$item->setCompleteDetails(true);
$item->setActor($actor);
} catch (InvalidResourceException $e) {
}
try {
$object = $qb->parseLeftJoinStream($data, 'objectstream_');
$item->setObject($object);
} catch (InvalidResourceException $e) {
}
$action = $this->parseStreamActionsLeftJoin($data);
if ($item->hasCache()) {
$cache = $item->getCache();

Wyświetl plik

@ -233,8 +233,10 @@ class AnnounceInterface extends AbstractActivityPubInterface implements IActivit
}
public function event(ACore $item, string $source): void {
return;
/** @var Stream $item */
switch ($source) {
// do we still need this ?
case 'updateCache':
$objectId = $item->getObjectId();
try {
@ -244,10 +246,17 @@ class AnnounceInterface extends AbstractActivityPubInterface implements IActivit
return;
}
$to = $this->get('attributedTo', $cachedItem->getObject(), '');
if ($to !== '') {
$this->streamRequest->updateAttributedTo($item->getId(), $to);
}
//
//
//
//
//
// pourquoi update !????
// $to = $this->get('attributedTo', $cachedItem->getObject(), '');
// if ($to !== '') {
// $this->streamRequest->updateAttributedTo($item->getId(), $to);
// }
try {
if ($item->hasActor()) {

Wyświetl plik

@ -33,7 +33,6 @@ namespace OCA\Social\Model\ActivityPub\Object;
use Exception;
use JsonSerializable;
use OCA\Social\AP;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Stream;
@ -67,7 +66,7 @@ class Announce extends Stream implements JsonSerializable {
parent::import($data);
// Might be better to create 'actor_id' field in the 'server_streams' table.
$this->setAttributedTo($this->getActorId());
// $this->setAttributedTo($this->getActorId());
}
/**
@ -76,16 +75,9 @@ class Announce extends Stream implements JsonSerializable {
public function exportAsLocal(): array {
$result = parent::exportAsLocal();
if ($this->hasCache()) {
$cache = $this->getCache();
if ($object = $cache->getItem($this->getObjectId())) {
$object = $object->getObject();
/** @var Stream $item */
$item = AP::$activityPub->getItemFromType($this->get('type', $object, Stream::TYPE));
$item->importFromLocal($object);
$result['reblog'] = $item->exportAsLocal();
$result['content'] = $item->getContent();
}
if ($this->hasObject()) {
// TODO: check it is a repost/boost
$result['reblog'] = $this->getObject()->exportAsLocal();
}
return $result;

Wyświetl plik

@ -630,7 +630,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
"content" => $this->getContent(),
"sensitive" => $this->isSensitive(),
"spoiler_text" => $this->getSpoilerText(),
"visibility" => $this->getVisibility(),
'visibility' => ($this->getVisibility() === '') ? 'unknown' : $this->getVisibility(),
"language" => $this->getLanguage(),
"in_reply_to_id" => null,
"in_reply_to_account_id" => null,

Wyświetl plik

@ -31,14 +31,15 @@ namespace OCA\Social\Service;
use OCA\Social\Exceptions\InvalidActionException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\StreamAction;
use OCA\Social\Tools\Traits\TStringTools;
class ActionService {
use TStringTools;
private StreamService $streamService;
private BoostService $boostService;
private StreamActionService $streamActionService;
private const TRANSLATE = 'translate';
@ -69,9 +70,11 @@ class ActionService {
public function __construct(
StreamService $streamService,
BoostService $boostService,
StreamActionService $streamActionService
) {
$this->streamService = $streamService;
$this->boostService = $boostService;
$this->streamActionService = $streamActionService;
}
@ -86,7 +89,7 @@ class ActionService {
* @return Stream|null
* @throws InvalidActionException
*/
public function action(string $actorId, int $nid, string $action): ?Stream {
public function action(Person $actor, int $nid, string $action): ?Stream {
if (!in_array($action, self::$availableStatusAction)) {
throw new InvalidActionException();
}
@ -98,19 +101,19 @@ class ActionService {
return $this->translate($nid);
case self::FAVOURITE:
$this->favourite($actorId, $post->getId());
$this->favourite($actor, $post->getId());
break;
case self::UNFAVOURITE:
$this->favourite($actorId, $post->getId(), false);
$this->favourite($actor, $post->getId(), false);
break;
case self::REBLOG:
$this->reblog($actorId, $post->getId());
$this->reblog($actor, $post->getId());
break;
case self::UNREBLOG:
$this->reblog($actorId, $post->getId(), false);
$this->reblog($actor, $post->getId(), false);
break;
}
@ -130,11 +133,13 @@ class ActionService {
return $this->streamService->getStreamByNid($nid);
}
private function favourite(string $actorId, string $postId, bool $enabled = true): void {
$this->streamActionService->setActionBool($actorId, $postId, StreamAction::LIKED, $enabled);
private function favourite(Person $actor, string $postId, bool $enabled = true): void {
$this->boostService->delete($actor, $postId);
// $this->streamActionService->setActionBool($actor->getId(), $postId, StreamAction::LIKED, $enabled);
}
private function reblog(string $actorId, string $postId, bool $enabled = true): void {
$this->streamActionService->setActionBool($actorId, $postId, StreamAction::BOOSTED, $enabled);
private function reblog(Person $actor, string $postId, bool $enabled = true): void {
$this->boostService->create($actor, $postId);
//$this->streamActionService->setActionBool($actor->getId(), $postId, StreamAction::BOOSTED, $enabled);
}
}

Wyświetl plik

@ -30,7 +30,6 @@ declare(strict_types=1);
namespace OCA\Social\Service;
use OCA\Social\Tools\Traits\TStringTools;
use Exception;
use OCA\Social\AP;
use OCA\Social\Db\StreamRequest;
@ -44,6 +43,7 @@ use OCA\Social\Model\ActivityPub\Object\Announce;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\StreamAction;
use OCA\Social\Tools\Traits\TStringTools;
/**
* Class BoostService
@ -121,6 +121,7 @@ class BoostService {
}
$announce->addCc($actor->getFollowers());
$announce->setObjectId($note->getId());
$announce->setRequestToken($this->uuid());

Wyświetl plik

@ -15,7 +15,7 @@
</router-link>
</div>
<div class="post-visibility"
:class="{ [visibility.icon]: true }"
:class="{ [visibility?.icon ?? '']: true }"
:title="visibility.text" />
<a :data-timestamp="timestamp"
class="post-timestamp live-relative-timestamp"