Skip to content
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
26 changes: 21 additions & 5 deletions lib/TInitialState.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,23 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
);

$attachmentFolder = $this->talkConfig->getAttachmentFolder($user->getUID());
$freeSpace = 0;

if ($attachmentFolder) {
try {
$userFolder = $rootFolder->getUserFolder($user->getUID());

if (!$userFolder->nodeExists($attachmentFolder)) {
$userFolder->newFolder($attachmentFolder);
try {
if (!$userFolder->nodeExists($attachmentFolder)) {
$userFolder->newFolder($attachmentFolder);
}

$freeSpace = $userFolder->get($attachmentFolder)->getFreeSpace();
} catch (NotPermittedException $e) {
$attachmentFolder = '/';
$this->serverConfig->setUserValue($user->getUID(), 'spreed', 'attachment_folder', '/');
$freeSpace = $userFolder->getFreeSpace();
}
} catch (NotPermittedException $e) {
$attachmentFolder = '/';
$this->serverConfig->setUserValue($user->getUID(), 'spreed', 'attachment_folder', '/');
} catch (NoUserException $e) {
}
}
Expand All @@ -118,6 +124,11 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
$attachmentFolder
);

$this->initialState->provideInitialState(
'attachment_folder_free_space',
$freeSpace
);

$this->initialState->provideInitialState(
'enable_matterbridge',
$this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1'
Expand Down Expand Up @@ -147,6 +158,11 @@ protected function publishInitialStateForGuest(): void {
''
);

$this->initialState->provideInitialState(
'attachment_folder_free_space',
''
);

$this->initialState->provideInitialState(
'enable_matterbridge',
false
Expand Down
19 changes: 13 additions & 6 deletions src/components/NewMessageForm/NewMessageForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@
class="new-message-form"
@submit.prevent>
<div
v-if="canUploadFiles || canShareFiles"
class="new-message-form__button">
<Actions
default-icon="icon-clip-add-file"
class="new-message-form__button"
:aria-label="t('spreed', 'Share files to the conversation')"
:aria-haspopup="true">
<ActionButton
v-if="canShareAndUploadFiles"
v-if="canUploadFiles"
:close-after-click="true"
icon="icon-upload"
@click.prevent="clickImportInput">
{{ t('spreed', 'Upload new files') }}
</ActionButton>
<ActionButton
v-if="canShareAndUploadFiles"
v-if="canShareFiles"
:close-after-click="true"
icon="icon-folder"
@click.prevent="handleFileShare">
Expand Down Expand Up @@ -195,13 +196,19 @@ export default {
return this.$store.getters.getUserId() === null
},

canShareAndUploadFiles() {
canShareFiles() {
return !this.currentUserIsGuest && !this.isReadOnly
},

canUploadFiles() {
const allowed = getCapabilities()?.spreed?.config?.attachments?.allowed
return allowed && !this.currentUserIsGuest && !this.isReadOnly
return allowed
&& this.attachmentFolderFreeSpace !== 0
&& this.canShareFiles
},

attachmentFolder() {
return this.$store.getters.getAttachmentFolder()
attachmentFolderFreeSpace() {
return this.$store.getters.getAttachmentFolderFreeSpace()
},
},

Expand Down
6 changes: 6 additions & 0 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { shareFile } from '../services/filesSharingServices'

const state = {
attachmentFolder: loadState('spreed', 'attachment_folder'),
attachmentFolderFreeSpace: loadState('spreed', 'attachment_folder_free_space'),
uploads: {
},
currentUploadId: undefined,
Expand Down Expand Up @@ -76,6 +77,11 @@ const getters = {
return state.attachmentFolder
},

// gets the current attachment folder
getAttachmentFolderFreeSpace: (state) => () => {
return state.attachmentFolderFreeSpace
},

uploadProgress: (state) => (uploadId, index) => {
if (state.uploads[uploadId].files[index]) {
return state.uploads[uploadId].files[index].uploadedSize / state.uploads[uploadId].files[index].totalSize * 100
Expand Down