Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nc vue components to v7 #1469

Merged
merged 11 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,3 @@
const babelConfig = require('@nextcloud/babel-config')

module.exports = babelConfig
11 changes: 3 additions & 8 deletions lib/AppInfo/Application.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\UpdateService; use OCA\Social\Service\UpdateService;
use OCA\Social\WellKnown\WebfingerHandler; use OCA\Social\WellKnown\WebfingerHandler;
use OCA\Social\Listeners\ProfileSectionListener;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
use OCP\Profile\BeforeTemplateRenderedEvent;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IServerContainer; use OCP\IServerContainer;
use OC\DB\SchemaWrapper; use OC\DB\SchemaWrapper;
Expand All @@ -62,19 +64,12 @@ public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params); parent::__construct(self::APP_NAME, $params);
} }



/**
* @param IRegistrationContext $context
*/
public function register(IRegistrationContext $context): void { public function register(IRegistrationContext $context): void {
$context->registerSearchProvider(UnifiedSearchProvider::class); $context->registerSearchProvider(UnifiedSearchProvider::class);
$context->registerWellKnownHandler(WebfingerHandler::class); $context->registerWellKnownHandler(WebfingerHandler::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, ProfileSectionListener::class);
} }



/**
* @param IBootContext $context
*/
public function boot(IBootContext $context): void { public function boot(IBootContext $context): void {
$manager = $context->getServerContainer() $manager = $context->getServerContainer()
->getNotificationManager(); ->getNotificationManager();
Expand Down
25 changes: 16 additions & 9 deletions lib/Controller/LocalController.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -124,18 +124,26 @@ public function uploadAttachement(): DataResponse {
* *
* @NoAdminRequired * @NoAdminRequired
*/ */
public function postCreate(array $data): DataResponse { public function postCreate(string $content = '', $to = null, string $type = null, ?string $replyTo = null, $attachments = null, ?string $hashtags = null): DataResponse {
$content = $content ?? '';
$to = is_string($to) ? [$to] : $to;
$to = $to ?? [];
$replyTo = $replyTo ?? '';
$type = $type ?? Stream::TYPE_PUBLIC;
$hashtags = $hashtags === '' ? [] : $hashtags;
$hashtags = $hashtags ?? [];
$attachments = $attachments ?? [];

try { try {
$actor = $this->accountService->getActorFromUserId($this->userId); $actor = $this->accountService->getActorFromUserId($this->userId);


$post = new Post($actor); $post = new Post($actor);
$post->setContent($this->get('content', $data, '')); $post->setContent($content);
$post->setReplyTo($this->get('replyTo', $data, '')); $post->setReplyTo($replyTo);
$post->setTo($this->getArray('to', $data, [])); $post->setTo($to);
$post->addTo($this->get('to', $data, '')); $post->setType($type);
$post->setType($this->get('type', $data, Stream::TYPE_PUBLIC)); $post->setHashtags($hashtags);
$post->setHashtags($this->getArray('hashtags', $data, [])); $post->setAttachments($attachments);
$post->setAttachments($this->getArray('attachments', $data, []));


$token = ''; $token = '';
$activity = $this->postService->createPost($post, $token); $activity = $this->postService->createPost($post, $token);
Expand All @@ -151,7 +159,6 @@ public function postCreate(array $data): DataResponse {
} }
} }



/** /**
* Get info about a post (limited to viewer rights). * Get info about a post (limited to viewer rights).
* *
Expand Down
5 changes: 2 additions & 3 deletions lib/Db/CoreRequestBuilder.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService; use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -584,7 +583,7 @@ protected function filterDBField(
protected function exprLimitToDBField( protected function exprLimitToDBField(
IQueryBuilder &$qb, string $field, string $value, bool $eq = true, bool $cs = true, IQueryBuilder &$qb, string $field, string $value, bool $eq = true, bool $cs = true,
string $alias = '' string $alias = ''
): IQueryFunction { ): string {
$expr = $qb->expr(); $expr = $qb->expr();


$pf = ''; $pf = '';
Expand Down Expand Up @@ -618,7 +617,7 @@ protected function limitToDBFieldInt(


protected function exprLimitToDBFieldInt( protected function exprLimitToDBFieldInt(
IQueryBuilder &$qb, string $field, int $value, string $alias = '' IQueryBuilder &$qb, string $field, int $value, string $alias = ''
): IQueryFunction { ): string {
$expr = $qb->expr(); $expr = $qb->expr();


$pf = ''; $pf = '';
Expand Down
22 changes: 22 additions & 0 deletions lib/Listeners/ProfileSectionListener.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace OCA\Social\Listeners;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Profile\BeforeTemplateRenderedEvent;
use OCP\Util;

class ProfileSectionListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof BeforeTemplateRenderedEvent)) {
return;
}
Util::addScript('social', 'social-profilePage');
}
}
18 changes: 18 additions & 0 deletions lib/Service/CacheDocumentService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ public function saveContentToCache(Document $document, string $content, string &
$document->setResizedCopy($resized); $document->setResizedCopy($resized);
} }


public function saveFromTempToCache(Document $document, string $tmpPath) {
$mime = mime_content_type($tmpPath);

$this->filterMimeTypes($mime);

$document->setMediaType($mime);
$document->setMimeType($mime);

$file = fopen($tmpPath, 'r');
$content = fread($file, filesize($tmpPath));

$filename = $this->generateFileFromContent($content);
$document->setLocalCopy($filename);
$this->resizeImage($content);
$resized = $this->generateFileFromContent($content);
$document->setResizedCopy($resized);
}



/** /**
* @param string $content * @param string $content
Expand Down
76 changes: 48 additions & 28 deletions lib/Service/PostService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,41 +53,28 @@
use OCA\Social\Model\Post; use OCA\Social\Model\Post;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException; use OCP\Files\NotPermittedException;
use Psr\Log\LoggerInterface;


class PostService { class PostService {
private StreamService $streamService; private StreamService $streamService;

private AccountService $accountService; private AccountService $accountService;

private ActivityService $activityService; private ActivityService $activityService;

private CacheDocumentService $cacheDocumentService; private CacheDocumentService $cacheDocumentService;

private ConfigService $configService; private ConfigService $configService;

private MiscService $miscService; private MiscService $miscService;
private LoggerInterface $logger;



/**
* PostService constructor.
*
* @param StreamService $streamService
* @param AccountService $accountService
* @param ActivityService $activityService
* @param CacheDocumentService $cacheDocumentService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct( public function __construct(
StreamService $streamService, AccountService $accountService, ActivityService $activityService, StreamService $streamService, AccountService $accountService, ActivityService $activityService,
CacheDocumentService $cacheDocumentService, ConfigService $configService, MiscService $miscService CacheDocumentService $cacheDocumentService, ConfigService $configService, MiscService $miscService, LoggerInterface $logger
) { ) {
$this->streamService = $streamService; $this->streamService = $streamService;
$this->accountService = $accountService; $this->accountService = $accountService;
$this->activityService = $activityService; $this->activityService = $activityService;
$this->cacheDocumentService = $cacheDocumentService; $this->cacheDocumentService = $cacheDocumentService;
$this->configService = $configService; $this->configService = $configService;
$this->miscService = $miscService; $this->miscService = $miscService;
$this->logger = $logger;
} }




Expand Down Expand Up @@ -142,15 +129,48 @@ public function createPost(Post $post, &$token = ''): ACore {
*/ */
private function generateDocumentsFromAttachments(Note $note, Post $post) { private function generateDocumentsFromAttachments(Note $note, Post $post) {
$documents = []; $documents = [];
foreach ($post->getAttachments() as $attachment) { \OC::$server->getLogger()->error(var_export($_FILES["attachments"], true));
if (!isset($_FILES['attachments'])) {
return [];
}
if (is_array($_FILES["attachments"]["error"])) {
foreach ($_FILES["attachments"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
try {
$document = $this->generateDocumentFromAttachment($note, $key);

$service = AP::$activityPub->getInterfaceForItem($document);
$service->save($document);

$documents[] = $document;
} catch (Exception $e) {
}
}
}
} else {
try { try {
$document = $this->generateDocumentFromAttachment($note, $attachment); $tmp_name = $_FILES["attachments"]["tmp_name"];
$name = basename($_FILES["attachments"]["name"]);
$tmpFile = tmpfile();
$tmpPath = stream_get_meta_data($tmpFile)['uri'];
if (move_uploaded_file($tmp_name, $tmpPath)) {
$document = new Document();
$document->setUrlCloud($this->configService->getCloudUrl());
$document->generateUniqueId('/documents/local');
$document->setParentId($note->getId());
$document->setPublic(true);

$this->cacheDocumentService->saveFromTempToCache($document, $tmpPath);
}


$service = AP::$activityPub->getInterfaceForItem($document); $service = AP::$activityPub->getInterfaceForItem($document);
$service->save($document); $service->save($document);


$documents[] = $document; $documents[] = $document;
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->error($e->getMessage(), [
'exception' => $e,
]);
} }
} }
$post->setDocuments($documents); $post->setDocuments($documents);
Expand All @@ -168,21 +188,21 @@ private function generateDocumentsFromAttachments(Note $note, Post $post) {
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws UrlCloudException * @throws UrlCloudException
*/ */
private function generateDocumentFromAttachment(Note $note, string $attachment): Document { private function generateDocumentFromAttachment(Note $note, int $key): Document {
list(, $data) = explode(';', $attachment); $tmp_name = $_FILES["attachments"]["tmp_name"][$key];
list(, $data) = explode(',', $data); $name = basename($_FILES["attachments"]["name"][$key]);
$content = base64_decode($data); $tmpFile = tmpfile();

$tmpPath = stream_get_meta_data($tmpFile)['uri'];
if (move_uploaded_file($tmp_name, $tmpPath)) {
$document = new Document(); $document = new Document();
$document->setUrlCloud($this->configService->getCloudUrl()); $document->setUrlCloud($this->configService->getCloudUrl());
$document->generateUniqueId('/documents/local'); $document->generateUniqueId('/documents/local');
$document->setParentId($note->getId()); $document->setParentId($note->getId());
$document->setPublic(true); $document->setPublic(true);


$mime = ''; $this->cacheDocumentService->saveFromTempToCache($document, $tmpPath);
$this->cacheDocumentService->saveLocalUploadToCache($document, $content, $mime); }
$document->setMediaType($mime);
$document->setMimeType($mime);


return $document; return $document;
} }
Expand Down
5 changes: 2 additions & 3 deletions lib/Tools/Db/ExtendedQueryBuilder.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use OC\DB\QueryBuilder\QueryBuilder; use OC\DB\QueryBuilder\QueryBuilder;
use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;


/** /**
* Class ExtendedQueryBuilder * Class ExtendedQueryBuilder
Expand Down Expand Up @@ -174,7 +173,7 @@ public function filterDBField(string $field, string $value, bool $cs = true, str


public function exprLimitToDBField( public function exprLimitToDBField(
string $field, string $value, bool $eq = true, bool $cs = true, string $alias = '' string $field, string $value, bool $eq = true, bool $cs = true, string $alias = ''
): IQueryFunction { ): string {
$expr = $this->expr(); $expr = $this->expr();


$pf = ''; $pf = '';
Expand Down Expand Up @@ -295,7 +294,7 @@ public function filterDBFieldInt(string $field, int $value, string $alias = '')
} }


public function exprLimitToDBFieldInt(string $field, int $value, string $alias = '', bool $eq = true public function exprLimitToDBFieldInt(string $field, int $value, string $alias = '', bool $eq = true
): IQueryFunction { ): string {
$expr = $this->expr(); $expr = $this->expr();


$pf = ''; $pf = '';
Expand Down
5 changes: 2 additions & 3 deletions lib/Tools/IExtendedQueryBuilder.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Exception; use Exception;
use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;


/** /**
* Interface IExtendedQueryBuilder * Interface IExtendedQueryBuilder
Expand Down Expand Up @@ -134,7 +133,7 @@ public function filterDBField(string $field, string $value, bool $cs = true, str


public function exprLimitToDBField( public function exprLimitToDBField(
string $field, string $value, bool $eq = true, bool $cs = true, string $alias = '' string $field, string $value, bool $eq = true, bool $cs = true, string $alias = ''
): IQueryFunction; ): string;


public function limitToDBFieldArray( public function limitToDBFieldArray(
string $field, array $values, bool $cs = true, string $alias = '' string $field, array $values, bool $cs = true, string $alias = ''
Expand Down Expand Up @@ -191,7 +190,7 @@ public function filterDBFieldInt(string $field, int $value, string $alias = '');
* @param int $value * @param int $value
* @param string $alias * @param string $alias
*/ */
public function exprLimitToDBFieldInt(string $field, int $value, string $alias = ''): IQueryFunction; public function exprLimitToDBFieldInt(string $field, int $value, string $alias = ''): string;




/** /**
Expand Down
Loading