@@ -4,53 +4,58 @@ import ChatbotLaunch from "../components/chatbot-launch";
44export default apiInitializer ( "1.8.0" , ( api ) => {
55 const siteSettings = api . container . lookup ( "service:site-settings" ) ;
66
7- api . modifyClass ( "component:chat-channel" , {
8- pluginId : "discourse-chatbot" ,
9- async fetchMessages ( findArgs = { } ) {
10- if ( this . messagesLoader . loading ) {
11- return ;
12- }
7+ api . modifyClass (
8+ "component:chat-channel" ,
9+ ( Superclass ) =>
10+ class extends Superclass {
11+ async fetchMessages ( findArgs = { } ) {
12+ if ( this . messagesLoader . loading ) {
13+ return ;
14+ }
1315
14- this . messagesManager . clear ( ) ;
16+ this . messagesManager . clear ( ) ;
1517
16- const result = await this . messagesLoader . load ( findArgs ) ;
17- this . messagesManager . messages = this . processMessages (
18- this . args . channel ,
19- result
20- ) ;
21- if ( findArgs . target_message_id ) {
22- this . scrollToMessageId ( findArgs . target_message_id , {
23- highlight : true ,
24- position : findArgs . position ,
25- } ) ;
26- } else if ( findArgs . fetch_from_last_read ) {
27- const lastReadMessageId = this . currentUserMembership ?. lastReadMessageId ;
28- if (
29- this . args . channel . chatable . type === "DirectMessage" &&
30- this . args . channel . unicodeTitle === this . siteSettings . chatbot_bot_user
31- ) {
32- this . scrollToMessageId (
33- this . messagesManager . messages [
34- this . messagesManager . messages . length - 1
35- ] . id
18+ const result = await this . messagesLoader . load ( findArgs ) ;
19+ this . messagesManager . messages = this . processMessages (
20+ this . args . channel ,
21+ result
3622 ) ;
37- } else {
38- this . scrollToMessageId ( lastReadMessageId ) ;
23+ if ( findArgs . target_message_id ) {
24+ this . scrollToMessageId ( findArgs . target_message_id , {
25+ highlight : true ,
26+ position : findArgs . position ,
27+ } ) ;
28+ } else if ( findArgs . fetch_from_last_read ) {
29+ const lastReadMessageId =
30+ this . currentUserMembership ?. lastReadMessageId ;
31+ if (
32+ this . args . channel . chatable . type === "DirectMessage" &&
33+ this . args . channel . unicodeTitle ===
34+ this . siteSettings . chatbot_bot_user
35+ ) {
36+ this . scrollToMessageId (
37+ this . messagesManager . messages [
38+ this . messagesManager . messages . length - 1
39+ ] . id
40+ ) ;
41+ } else {
42+ this . scrollToMessageId ( lastReadMessageId ) ;
43+ }
44+ } else if ( findArgs . target_date ) {
45+ this . scrollToMessageId ( result . meta . target_message_id , {
46+ highlight : true ,
47+ position : "center" ,
48+ } ) ;
49+ } else {
50+ this . _ignoreNextScroll = true ;
51+ this . scrollToBottom ( ) ;
52+ }
53+
54+ this . debounceFillPaneAttempt ( ) ;
55+ this . debouncedUpdateLastReadMessage ( ) ;
3956 }
40- } else if ( findArgs . target_date ) {
41- this . scrollToMessageId ( result . meta . target_message_id , {
42- highlight : true ,
43- position : "center" ,
44- } ) ;
45- } else {
46- this . _ignoreNextScroll = true ;
47- this . scrollToBottom ( ) ;
4857 }
49-
50- this . debounceFillPaneAttempt ( ) ;
51- this . debouncedUpdateLastReadMessage ( ) ;
52- } ,
53- } ) ;
58+ ) ;
5459
5560 if ( siteSettings . chatbot_quick_access_bot_post_kicks_off ) {
5661 api . registerValueTransformer (
0 commit comments