Skip to content

Commit be5de9e

Browse files
committed
(UI) support multiple audio types
1 parent d44bd3d commit be5de9e

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

src/ChatWindow/Message/Message.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</div>
9696

9797
<audio-player
98-
v-else-if="message.file.audio"
98+
v-else-if="isAudio"
9999
:src="message.file.url"
100100
@update-progress-time="progressTime = $event"
101101
@hover-audio-progress="hoverAudioProgress = $event"
@@ -192,7 +192,11 @@ import MessageActions from './MessageActions'
192192
import MessageReactions from './MessageReactions'
193193
import AudioPlayer from './AudioPlayer'
194194
195-
const { isImageFile, isVideoFile } = require('../../utils/media-file')
195+
const {
196+
isImageFile,
197+
isVideoFile,
198+
isAudioFile
199+
} = require('../../utils/media-file')
196200
197201
export default {
198202
name: 'Message',
@@ -262,6 +266,9 @@ export default {
262266
isVideo() {
263267
return isVideoFile(this.message.file)
264268
},
269+
isAudio() {
270+
return isAudioFile(this.message.file)
271+
},
265272
isCheckmarkVisible() {
266273
return (
267274
this.message.senderId === this.currentUserId &&

src/ChatWindow/RoomsList/RoomContent.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@
4141
</slot>
4242
</span>
4343
<div
44-
v-if="
45-
room.lastMessage &&
46-
!room.lastMessage.deleted &&
47-
room.lastMessage.file &&
48-
room.lastMessage.file.audio
49-
"
44+
v-if="room.lastMessage && !room.lastMessage.deleted && isAudio"
5045
class="vac-text-ellipsis"
5146
>
5247
<slot name="microphone-icon">
@@ -123,6 +118,7 @@ import SvgIcon from '../../components/SvgIcon'
123118
import FormatMessage from '../../components/FormatMessage'
124119
125120
import typingText from '../../utils/typing-text'
121+
const { isAudioFile } = require('../../utils/media-file')
126122
127123
export default {
128124
name: 'RoomsContent',
@@ -197,8 +193,17 @@ export default {
197193
)
198194
},
199195
formattedDuration() {
200-
let s = Math.round(this.room.lastMessage.file.duration)
196+
const file = this.room.lastMessage.file
197+
198+
if (!file.duration) {
199+
return `${file.name}.${file.extension}`
200+
}
201+
202+
let s = Math.round(file.duration)
201203
return (s - (s %= 60)) / 60 + (s > 9 ? ':' : ':0') + s
204+
},
205+
isAudio() {
206+
return isAudioFile(this.room.lastMessage.file)
202207
}
203208
},
204209

src/utils/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const IMAGE_TYPES = ['png', 'jpg', 'jpeg', 'webp', 'svg', 'gif']
2-
export const VIDEO_TYPES = ['mp4', 'ogg', 'webm', 'quicktime']
2+
export const VIDEO_TYPES = ['mp4', 'video/ogg', 'webm', 'quicktime']
3+
export const AUDIO_TYPES = ['mp3', 'audio/ogg', 'wav', 'mpeg']

src/utils/media-file.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { IMAGE_TYPES, VIDEO_TYPES } from './constants'
1+
import { IMAGE_TYPES, VIDEO_TYPES, AUDIO_TYPES } from './constants'
22

3-
export function isImageFile(file) {
3+
function checkMediaType(types, file) {
44
if (!file) return
55
const { type } = file
6-
return IMAGE_TYPES.some(t => type.toLowerCase().includes(t))
6+
return types.some(t => type.toLowerCase().includes(t))
7+
}
8+
9+
export function isImageFile(file) {
10+
return checkMediaType(IMAGE_TYPES, file)
711
}
812

913
export function isVideoFile(file) {
10-
if (!file) return
11-
const { type } = file
12-
return VIDEO_TYPES.some(t => type.toLowerCase().includes(t))
14+
return checkMediaType(VIDEO_TYPES, file)
15+
}
16+
17+
export function isAudioFile(file) {
18+
return checkMediaType(AUDIO_TYPES, file)
1319
}

0 commit comments

Comments
 (0)