fix: update attachments count when sharing

Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
Luka Trovic 2022-04-27 09:40:27 +02:00 коммит произвёл Julius Härtl
Родитель 2af94410f5
Коммит 0b6990f828
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
3 изменённых файлов: 26 добавлений и 7 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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)
})
})
},