Skip to content

Commit

Permalink
DEV2-3866 invoke binary to get server url (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
amircodota committed Oct 12, 2023
1 parent ae5a801 commit 10a45cd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tabnineCommon.binary.requests.config

import com.google.gson.annotations.SerializedName
import com.tabnineCommon.binary.BinaryRequest

enum class ChatCommunicationKind {
@SerializedName("forward")
Forward
}
class ChatCommunicatorAddressRequest(val kind: ChatCommunicationKind) : BinaryRequest<ChatCommunicatorAddressResponse> {
override fun response(): Class<ChatCommunicatorAddressResponse> {
return ChatCommunicatorAddressResponse::class.java
}

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

override fun validate(response: ChatCommunicatorAddressResponse): Boolean {
return true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tabnineCommon.binary.requests.config

import com.tabnineCommon.binary.BinaryResponse

data class ChatCommunicatorAddressResponse(val address: String) : BinaryResponse
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public enum Capability {
@SerializedName("plugin.feature.force_registration")
FORCE_REGISTRATION,
@SerializedName("plugin.feature.tabnine_chat")
TABNINE_CHAT
TABNINE_CHAT,
@SerializedName("chat_url_from_binary")
CHAT_URL_FROM_BINARY,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ package com.tabnineCommon.chat.commandHandlers
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.intellij.openapi.project.Project
import com.tabnineCommon.binary.requests.config.ChatCommunicationKind
import com.tabnineCommon.binary.requests.config.ChatCommunicatorAddressRequest
import com.tabnineCommon.capabilities.CapabilitiesService
import com.tabnineCommon.capabilities.Capability
import com.tabnineCommon.chat.commandHandlers.utils.getServerUrl
import com.tabnineCommon.general.DependencyContainer

data class ServerUrlRequest(val kind: ChatCommunicationKind)
data class ServerUrlResponse(val serverUrl: String)

class GetServerUrlHandler(gson: Gson) : ChatMessageHandler<Unit, ServerUrlResponse>(gson) {
override fun handle(payload: Unit?, project: Project): ServerUrlResponse {
class GetServerUrlHandler(gson: Gson) : ChatMessageHandler<ServerUrlRequest, ServerUrlResponse>(gson) {
override fun handle(payload: ServerUrlRequest?, project: Project): ServerUrlResponse {
if (CapabilitiesService.getInstance().isCapabilityEnabled(Capability.CHAT_URL_FROM_BINARY) && payload != null) {
val response = DependencyContainer.instanceOfBinaryRequestFacade().executeRequest(ChatCommunicatorAddressRequest(payload.kind))
return ServerUrlResponse(response.address)
}

val serverUrl = getServerUrl() ?: "https://api.tabnine.com"
return ServerUrlResponse(serverUrl)
}

override fun deserializeRequest(data: JsonElement?) {
override fun deserializeRequest(data: JsonElement?): ServerUrlRequest {
return gson.fromJson(data, ServerUrlRequest::class.java)
}
}

0 comments on commit 10a45cd

Please sign in to comment.