-
Notifications
You must be signed in to change notification settings - Fork 456
/
Copy pathgetMessageIcon.ts
52 lines (46 loc) · 1.69 KB
/
getMessageIcon.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { mdiCardText, mdiContacts, mdiFile, mdiImage, mdiMapMarker, mdiMicrophone, mdiMovie, mdiMusicNote, mdiPoll } from '@mdi/js'
import type { Conversation } from '../types/index.ts'
const iconSvgTemplate = (path: string) => {
const svgStyle = 'margin-block: calc((1lh - 16px)/2); vertical-align: bottom;'
return `<svg xmlns="http://www.w3.org/2000/svg" style="${svgStyle}" fill="currentColor" width="16" height="16" viewBox="0 0 24 24"><path d="${path}"></path></svg>`
}
export const getMessageIcon = (lastMessage: Conversation['lastMessage']): string => {
if (Array.isArray(lastMessage)) {
return ''
}
const file = lastMessage?.messageParameters?.file
if (file) {
if (file.mimetype?.startsWith('video')) {
return iconSvgTemplate(mdiMovie) // Media - Videos
}
if (file.mimetype?.startsWith('image')) {
return iconSvgTemplate(mdiImage) // Media - Images
}
if (file.mimetype?.startsWith('audio')) {
return lastMessage.messageType === 'voice-message'
? iconSvgTemplate(mdiMicrophone) // Voice messages
: iconSvgTemplate(mdiMusicNote) // Media - Audio
}
if (file.mimetype === 'text/vcard') {
return iconSvgTemplate(mdiContacts) // Contacts
}
return iconSvgTemplate(mdiFile) // Files
}
const object = lastMessage.messageParameters?.object
if (object) {
if (object?.type === 'talk-poll') {
return iconSvgTemplate(mdiPoll) // Polls
}
if (object?.type === 'deck-card') {
return iconSvgTemplate(mdiCardText) // Deck cards
}
if (object?.type === 'geo-location') {
return iconSvgTemplate(mdiMapMarker) // Locations
}
}
return ''
}