feature: add notify.sync

master
John Montagu, the 4th Earl of Sandvich 2026-04-29 16:20:27 -07:00
parent 48222309cd
commit da1ae03491
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 46 additions and 1 deletions

View File

@ -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,

View File

@ -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);
});
});

View File

@ -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",
}