@@ -211,6 +211,8 @@ export class ChatActions extends Actions<ChatState> {
211211 editing : { } ,
212212 } ;
213213 this . syncdb . set ( message ) ;
214+ const messagesState = this . store . get ( "messages" ) ;
215+ let selectedThreadKey : string ;
214216 if ( ! reply_to ) {
215217 this . deleteDraft ( 0 ) ;
216218 // NOTE: we also clear search, since it's confusing to send a message and not
@@ -219,17 +221,26 @@ export class ChatActions extends Actions<ChatState> {
219221 // Also, only do this clearing when not replying.
220222 // For replies search find full threads not individual messages.
221223 this . clearAllFilters ( ) ;
224+ selectedThreadKey = `${ time_stamp . valueOf ( ) } ` ;
222225 } else {
223226 // when replying we make sure that the thread is expanded, since otherwise
224227 // our reply won't be visible
225- const messages = this . store . get ( "messages" ) ;
226228 if (
227- messages
229+ messagesState
228230 ?. getIn ( [ `${ reply_to . valueOf ( ) } ` , "folding" ] )
229231 ?. includes ( sender_id )
230232 ) {
231233 this . toggleFoldThread ( reply_to ) ;
232234 }
235+ const root =
236+ getThreadRootDate ( {
237+ date : reply_to . valueOf ( ) ,
238+ messages : messagesState ,
239+ } ) ?? reply_to . valueOf ( ) ;
240+ selectedThreadKey = `${ root } ` ;
241+ }
242+ if ( selectedThreadKey != "0" ) {
243+ this . setSelectedThread ( selectedThreadKey ) ;
233244 }
234245
235246 const project_id = this . store ?. get ( "project_id" ) ;
@@ -1249,6 +1260,7 @@ export class ChatActions extends Actions<ChatState> {
12491260 } ;
12501261
12511262 setSelectedThread = ( threadKey : string | null ) => {
1263+ console . log ( "setSelectedThread" , { threadKey } ) ;
12521264 this . frameTreeActions ?. set_frame_data ( {
12531265 id : this . frameId ,
12541266 selectedThreadKey : threadKey ,
0 commit comments