Skip to content

Commit

Permalink
fix: update attachments count when sharing
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <luka@nextcloud.com>
  • Loading branch information
luka-nextcloud committed Apr 27, 2022
1 parent 9aff4bf commit 09c4076
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ public function findAll($cardId, $withDeleted = false) {

/**
* @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) {
Expand Down
18 changes: 17 additions & 1 deletion lib/Sharing/DeckShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -152,6 +166,8 @@ public function create(IShare $share) {
);
$data = $this->getRawShare($shareId);

$this->attachmentService->count($cardId, true);

return $this->createShareObject($data);
}

Expand Down
10 changes: 6 additions & 4 deletions src/components/card/AttachmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
})
})
},
Expand Down

0 comments on commit 09c4076

Please sign in to comment.