From f7ab437fd4e5f2d2f8bb52489030061fc5fc7fc9 Mon Sep 17 00:00:00 2001 From: Gemma Tipper Date: Thu, 16 May 2024 18:19:26 +0100 Subject: [PATCH] Add message inviting user to Discord every 10 usages --- changelog.d/114.added.md | 1 + src/api.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 changelog.d/114.added.md diff --git a/changelog.d/114.added.md b/changelog.d/114.added.md new file mode 100644 index 00000000..349507fc --- /dev/null +++ b/changelog.d/114.added.md @@ -0,0 +1 @@ +Users will ocassionally be invited to join the Discord server \ No newline at end of file diff --git a/src/api.ts b/src/api.ts index e76a81ec..e70f6312 100644 --- a/src/api.ts +++ b/src/api.ts @@ -17,6 +17,16 @@ const FEEDBACK_COUNTER = 'mirrord-feedback-counter'; */ const FEEDBACK_COUNTER_REVIEW_AFTER = 100; +/** +* Key to access the feedback counter (see `tickDiscordCounter`) from the global user config. +*/ +const DISCORD_COUNTER = 'mirrord-discord-counter'; + +/** +* Amount of times we run mirrord before inviting the user to join the Discord server. +*/ +const DISCORD_COUNTER_PROMPT_AFTER = 10; + const TARGET_TYPE_DISPLAY: Record = { pod: 'Pod', deployment: 'Deployment', @@ -378,6 +388,7 @@ export class MirrordAPI { async binaryExecute(target: string | null, configFile: string | null, executable: string | null, configEnv: EnvVars): Promise { tickMirrordForTeamsCounter(); tickFeedbackCounter(); + tickDiscordCounter(); /// Create a promise that resolves when the mirrord process exits return await vscode.window.withProgress({ @@ -543,3 +554,24 @@ function tickFeedbackCounter() { .info(); } } + +/** +* Updates the global Discord counter. +* After each `DISCORD_COUNTER_PROMPT_AFTER` mirrord runs, displays a message asking the user to join the discord. +*/ +function tickDiscordCounter() { + const previousRuns = parseInt(globalContext.globalState.get(DISCORD_COUNTER) ?? '0'); + const currentRuns = previousRuns + 1; + + globalContext.globalState.update(DISCORD_COUNTER, currentRuns); + + if ((currentRuns % DISCORD_COUNTER_PROMPT_AFTER) === 0) { + new NotificationBuilder() + .withMessage(`Need any help with mirrord? Come chat with our team on Discord!`) + .withGenericAction("Join us!", async () => { + vscode.commands.executeCommand(MirrordStatus.joinDiscordCommandId); + }) + .withDisableAction('promptReview') + .info(); + } +} \ No newline at end of file