From da1ae03491c994c8ca3bc8529374218a81b02b89 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Wed, 29 Apr 2026 16:20:27 -0700 Subject: [PATCH] feature: add notify.sync --- src/notify/index.ts | 15 ++++++++++++++- src/notify/types.test.ts | 17 +++++++++++++++++ src/notify/types.ts | 15 +++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/notify/types.test.ts diff --git a/src/notify/index.ts b/src/notify/index.ts index 2201bac..9612d85 100644 --- a/src/notify/index.ts +++ b/src/notify/index.ts @@ -1,7 +1,20 @@ import { Module } from "../module"; -import { Feature, WhosOnlineResponse } from "./types"; +import { Feature, NotifySyncResponse, WhosOnlineResponse } from "./types"; export class NotifyModule extends Module { + /** + * Fetches unread counts for a feature. + */ + public async sync(feature: Feature) { + return this.client._call( + NotifySyncResponse, + "notify.sync", + { + feature: feature as string, + } + ); + } + public async fetchOnlineUsers(feature: Feature) { return this.client._call( WhosOnlineResponse, diff --git a/src/notify/types.test.ts b/src/notify/types.test.ts new file mode 100644 index 0000000..54172a6 --- /dev/null +++ b/src/notify/types.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from "vitest"; +import { NotifySyncResponse } from "./types"; +import { TCResponseRaw } from "../types"; + +describe("notify types", () => { + it("should parse NotifySyncResponse", () => { + const response: TCResponseRaw = { + ok: true, + count: 6, + }; + + const constructed = new NotifySyncResponse(response); + + expect(constructed.ok).toBe(true); + expect(constructed.count).toBe(6); + }); +}); diff --git a/src/notify/types.ts b/src/notify/types.ts index 3f370e7..45fdbca 100644 --- a/src/notify/types.ts +++ b/src/notify/types.ts @@ -1,5 +1,17 @@ import { TCResponse, TCResponseRaw } from "../types"; +/** + * Response for notify.sync. + */ +export class NotifySyncResponse extends TCResponse { + public count: number; + + public constructor(res: TCResponseRaw) { + super(res); + this.count = res["count"] ?? 0; + } +} + export class WhosOnlineResponse extends TCResponse { public users: TruncatedUser[]; @@ -14,5 +26,8 @@ export interface TruncatedUser { } export enum Feature { + FEED = "feed", + ASK = "ask", FORUM = "forum", + CHAT = "chat", }