diff options
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 140 | ||||
-rw-r--r-- | apps/files/js/detailsview.js | 3 | ||||
-rw-r--r-- | apps/files/js/detailtabview.js | 15 | ||||
-rw-r--r-- | lib/private/FullTextSearch/FullTextSearchManager.php | 2 | ||||
-rw-r--r-- | lib/private/Preview/Generator.php | 18 | ||||
-rw-r--r-- | lib/public/FullTextSearch/Service/IIndexService.php | 4 | ||||
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 22 |
7 files changed, 87 insertions, 117 deletions
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php index ac97cb6f7c9..ead68840a4f 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -24,12 +24,10 @@ namespace OCA\Comments\Notification; -use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; use OCP\Files\IRootFolder; use OCP\IURLGenerator; -use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\INotification; @@ -85,9 +83,9 @@ class Notifier implements INotifier { $l = $this->l10nFactory->get('comments', $languageCode); $displayName = $comment->getActorId(); $isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER; - if ($comment->getActorType() === 'users') { + if($comment->getActorType() === 'users') { $commenter = $this->userManager->get($comment->getActorId()); - if ($commenter instanceof IUser) { + if(!is_null($commenter)) { $displayName = $commenter->getDisplayName(); } } @@ -95,7 +93,7 @@ class Notifier implements INotifier { switch($notification->getSubject()) { case 'mention': $parameters = $notification->getSubjectParameters(); - if ($parameters[0] !== 'files') { + if($parameters[0] !== 'files') { throw new \InvalidArgumentException('Unsupported comment object'); } $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); @@ -105,41 +103,47 @@ class Notifier implements INotifier { } $node = $nodes[0]; - $path = rtrim($node->getPath(), '/'); - if (strpos($path, '/' . $notification->getUser() . '/files/') === 0) { - // Remove /user/files/... - $fullPath = $path; - list(,,, $path) = explode('/', $fullPath, 4); - } - - $subjectParameters = [ - 'file' => [ - 'type' => 'file', - 'id' => $comment->getObjectId(), - 'name' => $node->getName(), - 'path' => $path, - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), - ], - ]; - if ($isDeletedActor) { - $subject = $l->t('You were mentioned on “{file}”, in a comment by a user that has since been deleted'); + $notification->setParsedSubject($l->t( + 'You were mentioned on “%s”, in a comment by a user that has since been deleted', + [$node->getName()] + )) + ->setRichSubject( + $l->t('You were mentioned on “{file}”, in a comment by a user that has since been deleted'), + [ + 'file' => [ + 'type' => 'file', + 'id' => $comment->getObjectId(), + 'name' => $node->getName(), + 'path' => $node->getPath(), + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), + ], + ] + ); } else { - $subject = $l->t('{user} mentioned you in a comment on “{file}”'); - $subjectParameters['user'] = [ - 'type' => 'user', - 'id' => $comment->getActorId(), - 'name' => $displayName, - ]; + $notification->setParsedSubject($l->t( + '%1$s mentioned you in a comment on “%2$s”', + [$displayName, $node->getName()] + )) + ->setRichSubject( + $l->t('{user} mentioned you in a comment on “{file}”'), + [ + 'user' => [ + 'type' => 'user', + 'id' => $comment->getActorId(), + 'name' => $displayName, + ], + 'file' => [ + 'type' => 'file', + 'id' => $comment->getObjectId(), + 'name' => $node->getName(), + 'path' => $node->getPath(), + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), + ], + ] + ); } - - list($message, $messageParameters) = $this->commentToRichMessage($comment); - - $notification->setRichSubject($subject, $subjectParameters) - ->setParsedSubject($this->richToParsed($subject, $subjectParameters)) - ->setRichMessage($message, $messageParameters) - ->setParsedMessage($this->richToParsed($message, $messageParameters)) - ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))) + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))) ->setLink($this->url->linkToRouteAbsolute( 'comments.Notifications.view', ['id' => $comment->getId()]) @@ -153,66 +157,4 @@ class Notifier implements INotifier { } } - - public function commentToRichMessage(IComment $comment): array { - $message = $comment->getMessage(); - $messageParameters = []; - - $mentionTypeCount = []; - - $mentions = $comment->getMentions(); - foreach ($mentions as $mention) { - if ($mention['type'] === 'user') { - $user = $this->userManager->get($mention['id']); - if (!$user instanceof IUser) { - continue; - } - } - - if (!array_key_exists($mention['type'], $mentionTypeCount)) { - $mentionTypeCount[$mention['type']] = 0; - } - $mentionTypeCount[$mention['type']]++; - - // To keep a limited character set in parameter IDs ([a-zA-Z0-9-]) - // the mention parameter ID does not include the mention ID (which - // could contain characters like '@' for user IDs) but a one-based - // index of the mentions of that type. - $mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']]; - - $message = str_replace('@' . $mention['id'], '{' . $mentionParameterId . '}', $message); - - try { - $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); - } catch (\OutOfBoundsException $e) { - // There is no registered display name resolver for the mention - // type, so the client decides what to display. - $displayName = ''; - } - - $messageParameters[$mentionParameterId] = [ - 'type' => $mention['type'], - 'id' => $mention['id'], - 'name' => $displayName - ]; - } - - return [$message, $messageParameters]; - } - - public function richToParsed(string $message, array $parameters): string { - $placeholders = $replacements = []; - foreach ($parameters as $placeholder => $parameter) { - $placeholders[] = '{' . $placeholder . '}'; - if ($parameter['type'] === 'user') { - $replacements[] = '@' . $parameter['name']; - } else if ($parameter['type'] === 'file') { - $replacements[] = $parameter['path']; - } else { - $replacements[] = $parameter['name']; - } - } - - return str_replace($placeholders, $replacements, $message); - } } diff --git a/apps/files/js/detailsview.js b/apps/files/js/detailsview.js index cd602961c0a..bac2a5ebd21 100644 --- a/apps/files/js/detailsview.js +++ b/apps/files/js/detailsview.js @@ -174,6 +174,9 @@ // hide other tabs $tabsContainer.find('.tab').addClass('hidden'); + $tabsContainer.attr('class', 'tabsContainer'); + $tabsContainer.addClass(tabView.getTabsContainerExtraClasses()); + // tab already rendered ? if (!$tabEl.length) { // render tab diff --git a/apps/files/js/detailtabview.js b/apps/files/js/detailtabview.js index a66cedbc15d..1e046f30246 100644 --- a/apps/files/js/detailtabview.js +++ b/apps/files/js/detailtabview.js @@ -41,6 +41,21 @@ }, /** + * Returns the extra CSS classes used by the tabs container when this + * tab is the selected one. + * + * In general you should not extend this method, as tabs should not + * modify the classes of its container; this is reserved as a last + * resort for very specific cases in which there is no other way to get + * the proper style or behaviour. + * + * @return {String} space-separated CSS classes + */ + getTabsContainerExtraClasses: function() { + return ''; + }, + + /** * Returns the tab label * * @return {String} label diff --git a/lib/private/FullTextSearch/FullTextSearchManager.php b/lib/private/FullTextSearch/FullTextSearchManager.php index 6529ef2506a..9a9b077cf23 100644 --- a/lib/private/FullTextSearch/FullTextSearchManager.php +++ b/lib/private/FullTextSearch/FullTextSearchManager.php @@ -195,7 +195,7 @@ class FullTextSearchManager implements IFullTextSearchManager { * @throws FullTextSearchAppNotAvailableException */ public function updateIndexesStatus(string $providerId, array $documentIds, int $status, bool $reset = false) { - $this->getIndexService()->updateIndexStatus($providerId, $documentIds, $status, $reset); + $this->getIndexService()->updateIndexesStatus($providerId, $documentIds, $status, $reset); } diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 86579e3480b..1f7decf2b79 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -298,19 +298,23 @@ class Generator { if ($height !== $maxHeight && $width !== $maxWidth) { /* - * Scale to the nearest power of two + * Scale to the nearest power of four */ - $pow2height = 2 ** ceil(log($height) / log(2)); - $pow2width = 2 ** ceil(log($width) / log(2)); + $pow4height = 4 ** ceil(log($height) / log(4)); + $pow4width = 4 ** ceil(log($width) / log(4)); - $ratioH = $height / $pow2height; - $ratioW = $width / $pow2width; + // Minimum size is 64 + $pow4height = max($pow4height, 64); + $pow4width = max($pow4width, 64); + + $ratioH = $height / $pow4height; + $ratioW = $width / $pow4width; if ($ratioH < $ratioW) { - $width = $pow2width; + $width = $pow4width; $height /= $ratioW; } else { - $height = $pow2height; + $height = $pow4height; $width /= $ratioH; } } diff --git a/lib/public/FullTextSearch/Service/IIndexService.php b/lib/public/FullTextSearch/Service/IIndexService.php index 376c07a4490..c5d1b9b3bcf 100644 --- a/lib/public/FullTextSearch/Service/IIndexService.php +++ b/lib/public/FullTextSearch/Service/IIndexService.php @@ -65,11 +65,11 @@ interface IIndexService { * @since 15.0.0 * * @param string $providerId - * @param $documentId + * @param string $documentId * @param int $status * @param bool $reset */ - public function updateIndexStatus(string $providerId, $documentId, int $status, bool $reset = false); + public function updateIndexStatus(string $providerId, string $documentId, int $status, bool $reset = false); /** diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 64786fa9fe8..565b526b659 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -104,7 +104,7 @@ class GeneratorTest extends \Test\TestCase { $previewFile = $this->createMock(ISimpleFile::class); $previewFolder->method('getFile') - ->with($this->equalTo('128-128.png')) + ->with($this->equalTo('256-256.png')) ->willReturn($previewFile); $this->eventDispatcher->expects($this->once()) @@ -212,7 +212,7 @@ class GeneratorTest extends \Test\TestCase { ->will($this->returnCallback(function($filename) use ($maxPreview, $previewFile) { if ($filename === '2048-2048-max.png') { return $maxPreview; - } else if ($filename === '128-128.png') { + } else if ($filename === '256-256.png') { return $previewFile; } $this->fail('Unexpected file'); @@ -223,7 +223,7 @@ class GeneratorTest extends \Test\TestCase { ->with($this->equalTo('my data')); $previewFolder->method('getFile') - ->with($this->equalTo('128-128.png')) + ->with($this->equalTo('256-256.png')) ->willThrowException(new NotFoundException()); $image = $this->createMock(IImage::class); @@ -233,7 +233,7 @@ class GeneratorTest extends \Test\TestCase { $image->expects($this->once()) ->method('resize') - ->with(128); + ->with(256); $image->method('data') ->willReturn('my resized data'); $image->method('valid')->willReturn(true); @@ -328,8 +328,8 @@ class GeneratorTest extends \Test\TestCase { return [ [1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512], [1024, 2048, 512, 512, false, IPreview::MODE_COVER, 512, 1024], - [1024, 2048, 512, 512, true, IPreview::MODE_FILL, 512, 512], - [1024, 2048, 512, 512, true, IPreview::MODE_COVER, 512, 512], + [1024, 2048, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], + [1024, 2048, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], [1024, 2048, -1, 512, false, IPreview::MODE_COVER, 256, 512], [1024, 2048, 512, -1, false, IPreview::MODE_FILL, 512, 1024], @@ -343,14 +343,20 @@ class GeneratorTest extends \Test\TestCase { [2048, 1024, 512, 512, false, IPreview::MODE_FILL, 512, 256], [2048, 1024, 512, 512, false, IPreview::MODE_COVER, 1024, 512], - [2048, 1024, 512, 512, true, IPreview::MODE_FILL, 512, 512], - [2048, 1024, 512, 512, true, IPreview::MODE_COVER, 512, 512], + [2048, 1024, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], + [2048, 1024, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], [2048, 1024, -1, 512, false, IPreview::MODE_FILL, 1024, 512], [2048, 1024, 512, -1, false, IPreview::MODE_COVER, 512, 256], [2048, 1024, 4096, 1024, true, IPreview::MODE_FILL, 2048, 512], [2048, 1024, 4096, 1024, true, IPreview::MODE_COVER, 2048, 512], + + //Test minimum size + [2048, 1024, 32, 32, false, IPreview::MODE_FILL, 64, 32], + [2048, 1024, 32, 32, false, IPreview::MODE_COVER, 64, 32], + [2048, 1024, 32, 32, true, IPreview::MODE_FILL, 64, 64], + [2048, 1024, 32, 32, true, IPreview::MODE_COVER, 64, 64], ]; } |