Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/FormatMessage/FormatMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div
v-if="message.markdown"
class="markdown"
:class="{ 'vac-emoji-message': containsOnlyEmojis(message) }"
:class="{ 'vac-emoji-message': containsOnlyOneEmoji(message) }"
@click="openTag"
v-html="message.value"
/>
Expand Down Expand Up @@ -70,7 +70,7 @@ import SvgIcon from '../SvgIcon/SvgIcon'

import markdown from '../../utils/markdown'
import { IMAGE_TYPES } from '../../utils/constants'
import { containsOnlyEmojis } from '../../utils/emoji'
import { containsOnlyEmojis, emojiCount } from '../../utils/emoji'

export default {
name: 'FormatMessage',
Expand Down Expand Up @@ -128,11 +128,11 @@ export default {
},

methods: {
containsOnlyEmojis(message) {
containsOnlyOneEmoji(message) {
const div = document.createElement('div')
div.innerHTML = message.value
const text = div.textContent || div.innerText || ''
return text.length && containsOnlyEmojis(text)
return emojiCount(text) === 1 && containsOnlyEmojis(text)
},
checkType(message, type) {
return message.types && message.types.indexOf(type) !== -1
Expand Down
6 changes: 5 additions & 1 deletion src/utils/emoji/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ export const extractEmojis = text => {

export const containsOnlyEmojis = text => {
const emojisOnly = extractEmojis(text)
return emojisOnly.length === text.toString().length && hasEmoji(emojisOnly)
return emojiCount(text) < text.toString().length && hasEmoji(emojisOnly)
}

export const emojiCount = text => {
return [...new Intl.Segmenter().segment(text)].length
}