Skip to content

Commit

Permalink
remove checks like 'message === {file}' or {object}'
Browse files Browse the repository at this point in the history
removed in favor of checking property existence
matches /file/ and /file.*/ for multiple files support

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Oct 16, 2023
1 parent 3b8e6e9 commit 9c86af4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
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
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
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 9c86af4

Please sign in to comment.