Skip to content

Commit

Permalink
DEV2-4419: enable chat for preview users (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 authored Dec 10, 2023
1 parent 0bd9699 commit 25ef60d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public enum Capability {
FORCE_REGISTRATION,
@SerializedName("plugin.feature.tabnine_chat")
TABNINE_CHAT,
@SerializedName("preview")
PREVIEW_CAPABILITY,
@SerializedName("preview_ended")
PREVIEW_ENDED_CAPABILITY,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ import javax.swing.JEditorPane
import javax.swing.event.HyperlinkEvent
import javax.swing.event.HyperlinkListener

const val PREVIEW_ENDED_MESSAGE = """<html>
<body style="padding: 20px;font-family: sans-serif;">
<div style="font-size: 12px; margin-bottom: 8px"><b>Tabnine Chat - Preview Period Ended</b></div>
<div style="font-size: 10px;">
<p style="margin-bottom: 8px">The preview period for Tabnine Chat has now ended. We hope you found our plugin valuable for your coding projects and enjoyed using it.</p>
<p style="margin-bottom: 8px">To continue enjoying Tabnine Chat and explore its full range of features, we invite you to consider subscribing to one of our plans. Detailed information about our pricing and the additional benefits of a subscription can be found on our <a href="https://www.tabnine.com/pricing">pricing page</a>.</p>
<p style="margin-bottom: 8px">If you have any questions or need assistance, our support team is always ready to help. Thank you for your understanding and support!</p>
</div>
</body>
</html>
"""

const val FEATURE_MISSING = """<html>
<body style="padding: 20px;">
<body style="padding: 20px;font-family: sans-serif;">
<div style="font-size: 12px; margin-bottom: 8px"><b>Tabnine Chat is currently in Beta</b></div>
<div style="font-size: 10px;">
<p style="margin-bottom: 8px">We understand that waiting for this awesome feature isn’t easy, but we guarantee it will be worth it.</p>
Expand All @@ -19,7 +31,7 @@ const val FEATURE_MISSING = """<html>
"""

const val PLEASE_LOGIN = """<html>
<body style="padding: 20px;">
<body style="padding: 20px;font-family: sans-serif;">
<div style="font-size: 12px; margin-bottom: 8px"><b>Tabnine Chat is currently in Beta</b></div>
<div style="font-size: 10px;">
<p style="margin-bottom: 8px">We understand that waiting for this awesome feature isn’t easy, but we guarantee it will be worth it.</p>
Expand All @@ -31,7 +43,7 @@ const val PLEASE_LOGIN = """<html>
"""

const val NEED_TO_BE_PART_OF_A_TEAM = """<html>
<body style="padding: 20px;">
<body style="padding: 20px;font-family: sans-serif;">
<div style="font-size: 12px; margin-bottom: 8px"><b>Tabnine Chat</b></div>
<div style="font-size: 10px;">
<p style="margin-bottom: 8px">To use Tabnine chat please make sure you are part of a team.</p>
Expand All @@ -43,6 +55,7 @@ const val NEED_TO_BE_PART_OF_A_TEAM = """<html>
fun createChatDisabledJPane(chatDisabledReason: ChatDisabledReason): JEditorPane {
val htmlContent = when (chatDisabledReason) {
ChatDisabledReason.AUTHENTICATION_REQUIRED -> PLEASE_LOGIN
ChatDisabledReason.PREVIEW_ENDED -> PREVIEW_ENDED_MESSAGE
ChatDisabledReason.FEATURE_REQUIRED -> FEATURE_MISSING
ChatDisabledReason.PART_OF_A_TEAM_REQUIRED -> NEED_TO_BE_PART_OF_A_TEAM
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class ChatState private constructor(

enum class ChatDisabledReason {
AUTHENTICATION_REQUIRED,
PREVIEW_ENDED,
FEATURE_REQUIRED,
PART_OF_A_TEAM_REQUIRED,
}
4 changes: 3 additions & 1 deletion Tabnine/src/main/java/com/tabnine/chat/ChatEnabledState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ class ChatEnabledState private constructor() : ChatFrame.UseChatEnabledState,
val isLoggedIn = binaryState.isLoggedIn ?: return

val hasCapability =
capabilities.anyEnabled(Capability.ALPHA, Capability.TABNINE_CHAT)
capabilities.anyEnabled(Capability.ALPHA, Capability.TABNINE_CHAT, Capability.PREVIEW_CAPABILITY)

if (isLoggedIn && hasCapability) {
set(ChatState.enabled())
} else if (capabilities.isEnabled(Capability.PREVIEW_ENDED_CAPABILITY)) {
set(ChatState.disabled(ChatDisabledReason.PREVIEW_ENDED))
} else if (isLoggedIn) {
set(ChatState.disabled(ChatDisabledReason.FEATURE_REQUIRED))
} else {
Expand Down

0 comments on commit 25ef60d

Please sign in to comment.