From 6bc393772a41090c823119dcaa1333ee525dacdf Mon Sep 17 00:00:00 2001 From: Ofek Ben-Yaish Date: Wed, 22 Nov 2023 17:34:17 +0200 Subject: [PATCH] Fix chat states --- .../com/tabnineCommon/chat/ChatDisabledReason.kt | 6 ++++-- .../main/java/com/tabnine/chat/ChatEnabledState.kt | 12 ++++++++---- .../com/tabnine/chat/TabnineChatWebViewFactory.kt | 4 +--- .../com/tabnineSelfHosted/chat/ChatEnabledState.kt | 12 ++++++++---- .../chat/TabnineChatWebViewFactory.kt | 4 +--- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Common/src/main/java/com/tabnineCommon/chat/ChatDisabledReason.kt b/Common/src/main/java/com/tabnineCommon/chat/ChatDisabledReason.kt index 9d4e5331..d0f9a82b 100644 --- a/Common/src/main/java/com/tabnineCommon/chat/ChatDisabledReason.kt +++ b/Common/src/main/java/com/tabnineCommon/chat/ChatDisabledReason.kt @@ -14,8 +14,10 @@ data class ChatState private constructor( @JvmStatic fun disabled(reason: ChatDisabledReason) = ChatState( - enabled = false, loading = - false, reason + enabled = false, + loading = + false, + reason ) } } diff --git a/Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt b/Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt index 6e3feb9a..fbd0f0ee 100644 --- a/Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt +++ b/Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt @@ -59,11 +59,15 @@ class ChatEnabledState private constructor() : ChatFrame.UseChatEnabledState, } override fun useState( - parent: Disposable, onStateChanged: (state: ChatState) -> Unit + parent: Disposable, + onStateChanged: (state: ChatState) -> Unit ) { - useState(parent, ChatEnabledChanged { - onStateChanged(it) - }) + useState( + parent, + ChatEnabledChanged { + onStateChanged(it) + } + ) } } diff --git a/Tabnine/src/main/java/com/tabnine/chat/TabnineChatWebViewFactory.kt b/Tabnine/src/main/java/com/tabnine/chat/TabnineChatWebViewFactory.kt index bb2f82fe..012bf0f3 100644 --- a/Tabnine/src/main/java/com/tabnine/chat/TabnineChatWebViewFactory.kt +++ b/Tabnine/src/main/java/com/tabnine/chat/TabnineChatWebViewFactory.kt @@ -13,9 +13,7 @@ class TabnineChatWebViewFactory : ToolWindowFactory, Disposable { private val binaryRequestFacade = instanceOfBinaryRequestFacade() override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) { - BinaryStateSingleton.instance.get()?.isLoggedIn == true - } + val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) Disposer.register(toolWindow.disposable, chatFrame) toolWindow.component.add(chatFrame) } diff --git a/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/ChatEnabledState.kt b/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/ChatEnabledState.kt index c9222062..a4d1e0fd 100644 --- a/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/ChatEnabledState.kt +++ b/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/ChatEnabledState.kt @@ -42,11 +42,15 @@ class ChatEnabledState private constructor() : ChatFrame.UseChatEnabledState, } override fun useState( - parent: Disposable, onStateChanged: (state: ChatState) -> Unit + parent: Disposable, + onStateChanged: (state: ChatState) -> Unit ) { - useState(parent, ChatEnabledChanged { - onStateChanged(it) - }) + useState( + parent, + ChatEnabledChanged { + onStateChanged(it) + } + ) } } diff --git a/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/TabnineChatWebViewFactory.kt b/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/TabnineChatWebViewFactory.kt index 29ea131e..eb620d33 100644 --- a/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/TabnineChatWebViewFactory.kt +++ b/TabnineSelfHosted/src/main/java/com/tabnineSelfHosted/chat/TabnineChatWebViewFactory.kt @@ -13,9 +13,7 @@ class TabnineChatWebViewFactory : ToolWindowFactory, Disposable { private val binaryRequestFacade = instanceOfBinaryRequestFacade() override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) { - UserInfoStateSingleton.instance.get()?.isLoggedIn == true - } + val chatFrame = ChatFrame(project, binaryRequestFacade, ChatEnabledState.instance) Disposer.register(toolWindow.disposable, chatFrame) toolWindow.component.add(chatFrame) }