Skip to content

Commit be3f0a4

Browse files
chore: upgrade dependencies
1 parent 5f4d8e8 commit be3f0a4

File tree

3 files changed

+2054
-1852
lines changed

3 files changed

+2054
-1852
lines changed

src/inbox.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
import { Api } from "coder/site/src/api/api"
2+
import { Workspace, GetInboxNotificationResponse } from "coder/site/src/api/typesGenerated"
23
import { ProxyAgent } from "proxy-agent"
34
import * as vscode from "vscode"
45
import { WebSocket } from "ws"
56
import { errToStr } from "./api-helper"
67
import { type Storage } from "./storage"
78

8-
type InboxMessage = {
9-
unread_count: number
10-
notification: {
11-
id: string
12-
user_id: string
13-
template_id: string
14-
targets: string[]
15-
title: string
16-
content: string
17-
actions: Record<string, string>
18-
read_at: string
19-
created_at: string
20-
}
21-
}
22-
239
// These are the template IDs of our notifications.
2410
// Maybe in the future we should avoid hardcoding
2511
// these in both coderd and here.
@@ -31,17 +17,23 @@ export class Inbox implements vscode.Disposable {
3117
private disposed = false
3218
private socket: WebSocket
3319

34-
constructor(httpAgent: ProxyAgent, restClient: Api, storage: Storage) {
20+
constructor(workspace: Workspace, httpAgent: ProxyAgent, restClient: Api, storage: Storage) {
3521
this.storage = storage
3622

3723
const baseUrlRaw = restClient.getAxiosInstance().defaults.baseURL
3824
if (!baseUrlRaw) {
3925
throw new Error("No base URL set on REST client")
4026
}
4127

28+
const watchTemplates = [TEMPLATE_WORKSPACE_OUT_OF_DISK, TEMPLATE_WORKSPACE_OUT_OF_MEMORY]
29+
const watchTemplatesParam = encodeURIComponent(watchTemplates.join(","))
30+
31+
const watchTargets = [workspace.id]
32+
const watchTargetsParam = encodeURIComponent(watchTargets.join(","))
33+
4234
const baseUrl = new URL(baseUrlRaw)
4335
const socketProto = baseUrl.protocol === "https:" ? "wss:" : "ws:"
44-
const socketUrlRaw = `${socketProto}//${baseUrl.host}/api/v2/notifications/inbox/watch`
36+
const socketUrlRaw = `${socketProto}//${baseUrl.host}/api/v2/notifications/inbox/watch?templates=${watchTemplatesParam}&targets=${watchTargetsParam}`
4537

4638
const coderSessionTokenHeader = "Coder-Session-Token"
4739
this.socket = new WebSocket(new URL(socketUrlRaw), {
@@ -64,14 +56,9 @@ export class Inbox implements vscode.Disposable {
6456

6557
this.socket.on("message", (data) => {
6658
try {
67-
const inboxMessage = JSON.parse(data.toString()) as InboxMessage
59+
const inboxMessage = JSON.parse(data.toString()) as GetInboxNotificationResponse
6860

69-
if (
70-
inboxMessage.notification.template_id === TEMPLATE_WORKSPACE_OUT_OF_DISK ||
71-
inboxMessage.notification.template_id === TEMPLATE_WORKSPACE_OUT_OF_MEMORY
72-
) {
73-
vscode.window.showInformationMessage(inboxMessage.notification.title)
74-
}
61+
vscode.window.showInformationMessage(inboxMessage.notification.title)
7562
} catch (error) {
7663
this.notifyError(error)
7764
}

src/remote.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export class Remote {
406406

407407
// Watch coder inbox for messages
408408
const httpAgent = await createHttpAgent()
409-
const inbox = new Inbox(httpAgent, workspaceRestClient, this.storage)
409+
const inbox = new Inbox(workspace, httpAgent, workspaceRestClient, this.storage)
410410
disposables.push(inbox)
411411

412412
// Wait for the agent to connect.

0 commit comments

Comments
 (0)