Skip to content

Commit

Permalink
enable chat for preview users
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 committed Dec 6, 2023
1 parent c853705 commit 46e33cd
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@
"name": "Chat",
"when": "tabnine.chat.webview == 'chat'"
},
{
"id": "tabnine.chat.preview_ended",
"type": "webview",
"name": "Preview ended",
"when": "tabnine.chat.webview == 'preview_ended'"
},
{
"id": "tabnine.chat.welcome",
"type": "webview",
Expand Down
2 changes: 2 additions & 0 deletions src/capabilities/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum Capability {
TEST_GEN = "vscode_test_gen",
FORCE_REGISTRATION = "plugin.feature.force_registration",
TABNINE_CHAT = "plugin.feature.tabnine_chat",
PREVIEW_CAPABILITIY = "preview",
PREVIEW_ENDED_CAPABILITIY = "preview_ended",
}

let enabledCapabilities: Record<string, boolean> | null = null;
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import BINARY_STATE from "./binary/binaryStateSingleton";
import EvalSaasChatEnabledState from "./tabnineChatWidget/EvalSaasChatEnabledState";
import { ChatAPI } from "./tabnineChatWidget/ChatApi";
import ChatViewProvider from "./tabnineChatWidget/ChatViewProvider";
import { previewEndedView } from "./tabnineChatWidget/webviews/previewEndedView";

export async function activate(
context: vscode.ExtensionContext
Expand Down Expand Up @@ -127,6 +128,7 @@ async function backgroundInit(context: vscode.ExtensionContext) {
void callForLogin();
});
context.subscriptions.push(
previewEndedView(context),
emptyStateWelcomeView(context),
emptyStateAuthenticateView(context)
);
Expand Down
1 change: 1 addition & 0 deletions src/tabnineChatWidget/ChatEnabledState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Disposable } from "vscode";

export type ChatNotEnabledReason =
| "preview_ended"
| "capability_required"
| "authnetication_required"
| "part_of_a_team_required";
Expand Down
9 changes: 8 additions & 1 deletion src/tabnineChatWidget/SaasChatEnabledState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export default class SaasChatEnabledState

if (getIsCapabilitesEnabled()) {
this.set(ChatStates.enabled);
} else if (isPreviewEnded()) {
this.set(ChatStates.disabled("preview_ended"));
} else if (isLoggedIn) {
this.set(ChatStates.disabled("capability_required"));
} else {
Expand All @@ -54,6 +56,11 @@ export default class SaasChatEnabledState
function getIsCapabilitesEnabled() {
return (
isCapabilityEnabled(Capability.ALPHA_CAPABILITY) ||
isCapabilityEnabled(Capability.TABNINE_CHAT)
isCapabilityEnabled(Capability.TABNINE_CHAT) ||
isCapabilityEnabled(Capability.PREVIEW_CAPABILITIY)
);
}

function isPreviewEnded(): boolean {
return isCapabilityEnabled(Capability.PREVIEW_ENDED_CAPABILITIY);
}
21 changes: 21 additions & 0 deletions src/tabnineChatWidget/webviews/previewEnded.html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { template } from "./template.html";

export const PREVIEW_ENDED_MESSAGE = `
<div style="font-size: 14px;">
<h3>Tabnine Chat - Preview Period Ended</h3>
<p>
The preview period for Tabnine Chat in Visual Studio Code has now ended. We hope you found it valuable for your coding projects and enjoyed the experience.
</p>
<p>
To continue using Tabnine Chat and access its full range of features, we invite you to subscribe to one of our plans.
</p>
<p>
You can find detailed information about our pricing and the additional benefits of a subscription on our <a href="https://www.tabnine.com/pricing">pricing page</a>.
</p>
<p>
If you have any questions or need assistance, our support team is always ready to help.
</p>
</div>`;

export const html = (logoSrc: string) =>
template(PREVIEW_ENDED_MESSAGE, logoSrc);
31 changes: 31 additions & 0 deletions src/tabnineChatWidget/webviews/previewEndedView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Disposable, ExtensionContext, WebviewView, window } from "vscode";
import { fireEvent } from "../../binary/requests/requests";
import { html } from "./previewEnded.html";
import { getIcon } from "./getIcon";

export function previewEndedView(context: ExtensionContext): Disposable {
return window.registerWebviewViewProvider("tabnine.chat.preview_ended", {
resolveWebviewView(webviewView: WebviewView) {
context.subscriptions.push(
webviewView.onDidChangeVisibility(() => {
if (webviewView.visible) {
void fireEvent({
name: "tabnine-chat-preview-ended-visible",
});
}
})
);
const view = webviewView.webview;
view.options = {
enableScripts: true,
enableCommandUris: true,
};
const logoSrc = getIcon(context, view);
view.html = html(logoSrc);

void fireEvent({
name: "tabnine-chat-preview-ended-inited",
});
},
});
}

0 comments on commit 46e33cd

Please sign in to comment.