Skip to content

Commit

Permalink
Merge pull request #10720 from nextcloud/fix/noid/shared-items-fixups
Browse files Browse the repository at this point in the history
fix(sharedItems): minor refactoring and style fixes
  • Loading branch information
Antreesy authored Oct 17, 2023
2 parents 8dbaa3a + 9c86af4 commit 78215c9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
:container="containerId"
has-typing-indicator
:aria-label="t('spreed', 'Post message')" />

<!-- File upload dialog -->
<NewMessageUploadEditor />

<TransitionWrapper name="fade">
<NcButton v-show="!isChatScrolledToBottom"
type="secondary"
Expand All @@ -74,6 +78,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import GuestWelcomeWindow from './GuestWelcomeWindow.vue'
import MessagesList from './MessagesList/MessagesList.vue'
import NewMessage from './NewMessage/NewMessage.vue'
import NewMessageUploadEditor from './NewMessage/NewMessageUploadEditor.vue'
import TransitionWrapper from './TransitionWrapper.vue'

import { CONVERSATION } from '../constants.js'
Expand All @@ -88,6 +93,7 @@ export default {
ChevronDoubleDown,
MessagesList,
NewMessage,
NewMessageUploadEditor,
TransitionWrapper,
GuestWelcomeWindow,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,15 @@ export default {

linkToFile() {
if (this.isFileShare) {
return this.messageParameters?.file?.link
const firstFileKey = (Object.keys(this.messageParameters).find(key => key.startsWith('file')))
return this.messageParameters?.[firstFileKey]?.link
} else {
return ''
}
return ''
},

isFileShare() {
return this.message === '{file}' && this.messageParameters?.file
return Object.keys(Object(this.messageParameters)).some(key => key.startsWith('file'))
},

isCurrentGuest() {
Expand All @@ -542,7 +544,6 @@ export default {

isPollMessage() {
return this.messageType === 'comment'
&& this.message === '{object}'
&& this.messageParameters?.object?.type === 'talk-poll'
},

Expand Down
5 changes: 0 additions & 5 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@
</template>
</form>

<!-- File upload dialog -->
<NewMessageUploadEditor />

<!-- Poll creation dialog -->
<NewMessagePollEditor v-if="showPollEditor"
:token="token"
Expand Down Expand Up @@ -175,7 +172,6 @@ import NewMessageAudioRecorder from './NewMessageAudioRecorder.vue'
import NewMessageNewFileDialog from './NewMessageNewFileDialog.vue'
import NewMessagePollEditor from './NewMessagePollEditor.vue'
import NewMessageTypingIndicator from './NewMessageTypingIndicator.vue'
import NewMessageUploadEditor from './NewMessageUploadEditor.vue'

import { CONVERSATION, PARTICIPANT, PRIVACY } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
Expand Down Expand Up @@ -211,7 +207,6 @@ export default {
NewMessageNewFileDialog,
NewMessagePollEditor,
NewMessageTypingIndicator,
NewMessageUploadEditor,
Quote,
// Icons
BellOff,
Expand Down
4 changes: 2 additions & 2 deletions src/components/NewMessage/NewMessageUploadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ export default {
},

voiceMessageName() {
if (!this.firstFile.file.name) {
if (!this.firstFile?.file?.name) {
return ''
}
return this.firstFile.file.name
},

voiceMessageLocalURL() {
if (!this.firstFile.file.localURL) {
if (!this.firstFile?.file?.localURL) {
return ''
}
return this.firstFile.file.localURL
Expand Down
3 changes: 1 addition & 2 deletions src/components/Quote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ export default {
},

isFileShareMessage() {
return this.message === '{file}'
&& 'file' in this.messageParameters
return Object.keys(Object(this.messageParameters)).some(key => key.startsWith('file'))
},

richParameters() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/RightSidebar/SharedItems/SharedItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div v-else-if="isOther"
:key="item.id"
class="shared-items__other">
<a v-if="item.messageParameters.object.link"
<a v-if="item.messageParameters.object?.link"
:href="item.messageParameters.object.link"
target="_blank">
{{ item.messageParameters.object.name }}
Expand Down
8 changes: 4 additions & 4 deletions src/components/RightSidebar/SharedItems/SharedItemsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
-->

<template>
<div class="shared-items">
<LoadingComponent v-if="loading" class="shared-items__loading" />
<div class="shared-items-tab">
<LoadingComponent v-if="loading" class="shared-items-tab__loading" />

<template v-else>
<!-- Shared items grouped by type -->
Expand Down Expand Up @@ -64,7 +64,7 @@

<!-- No shared content -->
<NcEmptyContent v-else-if="!hasSharedItems && !hasRelatedResources"
class="shared-items__empty-content"
class="shared-items-tab__empty-content"
:name="t('spreed', 'No shared items')">
<template #icon>
<FolderMultipleImage :size="20" />
Expand Down Expand Up @@ -227,7 +227,7 @@ export default {
}
}

.shared-items {
.shared-items-tab {
display: flex;
flex-direction: column;
height: 100%;
Expand Down
13 changes: 8 additions & 5 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,13 @@ const actions = {

context.commit('addMessage', message)

if ((message.messageType === 'comment' && message.message === '{file}' && message.messageParameters?.file)
|| (message.messageType === 'voice-message' && message.message === '{file}' && message.messageParameters?.file)
|| (message.messageType === 'comment' && message.message === '{object}' && message.messageParameters?.object)) {
sharedItemsStore.addSharedItemFromMessage(message)
if (message.messageParameters && (message.messageType === 'comment' || message.messageType === 'voice-message')) {
if (message.messageParameters?.object || message.messageParameters?.file) {
// Handle voice messages, shares with single file, polls, deck cards, e.t.c
sharedItemsStore.addSharedItemFromMessage(message)
} else if (Object.keys(message.messageParameters).some(key => key.startsWith('file'))) {
// Handle shares with multiple files
}
}
},

Expand Down Expand Up @@ -1297,7 +1300,7 @@ const actions = {
delete message.parent
}

if (message.message === '{object}' && message.messageParameters.object) {
if (message.messageParameters?.object) {
const richObject = message.messageParameters.object
const response = await postRichObjectToConversation(
targetToken,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getItemTypeFromMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SHARED_ITEM } from '../constants.js'

export const getItemTypeFromMessage = function(message) {
if (message.message === '{object}') {
if (message.messageParameters?.object) {
if (message.messageParameters.object.type === 'geo-location') {
return SHARED_ITEM.TYPES.LOCATION
} else if (message.messageParameters.object.type === 'deck-card') {
Expand All @@ -11,7 +11,7 @@ export const getItemTypeFromMessage = function(message) {
} else {
return SHARED_ITEM.TYPES.OTHER
}
} else if (message.message === '{file}') {
} else if (message.messageParameters?.file) {
const messageType = message.messageType || ''
const mimetype = message.messageParameters.file?.mimetype || ''
if (messageType === 'record-audio' || messageType === 'record-video') {
Expand Down

0 comments on commit 78215c9

Please sign in to comment.