Skip to content

Commit aa2676d

Browse files
committed
(UI) formatString rooms last message
1 parent 16d3a02 commit aa2676d

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/ChatWindow/Message.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export default {
311311
312312
computed: {
313313
linkifiedMessage() {
314-
return formatString(this.message.content)
314+
return formatString(this.message.content, true)
315315
},
316316
showDate() {
317317
return (

src/ChatWindow/RoomsList.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
<span v-if="room.lastMessage.seen">
6464
<svg-icon name="checkmark" class="icon-check" />
6565
</span>
66-
<span>{{ getLastMessage(room) }}</span>
66+
<span v-for="(message, i) in getLastMessage(room)" :key="i">
67+
<span v-if="message.bind" v-html="message.content"></span>
68+
<span v-else>{{ message.content }}</span>
69+
</span>
6770
</div>
6871
</div>
6972
</div>
@@ -76,6 +79,7 @@ import Loader from './Loader'
7679
import SvgIcon from './SvgIcon'
7780
7881
import filteredUsers from '../utils/filterItems'
82+
import formatString from '../utils/formatString'
7983
8084
export default {
8185
name: 'rooms-list',
@@ -132,15 +136,19 @@ export default {
132136
if (user.status) return user.status.state
133137
},
134138
getLastMessage(room) {
135-
if (room.users.length <= 2) return room.lastMessage.content
139+
if (room.users.length <= 2) {
140+
return formatString(room.lastMessage.content)
141+
}
136142
137143
const user = room.users.find(
138144
user => user._id === room.lastMessage.sender_id
139145
)
140146
141-
if (user._id === this.currentUserId) return room.lastMessage.content
147+
if (user._id === this.currentUserId) {
148+
return formatString(room.lastMessage.content)
149+
}
142150
143-
return `${user.username} - ${room.lastMessage.content}`
151+
return `${user.username} - ${formatString(room.lastMessage.content)}`
144152
}
145153
}
146154
}

src/utils/formatString.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const linkify = require('linkifyjs')
22
import linkifyHtml from 'linkifyjs/html'
33

4-
export default text => {
4+
export default (text, doLinkify = false) => {
55
const strings = text.split(' ')
66

77
const formattedStrings = strings.map((string, i) => {
88
const links = linkify.find(string)
99

1010
let result = ''
1111

12-
if (links.length && string === links[0].value) {
12+
if (doLinkify && links.length && string === links[0].value) {
1313
result = {
1414
bind: true,
1515
content: linkifyHtml(links[0].value, {

0 commit comments

Comments
 (0)