Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV2-4200: Fix inconsistent behavior (also DEV2-3330) #692

Merged
merged 31 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a1992e0
Change text to be more accurate
ofekby Nov 19, 2023
23c6ef0
Update update functionality to be more separate and consistent
ofekby Nov 20, 2023
3c52f51
Fix toolbar to be more consistent
ofekby Nov 21, 2023
e57eaa3
Formatting
ofekby Nov 21, 2023
f555549
Merge remote-tracking branch 'origin/master' into fix-inconsistent-be…
ofekby Nov 21, 2023
353f2b2
CI fixes
ofekby Nov 21, 2023
5550d04
Change to only show once
ofekby Nov 21, 2023
6860c3d
Change to control with thread safe mechanism
ofekby Nov 21, 2023
8bff124
Fix self hosted
ofekby Nov 21, 2023
be24ce3
Formatting
ofekby Nov 21, 2023
51278b9
Fix test
ofekby Nov 21, 2023
3d9bfb2
Fix test
ofekby Nov 21, 2023
8cfadc0
Make notification push more accurate
ofekby Nov 22, 2023
ebff99d
Make force registration more accurate
ofekby Nov 22, 2023
a98c1db
Formatting
ofekby Nov 22, 2023
82d83a3
Optimize locking time
ofekby Nov 22, 2023
66cf175
Make value volatile
ofekby Nov 22, 2023
6d8a186
Format
ofekby Nov 22, 2023
00238c3
Format
ofekby Nov 22, 2023
447f2eb
Format
ofekby Nov 22, 2023
32dec4e
Fix chat states
ofekby Nov 22, 2023
6bc3937
Fix chat states
ofekby Nov 22, 2023
f7e258a
Fix unused import
ofekby Nov 22, 2023
1134625
Fix authentication required
ofekby Nov 22, 2023
1cc622b
Remove useless vars
ofekby Nov 22, 2023
4cac9db
Change to use state
ofekby Nov 23, 2023
12ea07c
Change initialization
ofekby Nov 23, 2023
7a7b705
Try expire notification when new notification present
ofekby Nov 23, 2023
6a4d6db
Change state function name
ofekby Nov 27, 2023
5622853
Rename and get current state
ofekby Nov 27, 2023
d3f0a2e
Fix is enabled bug
ofekby Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package com.tabnineCommon.binary.requests.login
import com.tabnineCommon.binary.BinaryRequest
import com.tabnineCommon.binary.requests.EmptyResponse

class LogoutRequest : BinaryRequest<EmptyResponse> {
class LogoutRequest(private val onSuccessFn: (() -> Unit)? = null) : BinaryRequest<EmptyResponse> {
override fun response(): Class<EmptyResponse> {
return EmptyResponse::class.java
}

override fun serialize(): Any {
return mapOf("Logout" to this)
}

override fun onSuccess(response: EmptyResponse?) {
onSuccessFn?.let { it() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import com.tabnineCommon.binary.requests.capabilities.RefreshRemotePropertiesRequest;
import com.tabnineCommon.config.Config;
import com.tabnineCommon.general.DependencyContainer;
import com.tabnineCommon.lifecycle.BinaryCapabilitiesChangeNotifier;
import com.tabnineCommon.lifecycle.CapabilitiesStateSingleton;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand All @@ -31,7 +32,6 @@ public class CapabilitiesService {

private final BinaryRequestFacade binaryRequestFacade =
DependencyContainer.instanceOfBinaryRequestFacade();
private final Set<Capability> enabledCapabilities = new HashSet<>();

public static CapabilitiesService getInstance() {
return ServiceManager.getService(CapabilitiesService.class);
Expand All @@ -45,9 +45,18 @@ public boolean isCapabilityEnabled(Capability capability) {
if (Config.IS_SELF_HOSTED) {
return true;
}
synchronized (enabledCapabilities) {
return enabledCapabilities.contains(capability);
}

return CapabilitiesStateSingleton.getInstance()
.getOptional()
.map(c -> c.isEnabled(capability))
.orElse(false);
}

public boolean isReady() {
return CapabilitiesStateSingleton.getInstance()
.getOptional()
.map(Capabilities::isReady)
.orElse(false);
}

public void forceRefreshCapabilities() {
Expand Down Expand Up @@ -84,11 +93,6 @@ private void fetchCapabilitiesLoop() {
lastRefresh = Optional.of(System.currentTimeMillis());
lastPid = Optional.of(pid);
}
if (!enabledCapabilities.isEmpty()) {
this.messageBus
.syncPublisher(BinaryCapabilitiesChangeNotifier.CAPABILITIES_CHANGE_NOTIFIER_TOPIC)
.notifyFetched();
}
} catch (Throwable t) {
Logger.getInstance(getClass()).debug("Unexpected error. Capabilities refresh failed", t);
}
Expand All @@ -114,19 +118,16 @@ private void fetchCapabilities() {
}

private void setCapabilities(CapabilitiesResponse capabilitiesResponse) {
synchronized (enabledCapabilities) {
Set<Capability> newCapabilities = new HashSet<>();

capabilitiesResponse.getEnabledFeatures().stream()
.filter(Objects::nonNull)
.forEach(newCapabilities::add);

if (!newCapabilities.equals(enabledCapabilities)) {
enabledCapabilities.clear();
enabledCapabilities.addAll(newCapabilities);
CapabilityNotifier.Companion.publish(
new Capabilities(newCapabilities, capabilitiesResponse.getExperimentSource()));
}
Set<Capability> newCapabilities = new HashSet<>();
List<Capability> capabilities = capabilitiesResponse.getEnabledFeatures();

if (capabilities != null) {
capabilities.stream().filter(Objects::nonNull).forEach(newCapabilities::add);
}

Capabilities newCapabilitiesState =
new Capabilities(newCapabilities, capabilitiesResponse.getExperimentSource());

CapabilitiesStateSingleton.getInstance().set(newCapabilitiesState);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,49 @@ import javax.swing.JEditorPane
import javax.swing.event.HyperlinkEvent
import javax.swing.event.HyperlinkListener

val LOGIN_BUTTON = "<p>If you already have access to chat, please <a href=\"https://app.tabnine.com/signin\">sign in</a></p>".trimIndent()
const val FEATURE_MISSING = """<html>
<body style="padding: 20px;">
<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>
<p style="margin-bottom: 8px">Tabnine Chat will soon be available to all users, and we'll make sure to keep you informed. Thank you for your patience! <a href="https://www.tabnine.com/#ChatSection"> Learn more</a></p>
</div>
</body>
</html>
"""

fun createChatDisabledJPane(isLoggedIn: Boolean = false): JEditorPane {
val pane = JEditorPane(
"text/html",
"""<html>
const val PLEASE_LOGIN = """<html>
<body style="padding: 20px;">
<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>
<p style="margin-bottom: 8px">Tabnine Chat will soon be available to all users, and we'll make sure to keep you informed. Thank you for your patience! <a href="https://www.tabnine.com/#ChatSection"> Learn more</a></p>
${if (!isLoggedIn) LOGIN_BUTTON else ""}
<p>If you already have access to chat, please <a href="https://app.tabnine.com/signin">sign in</a></p>
</div>
</body>
</html>
""".trimIndent()
"""

const val NEED_TO_BE_PART_OF_A_TEAM = """<html>
<body style="padding: 20px;">
<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>
</div>
</body>
</html>
"""

fun createChatDisabledJPane(chatDisabledReason: ChatDisabledReason): JEditorPane {
val htmlContent = when (chatDisabledReason) {
ChatDisabledReason.AUTHENTICATION_REQUIRED -> PLEASE_LOGIN
ChatDisabledReason.FEATURE_REQUIRED -> FEATURE_MISSING
ChatDisabledReason.PART_OF_A_TEAM_REQUIRED -> NEED_TO_BE_PART_OF_A_TEAM
}

val pane = JEditorPane(
"text/html",
htmlContent.trimIndent()
).apply {
isEditable = false
isOpaque = false
Expand Down
29 changes: 29 additions & 0 deletions Common/src/main/java/com/tabnineCommon/chat/ChatDisabledReason.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.tabnineCommon.chat

data class ChatState private constructor(
val enabled: Boolean,
val loading: Boolean,
val chatDisabledReason: ChatDisabledReason?
) {
companion object {
@JvmStatic
fun enabled() = ChatState(enabled = true, loading = false, null)

@JvmStatic
fun loading() = ChatState(enabled = false, loading = true, null)

@JvmStatic
fun disabled(reason: ChatDisabledReason) = ChatState(
enabled = false,
loading =
false,
reason
)
}
}

enum class ChatDisabledReason {
AUTHENTICATION_REQUIRED,
FEATURE_REQUIRED,
PART_OF_A_TEAM_REQUIRED,
}
60 changes: 0 additions & 60 deletions Common/src/main/java/com/tabnineCommon/chat/ChatEnabled.kt

This file was deleted.

Loading