@@ -26,14 +26,21 @@ export class TabBarController {
2626 constructor ( messenger : Messenger ) {
2727 this . messenger = messenger
2828 }
29- processActionClickMessage ( msg : DetailedListActionClickMessage ) {
29+ async processActionClickMessage ( msg : DetailedListActionClickMessage ) {
3030 if ( msg . listType === 'history' ) {
3131 if ( msg . action . text === 'Delete' ) {
3232 this . chatHistoryDb . deleteHistory ( msg . action . id )
3333 this . messenger . sendUpdateDetailedListMessage ( 'history' , { list : this . generateHistoryList ( ) } )
3434 } else if ( msg . action . text === 'Export' ) {
35- const selectedTab = this . chatHistoryDb . getTab ( msg . action . id )
36- this . restoreTab ( selectedTab , true )
35+ // If conversation is already open, export it
36+ const openTabId = this . chatHistoryDb . getOpenTabId ( msg . action . id )
37+ if ( openTabId ) {
38+ await this . exportChatButtonClicked ( { tabID : openTabId , buttonId : 'export_chat' } )
39+ } // If conversation is not open, restore it before exporting
40+ else {
41+ const selectedTab = this . chatHistoryDb . getTab ( msg . action . id )
42+ this . restoreTab ( selectedTab , true )
43+ }
3744 }
3845 }
3946 }
@@ -58,13 +65,14 @@ export class TabBarController {
5865 }
5966 }
6067
68+ // If selected is conversation is already open, select that tab. Else, open new tab with conversation.
6169 processItemSelectMessage ( msg : DetailedListItemSelectMessage ) {
6270 if ( msg . listType === 'history' ) {
6371 const historyID = msg . item . id
6472 if ( historyID ) {
65- const selectedTab = this . chatHistoryDb . getTab ( historyID )
66- const openTabID = this . chatHistoryDb . getTabId ( historyID )
67- if ( ! selectedTab ?. isOpen || ! openTabID ) {
73+ const openTabID = this . chatHistoryDb . getOpenTabId ( historyID )
74+ if ( ! openTabID ) {
75+ const selectedTab = this . chatHistoryDb . getTab ( historyID )
6876 this . restoreTab ( selectedTab )
6977 } else {
7078 this . messenger . sendSelectTabMessage ( openTabID , historyID )
0 commit comments