import as local

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1639/head
Maxence Lange 2023-03-13 10:11:04 -01:00
rodzic 6853061149
commit fc786859f1
10 zmienionych plików z 191 dodań i 56 usunięć

Wyświetl plik

@ -172,18 +172,21 @@ class SocialPubController extends Controller {
* @throws SocialAppConfigException
* @throws StreamNotFoundException
*/
public function displayPost(string $username, string $token): TemplateResponse {
public function displayPost(string $username, int $token): TemplateResponse {
try {
$viewer = $this->accountService->getCurrentViewer();
$this->streamService->setViewer($viewer);
} catch (AccountDoesNotExistException $e) {
}
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
// $postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
$stream = $this->streamService->getStreamByNid($token);
if (strtolower($stream->getActor()->getDisplayName()) !== strtolower($username)) {
throw new StreamNotFoundException();
}
$stream = $this->streamService->getStreamById($postId, true);
$data = [
'id' => $postId,
'application' => 'Social'
];

Wyświetl plik

@ -109,6 +109,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
}
$this->selectAlias($pf . '.id', 'cacheactor_id')
->selectAlias($pf . '.nid', 'cacheactor_nid')
->selectAlias($pf . '.type', 'cacheactor_type')
->selectAlias($pf . '.account', 'cacheactor_account')
->selectAlias($pf . '.following', 'cacheactor_following')

Wyświetl plik

@ -31,9 +31,6 @@ declare(strict_types=1);
namespace OCA\Social\Interfaces\Object;
use OCA\Social\Tools\Exceptions\CacheItemNotFoundException;
use OCA\Social\Tools\Exceptions\MalformedArrayException;
use OCA\Social\Tools\Traits\TArrayTools;
use Exception;
use OCA\Social\AP;
use OCA\Social\Db\ActionsRequest;
@ -44,11 +41,6 @@ use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Tools\Exceptions\RequestContentException;
use OCA\Social\Tools\Exceptions\RequestNetworkException;
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
use OCA\Social\Tools\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Exceptions\UnauthorizedFediverseException;
@ -65,6 +57,14 @@ use OCA\Social\Model\StreamQueue;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\StreamQueueService;
use OCA\Social\Tools\Exceptions\CacheItemNotFoundException;
use OCA\Social\Tools\Exceptions\MalformedArrayException;
use OCA\Social\Tools\Exceptions\RequestContentException;
use OCA\Social\Tools\Exceptions\RequestNetworkException;
use OCA\Social\Tools\Exceptions\RequestResultNotJsonException;
use OCA\Social\Tools\Exceptions\RequestResultSizeException;
use OCA\Social\Tools\Exceptions\RequestServerException;
use OCA\Social\Tools\Traits\TArrayTools;
/**
* Class AnnounceInterface
@ -178,9 +178,9 @@ class AnnounceInterface extends AbstractActivityPubInterface implements IActivit
}
try {
$post = $this->streamRequest->getStreamById($item->getObjectId());
$post = $this->streamRequest->getStreamById($item->getObjectId(), false, ACore::FORMAT_LOCAL);
} catch (StreamNotFoundException $e) {
return; // should not happens.
return; // should not happen.
}
$this->updateDetails($post);
@ -256,7 +256,11 @@ class AnnounceInterface extends AbstractActivityPubInterface implements IActivit
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$post = $this->streamRequest->getStreamById($item->getObjectId());
$post = $this->streamRequest->getStreamById(
$item->getObjectId(),
false,
ACore::FORMAT_LOCAL
);
$this->updateDetails($post);
$this->generateNotification($post, $actor);
} catch (Exception $e) {
@ -321,7 +325,6 @@ class AnnounceInterface extends AbstractActivityPubInterface implements IActivit
// $notification->setDetail('url', '');
$notification->setDetailItem('post', $post);
$notification->setDetailInt('nid', $post->getNid());
$notification->addDetail('accounts', $author->getAccount());
$notification->setAttributedTo($author->getId())
->setSubType(Announce::TYPE)

Wyświetl plik

@ -35,11 +35,11 @@ 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\ItemAlreadyExistsException;
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\Activity\AbstractActivityPubInterface;
@ -135,7 +135,12 @@ class LikeInterface extends AbstractActivityPubInterface implements IActivityPub
$actor = $this->cacheActorService->getFromId($item->getActorId());
}
$post = $this->streamRequest->getStreamById($item->getObjectId());
$post = $this->streamRequest->getStreamById(
$item->getObjectId(),
false,
ACore::FORMAT_LOCAL
);
$post->setCompleteDetails(true);
$this->updateDetails($post);
$this->generateNotification($post, $actor);
} catch (Exception $e) {
@ -204,7 +209,6 @@ class LikeInterface extends AbstractActivityPubInterface implements IActivityPub
$notification = AP::$activityPub->getItemFromType(SocialAppNotification::TYPE);
// $notification->setDetail('url', '');
$notification->setDetailItem('post', $post);
$notification->setDetailInt('nid', $post->getNid());
$notification->addDetail('accounts', $author->getAccount());
$notification->setAttributedTo($author->getId())
->setSubType(Like::TYPE)

Wyświetl plik

@ -638,10 +638,11 @@ class ACore extends Item implements JsonSerializable {
}
/**
* based on json generated/exported as LOCAL
* @param array $data
*/
public function importFromCache(array $data) {
$this->import($data);
public function importFromLocal(array $data) {
$this->setNid($this->getInt('id', $data));
}
/**

Wyświetl plik

@ -636,6 +636,47 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
}
}
/**
* @param array $data
*
* @return $this
*/
public function importFromLocal(array $data): self {
parent::importFromLocal($data);
$this->setId($this->get('url', $data));
$this->setPreferredUsername($this->get('username', $data));
$this->setAccount($this->get('acct', $data));
$this->setDisplayName($this->get('display_name', $data));
$this->setLocked($this->getBool('locked', $data));
$this->setBot($this->getBool('bot', $data));
$this->setDiscoverable($this->getBool('discoverable', $data));
$this->setDescription($this->get('note', $data));
$this->setUrl($this->get('url', $data));
$this->setAvatar($this->get('avatar', $data));
$this->setHeader($this->get('header', $data));
$this->setPrivacy($this->get('source.privacy', $data));
$this->setSensitive($this->getBool('source.sensitive', $data));
$this->setLanguage($this->get('source.language', $data));
try {
$dTime = new DateTime($this->get('created_at', $data, 'yesterday'));
$this->setCreation($dTime->getTimestamp());
} catch (Exception $e) {
}
$count = [
'followers' => $this->getInt('followers_count', $data),
'following' => $this->getInt('following_count', $data),
'post' => $this->getInt('statuses_count', $data),
'last_post_creation' => $this->get('last_status_at', $data)
];
$this->setDetailArray('count', $count);
return $this;
}
/**
* @param array $data
@ -720,34 +761,35 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
$details = $this->getDetailsAll();
$result =
[
"username" => $this->getPreferredUsername(),
"acct" => $this->isLocal() ? $this->getPreferredUsername() : $this->getAccount(),
"display_name" => $this->getDisplayName(),
"locked" => $this->isLocked(),
"bot" => $this->isBot(),
"discoverable" => $this->isDiscoverable(),
"group" => false,
"created_at" => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z',
"note" => $this->getDescription(),
"url" => $this->getId(),
"avatar" => $this->getAvatar(),
"avatar_static" => $this->getAvatar(),
"header" => $this->getHeader(),
"header_static" => $this->getHeader(),
"followers_count" => $this->getInt('count.followers', $details),
"following_count" => $this->getInt('count.following', $details),
"statuses_count" => $this->getInt('count.post', $details),
"last_status_at" => $this->get('last_post_creation', $details),
"source" => [
"privacy" => $this->getPrivacy(),
"sensitive" => $this->isSensitive(),
"language" => $this->getLanguage(),
"note" => $this->getDescription(),
"fields" => [],
"follow_requests_count" => 0
'id' => (string)$this->getNid(),
'username' => $this->getPreferredUsername(),
'acct' => $this->isLocal() ? $this->getPreferredUsername() : $this->getAccount(),
'display_name' => $this->getDisplayName(),
'locked' => $this->isLocked(),
'bot' => $this->isBot(),
'discoverable' => $this->isDiscoverable(),
'group' => false,
'created_at' => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z',
'note' => $this->getDescription(),
'url' => $this->getId(),
'avatar' => $this->getAvatar(),
'avatar_static' => $this->getAvatar(),
'header' => $this->getHeader(),
'header_static' => $this->getHeader(),
'followers_count' => $this->getInt('count.followers', $details),
'following_count' => $this->getInt('count.following', $details),
'statuses_count' => $this->getInt('count.post', $details),
'last_status_at' => $this->get('last_post_creation', $details),
'source' => [
'privacy' => $this->getPrivacy(),
'sensitive' => $this->isSensitive(),
'language' => $this->getLanguage(),
'note' => $this->getDescription(),
'fields' => [],
'follow_requests_count' => 0
],
"emojis" => [],
"fields" => []
'emojis' => [],
'fields' => []
];
return array_merge(parent::exportAsLocal(), $result);

Wyświetl plik

@ -82,7 +82,7 @@ class Announce extends Stream implements JsonSerializable {
$object = $object->getObject();
/** @var Stream $item */
$item = AP::$activityPub->getItemFromType($this->get('type', $object, Stream::TYPE));
$item->importFromCache($object);
$item->importFromLocal($object);
$result['reblog'] = $item->exportAsLocal();
$result['content'] = $item->getContent();
}

Wyświetl plik

@ -115,6 +115,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
return $this->content;
}
/**
* @param string $content
*
@ -491,13 +492,57 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
$this->setCache($cache);
}
public function importFromCache(array $data) {
parent::importFromCache($data);
public function importFromLocal(array $data) {
parent::importFromLocal($data);
$this->setId($this->get('url', $data));
$this->setUrl($this->get('url', $data));
$this->setLocal($this->getBool('local', $data));
$this->setContent($this->get('content', $data));
$this->setSensitive($this->getBool('sensitive', $data));
$this->setSpoilerText($this->get('spoiler_text', $data));
$this->setVisibility($this->get('visibility', $data));
$this->setLanguage($this->get('language', $data));
$action = new StreamAction();
$action->setValues(
[
StreamAction::LIKED => $this->getBool('favourited', $data),
StreamAction::BOOSTED => $this->getBool('reblogged', $data)
]
);
$this->setAction($action);
try {
$dTime = new DateTime($this->get('created_at', $data, 'yesterday'));
$this->setPublishedTime($dTime->getTimestamp());
} catch (Exception $e) {
}
// "in_reply_to_id" => null,
// "in_reply_to_account_id" => null,
// 'replies_count' => 0,
// 'reblogs_count' => 0,
// 'favourites_count' => 0,
// 'muted' => false,
// 'bookmarked' => false,
// "reblog" => null,
// 'noindex' => false
$attachments = [];
foreach ($this->getArray('media_attachments', $data) as $dataAttachment) {
$attachment = new MediaAttachment();
$attachment->import($dataAttachment);
$attachments[] = $attachment;
}
$this->setAttachments($attachments);
// import from cache with new format !
$actor = new Person();
$actor->importFromCache($data['actor_info'] ?? []);
$actor->importFromLocal($this->getArray('account', $data));
$actor->setExportFormat(ACore::FORMAT_LOCAL);
$this->setActor($actor);
$this->setCompleteDetails(true);
// $this->setCompleteDetails(true);
}
@ -608,8 +653,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
$statusPost = $this->getDetails('post');
if (sizeof($statusPost) > 0) {
$status = new Stream();
$status->importFromCache($statusPost);
$status->setNid($this->getDetailInt('nid'));
$status->importFromLocal($statusPost);
$status->setExportFormat(self::FORMAT_LOCAL);
}

Wyświetl plik

@ -204,8 +204,29 @@ class AttachmentMeta implements JsonSerializable {
return $this->blurHash;
}
public function import(array $data): self {
if (array_key_exists('width', $data)) {
$this->setWidth($this->getInt('width', $data));
}
if (array_key_exists('height', $data)) {
$this->setHeight($this->getInt('height', $data));
}
if (array_key_exists('aspect', $data)) {
$this->setAspect($this->getInt('aspect', $data));
}
if (array_key_exists('duration', $data)) {
$this->setDuration($this->getInt('duration', $data));
}
$this->setSize($this->get('size', $data));
$this->setLength($this->get('length', $data));
$this->setFps($this->getFloat('fps', $data));
$this->setAudioEncode($this->get('audio_encode', $data));
$this->setAudioBitrate($this->get('audio_bitrate', $data));
$this->setAudioChannels($this->get('audio_channels', $data));
$this->setDescription($this->get('description', $data));
$this->setBlurHash($this->get('blurhash', $data));
$original = new AttachmentMetaDim();
$original->import($this->getArray('original', $data));
$this->setOriginal($original);

Wyświetl plik

@ -136,6 +136,22 @@ class MediaAttachment implements JsonSerializable {
}
public function import(array $data): self {
$this->setId($this->get('id', $data));
$this->setType($this->get('type', $data));
$this->setUrl($this->get('type', $data));
$this->setPreviewUrl($this->get('type', $data));
$this->setRemoteUrl($this->get('type', $data));
$this->setDescription($this->get('type', $data));
$this->setBlurHash($this->get('blurhash', $data));
$meta = new AttachmentMeta();
$meta->import($this->getArray('meta', $data));
$this->setMeta($meta);
return $this;
}
public function jsonSerialize(): array {
return array_filter(
[