Skip to content

Commit f666df7

Browse files
committed
(fix) update users tag conditions
1 parent ab17959 commit f666df7

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

src/ChatWindow/Room.vue

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -586,44 +586,45 @@ export default {
586586
587587
methods: {
588588
updateShowUsersTag() {
589-
if (this.$refs['roomTextarea'] && this.room.users.length > 2) {
590-
if (
591-
this.textareaCursorPosition ===
592-
this.$refs['roomTextarea'].selectionStart
593-
) {
594-
return
595-
}
589+
if (!this.$refs['roomTextarea']) return
590+
if (!this.room.users || this.room.users.length <= 2) return
596591
597-
this.textareaCursorPosition = this.$refs['roomTextarea'].selectionStart
592+
if (
593+
this.textareaCursorPosition ===
594+
this.$refs['roomTextarea'].selectionStart
595+
) {
596+
return
597+
}
598598
599-
let n = this.textareaCursorPosition
599+
this.textareaCursorPosition = this.$refs['roomTextarea'].selectionStart
600600
601-
while (
602-
n > 0 &&
603-
this.message.charAt(n - 1) !== '@' &&
604-
this.message.charAt(n - 1) !== ' '
605-
) {
606-
n--
607-
}
601+
let n = this.textareaCursorPosition
608602
609-
const beforeTag = this.message.charAt(n - 2)
610-
const notLetterNumber = !beforeTag.match(/^[0-9a-zA-Z]+$/)
611-
612-
if (
613-
this.message.charAt(n - 1) === '@' &&
614-
(!beforeTag || beforeTag === ' ' || notLetterNumber)
615-
) {
616-
const query = this.message.substring(n, this.textareaCursorPosition)
617-
618-
this.filteredUsersTag = filteredUsers(
619-
this.room.users,
620-
'username',
621-
query,
622-
true
623-
).filter(user => user._id !== this.currentUserId)
624-
} else {
625-
this.resetUsersTag()
626-
}
603+
while (
604+
n > 0 &&
605+
this.message.charAt(n - 1) !== '@' &&
606+
this.message.charAt(n - 1) !== ' '
607+
) {
608+
n--
609+
}
610+
611+
const beforeTag = this.message.charAt(n - 2)
612+
const notLetterNumber = !beforeTag.match(/^[0-9a-zA-Z]+$/)
613+
614+
if (
615+
this.message.charAt(n - 1) === '@' &&
616+
(!beforeTag || beforeTag === ' ' || notLetterNumber)
617+
) {
618+
const query = this.message.substring(n, this.textareaCursorPosition)
619+
620+
this.filteredUsersTag = filteredUsers(
621+
this.room.users,
622+
'username',
623+
query,
624+
true
625+
).filter(user => user._id !== this.currentUserId)
626+
} else {
627+
this.resetUsersTag()
627628
}
628629
},
629630
selectUserTag(user) {

0 commit comments

Comments
 (0)