From bfcd5357e36bddf91a1e21dc9df64a038ac85b94 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Wed, 27 Apr 2022 09:40:27 +0200 Subject: [PATCH] fix: update attachments count when sharing Signed-off-by: Luka Trovic --- lib/Service/AttachmentService.php | 5 +++-- lib/Sharing/DeckShareProvider.php | 18 +++++++++++++++++- src/components/card/AttachmentList.vue | 10 ++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index dc9cbd5f8..46668b8b5 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -137,16 +137,17 @@ class AttachmentService { /** * @param $cardId + * @param bool $update | Force the update of the cached values * @return int|mixed * @throws BadRequestException */ - public function count($cardId) { + public function count($cardId, $update = false) { if (is_numeric($cardId) === false) { throw new BadRequestException('card id must be a number'); } $count = $this->cache->get('card-' . $cardId); - if (!$count) { + if ($update OR !$count) { $count = count($this->attachmentMapper->findAll($cardId)); foreach (array_keys($this->services) as $attachmentType) { diff --git a/lib/Sharing/DeckShareProvider.php b/lib/Sharing/DeckShareProvider.php index 6ac48ea8c..bac0ea6da 100644 --- a/lib/Sharing/DeckShareProvider.php +++ b/lib/Sharing/DeckShareProvider.php @@ -34,6 +34,7 @@ use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\User; use OCA\Deck\NoPermissionException; use OCA\Deck\Service\PermissionService; +use OCA\Deck\Service\AttachmentService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Utility\ITimeFactory; @@ -75,16 +76,29 @@ class DeckShareProvider implements \OCP\Share\IShareProvider { private $cardMapper; /** @var PermissionService */ private $permissionService; + /** @var AttachmentService */ + private $attachmentService; /** @var ITimeFactory */ private $timeFactory; private $l; - public function __construct(IDBConnection $connection, IManager $shareManager, ISecureRandom $secureRandom, BoardMapper $boardMapper, CardMapper $cardMapper, PermissionService $permissionService, IL10N $l) { + public function __construct( + IDBConnection $connection, + IManager $shareManager, + ISecureRandom $secureRandom, + BoardMapper $boardMapper, + CardMapper $cardMapper, + AttachmentService $attachmentService, + PermissionService $permissionService, + IL10N $l + ) { $this->dbConnection = $connection; $this->shareManager = $shareManager; $this->boardMapper = $boardMapper; $this->cardMapper = $cardMapper; + $this->attachmentService = $attachmentService; $this->permissionService = $permissionService; + $this->l = $l; $this->timeFactory = \OC::$server->get(ITimeFactory::class); } @@ -152,6 +166,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider { ); $data = $this->getRawShare($shareId); + $this->attachmentService->count($cardId, true); + return $this->createShareObject($data); } diff --git a/src/components/card/AttachmentList.vue b/src/components/card/AttachmentList.vue index f28b05ddb..34d46d35c 100644 --- a/src/components/card/AttachmentList.vue +++ b/src/components/card/AttachmentList.vue @@ -109,7 +109,7 @@ import relativeDate from '../../mixins/relativeDate' import { formatFileSize } from '@nextcloud/files' import { getCurrentUser } from '@nextcloud/auth' import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router' -import { mapState } from 'vuex' +import { mapState, mapActions } from 'vuex' import { loadState } from '@nextcloud/initial-state' import attachmentUpload from '../../mixins/attachmentUpload' import { getFilePickerBuilder } from '@nextcloud/dialogs' @@ -205,11 +205,14 @@ export default { cardId: { immediate: true, handler() { - this.$store.dispatch('fetchAttachments', this.cardId) + this.fetchAttachments(this.cardId) }, }, }, methods: { + ...mapActions([ + "fetchAttachments", + ]), handleUploadFile(event) { const files = event.target.files ?? [] for (const file of files) { @@ -233,8 +236,7 @@ export default { shareType: 12, shareWith: '' + this.cardId, }).then(() => { - this.$store.dispatch('fetchAttachments', this.cardId) - this.$store.commit('cardIncreaseAttachmentCount', this.cardId) + this.fetchAttachments(this.cardId) }) }) },