Skip to content

Commit

Permalink
add voice messages to the sharedItemsStore
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Sep 21, 2023
1 parent 6158ad7 commit def4a3a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
7 changes: 4 additions & 3 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ import { ATTENDEE, CONVERSATION, PARTICIPANT } from '../../../../constants.js'
import participant from '../../../../mixins/participant.js'
import { EventBus } from '../../../../services/EventBus.js'
import { useGuestNameStore } from '../../../../stores/guestName.js'
import { getItemTypeFromMessage } from '../../../../utils/getItemTypeFromMessage.js'

const isTranslationAvailable = getCapabilities()?.spreed?.config?.chat?.translations?.length > 0

Expand Down Expand Up @@ -581,19 +582,19 @@ export default {
Object.keys(this.messageParameters).forEach(function(p) {
const type = this.messageParameters[p].type
const mimetype = this.messageParameters[p].mimetype
const itemType = getItemTypeFromMessage(this.messageObject)
if (type === 'user' || type === 'call' || type === 'guest' || type === 'user-group' || type === 'group') {
richParameters[p] = {
component: Mention,
props: this.messageParameters[p],
}
} else if (type === 'file' && mimetype !== 'text/vcard') {
const parameters = this.messageParameters[p]
parameters['is-voice-message'] = this.messageType === 'voice-message'
richParameters[p] = {
component: FilePreview,
props: Object.assign({
token: this.token,
}, parameters),
itemType,
}, this.messageParameters[p]),
}
} else if (type === 'deck-card') {
richParameters[p] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ export default {
default: '',
},

isVoiceMessage: {
type: Boolean,
default: false,
},

rowLayout: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -304,7 +299,7 @@ export default {
return {
is: 'div',
}
} else if (this.isVoiceMessage) {
} else if (this.isVoiceMessage && !this.isSharedItems) {
return {
is: AudioPlayer,
name: this.name,
Expand Down Expand Up @@ -417,6 +412,10 @@ export default {
return false
},

isVoiceMessage() {
return this.itemType === SHARED_ITEM.TYPES.VOICE
},

isPlayable() {
// don't show play button for direct renders
if (this.failed || !this.isViewerAvailable || this.previewType !== PREVIEW_TYPE.PREVIEW) {
Expand Down
1 change: 1 addition & 0 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ 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)) {
context.dispatch('addSharedItemMessage', {
message,
Expand Down
30 changes: 1 addition & 29 deletions src/store/sharedItemsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,8 @@

import Vue from 'vue'

import { SHARED_ITEM } from '../constants.js'
import { getSharedItemsOverview, getSharedItems } from '../services/sharedItemsService.js'

const getItemTypeFromMessage = function(message) {
if (message.message === '{object}') {
if (message.messageParameters.object.type === 'geo-location') {
return SHARED_ITEM.TYPES.LOCATION
} else if (message.messageParameters.object.type === 'deck-card') {
return SHARED_ITEM.TYPES.DECK_CARD
} else if (message.messageParameters.object.type === 'talk-poll') {
return SHARED_ITEM.TYPES.POLL
} else {
return SHARED_ITEM.TYPES.OTHER
}
} else {
const messageType = message.messageType || ''
const mimetype = message.messageParameters.file?.mimetype || ''
if (messageType === 'record-audio' || messageType === 'record-video') {
return SHARED_ITEM.TYPES.RECORDING
} else if (messageType === 'voice-message') {
return SHARED_ITEM.TYPES.VOICE
} else if (mimetype.startsWith('audio/')) {
return SHARED_ITEM.TYPES.AUDIO
} else if (mimetype.startsWith('image/') || mimetype.startsWith('video/')) {
return SHARED_ITEM.TYPES.MEDIA
} else {
return SHARED_ITEM.TYPES.FILE
}
}
}
import { getItemTypeFromMessage } from '../utils/getItemTypeFromMessage.js'

// sharedItemsByConversationAndType structure
// token: {
Expand Down
31 changes: 31 additions & 0 deletions src/utils/getItemTypeFromMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { SHARED_ITEM } from '../constants.js'

export const getItemTypeFromMessage = function(message) {
if (message.message === '{object}') {
if (message.messageParameters.object.type === 'geo-location') {
return SHARED_ITEM.TYPES.LOCATION
} else if (message.messageParameters.object.type === 'deck-card') {
return SHARED_ITEM.TYPES.DECK_CARD
} else if (message.messageParameters.object.type === 'talk-poll') {
return SHARED_ITEM.TYPES.POLL
} else {
return SHARED_ITEM.TYPES.OTHER
}
} else if (message.message === '{file}') {
const messageType = message.messageType || ''
const mimetype = message.messageParameters.file?.mimetype || ''
if (messageType === 'record-audio' || messageType === 'record-video') {
return SHARED_ITEM.TYPES.RECORDING
} else if (messageType === 'voice-message') {
return SHARED_ITEM.TYPES.VOICE
} else if (mimetype.startsWith('audio/')) {
return SHARED_ITEM.TYPES.AUDIO
} else if (mimetype.startsWith('image/') || mimetype.startsWith('video/')) {
return SHARED_ITEM.TYPES.MEDIA
} else {
return SHARED_ITEM.TYPES.FILE
}
} else {
return SHARED_ITEM.TYPES.OTHER
}
}

0 comments on commit def4a3a

Please sign in to comment.