132
132
</template >
133
133
</room-message-reply >
134
134
135
+ <room-emojis
136
+ :filtered-emojis =" filteredEmojis"
137
+ @select-emoji =" selectEmoji($event)"
138
+ />
139
+
135
140
<room-users-tag
136
141
:filtered-users-tag =" filteredUsersTag"
137
142
@select-user-tag =" selectUserTag($event)"
138
143
/>
139
144
140
145
<div
141
146
class =" vac-box-footer"
142
- :class =" { 'vac-app-box-shadow': filteredUsersTag.length }"
147
+ :class =" {
148
+ 'vac-app-box-shadow': filteredEmojis.length || filteredUsersTag.length
149
+ }"
143
150
>
144
151
<div
145
152
v-if =" showAudio && !imageFile && !videoFile"
@@ -330,6 +337,7 @@ import EmojiPicker from '../../components/EmojiPicker'
330
337
import RoomHeader from ' ./RoomHeader'
331
338
import RoomMessageReply from ' ./RoomMessageReply'
332
339
import RoomUsersTag from ' ./RoomUsersTag'
340
+ import RoomEmojis from ' ./RoomEmojis'
333
341
import Message from ' ../Message/Message'
334
342
335
343
import filteredUsers from ' ../../utils/filter-items'
@@ -348,6 +356,7 @@ export default {
348
356
RoomHeader,
349
357
RoomMessageReply,
350
358
RoomUsersTag,
359
+ RoomEmojis,
351
360
Message
352
361
},
353
362
@@ -402,6 +411,7 @@ export default {
402
411
scrollMessagesCount: 0 ,
403
412
newMessages: [],
404
413
keepKeyboardOpen: false ,
414
+ filteredEmojis: [],
405
415
filteredUsersTag: [],
406
416
selectedUsersTag: [],
407
417
textareaCursorPosition: null ,
@@ -521,16 +531,18 @@ export default {
521
531
}
522
532
}
523
533
524
- this .updateShowUsersTag ()
534
+ this .updateFooterList (' @' )
535
+ this .updateFooterList (' :' )
525
536
})
526
537
527
538
this .$refs [' roomTextarea' ].addEventListener (' click' , () => {
528
539
if (isMobile) this .keepKeyboardOpen = true
529
- this .updateShowUsersTag ()
540
+ this .updateFooterList (' @' )
541
+ this .updateFooterList (' :' )
530
542
})
531
543
532
544
this .$refs [' roomTextarea' ].addEventListener (' blur' , () => {
533
- this .resetUsersTag ()
545
+ this .resetFooterList ()
534
546
if (isMobile) setTimeout (() => (this .keepKeyboardOpen = false ), 0 )
535
547
})
536
548
},
@@ -550,9 +562,15 @@ export default {
550
562
this .scrollIcon = bottomScroll > 500 || this .scrollMessagesCount
551
563
}, 200 )
552
564
},
553
- updateShowUsersTag ( ) {
565
+ updateFooterList ( tagChar ) {
554
566
if (! this .$refs [' roomTextarea' ]) return
555
- if (! this .room .users || this .room .users .length <= 2 ) return
567
+
568
+ if (
569
+ tagChar === ' @' &&
570
+ (! this .room .users || this .room .users .length <= 2 )
571
+ ) {
572
+ return
573
+ }
556
574
557
575
if (
558
576
this .textareaCursorPosition ===
@@ -567,7 +585,7 @@ export default {
567
585
568
586
while (
569
587
position > 0 &&
570
- this .message .charAt (position - 1 ) !== ' @ ' &&
588
+ this .message .charAt (position - 1 ) !== tagChar &&
571
589
this .message .charAt (position - 1 ) !== ' '
572
590
) {
573
591
position--
@@ -577,25 +595,23 @@ export default {
577
595
const notLetterNumber = ! beforeTag .match (/ ^ [0-9a-zA-Z ] + $ / )
578
596
579
597
if (
580
- this .message .charAt (position - 1 ) === ' @ ' &&
598
+ this .message .charAt (position - 1 ) === tagChar &&
581
599
(! beforeTag || beforeTag === ' ' || notLetterNumber)
582
600
) {
583
601
const query = this .message .substring (
584
602
position,
585
603
this .textareaCursorPosition
586
604
)
587
-
588
- this .filteredUsersTag = filteredUsers (
589
- this .room .users ,
590
- ' username' ,
591
- query,
592
- true
593
- ).filter (user => user ._id !== this .currentUserId )
605
+ if (tagChar === ' :' ) {
606
+ this .updateEmojis (query)
607
+ } else if (tagChar === ' @' ) {
608
+ this .updateShowUsersTag (query)
609
+ }
594
610
} else {
595
- this .resetUsersTag ()
611
+ this .resetFooterList ()
596
612
}
597
613
},
598
- selectUserTag ( user ) {
614
+ getCharPosition ( ) {
599
615
const cursorPosition = this .$refs [' roomTextarea' ].selectionStart
600
616
601
617
let position = cursorPosition
@@ -611,6 +627,37 @@ export default {
611
627
endPosition++
612
628
}
613
629
630
+ return { position, endPosition }
631
+ },
632
+ updateEmojis (query ) {
633
+ if (! query) return
634
+
635
+ const emojisListKeys = Object .keys (this .emojisList )
636
+ const matchingKeys = emojisListKeys .filter (key => key .startsWith (query))
637
+
638
+ this .filteredEmojis = matchingKeys .map (key => this .emojisList [key])
639
+ },
640
+ selectEmoji (emoji ) {
641
+ const { position , endPosition } = this .getCharPosition ()
642
+
643
+ this .message =
644
+ this .message .substr (0 , position - 1 ) +
645
+ emoji +
646
+ this .message .substr (endPosition, this .message .length - 1 )
647
+
648
+ this .focusTextarea ()
649
+ },
650
+ updateShowUsersTag (query ) {
651
+ this .filteredUsersTag = filteredUsers (
652
+ this .room .users ,
653
+ ' username' ,
654
+ query,
655
+ true
656
+ ).filter (user => user ._id !== this .currentUserId )
657
+ },
658
+ selectUserTag (user ) {
659
+ const { position , endPosition } = this .getCharPosition ()
660
+
614
661
const space = this .message .substr (endPosition, endPosition).length
615
662
? ' '
616
663
: ' '
@@ -625,7 +672,8 @@ export default {
625
672
626
673
this .focusTextarea ()
627
674
},
628
- resetUsersTag () {
675
+ resetFooterList () {
676
+ this .filteredEmojis = []
629
677
this .filteredUsersTag = []
630
678
this .textareaCursorPosition = null
631
679
},
@@ -657,7 +705,7 @@ export default {
657
705
}
658
706
659
707
this .selectedUsersTag = []
660
- this .resetUsersTag ()
708
+ this .resetFooterList ()
661
709
this .resetTextareaSize ()
662
710
this .message = ' '
663
711
this .editedMessage = {}
0 commit comments