feature: add notify.sync
parent
48222309cd
commit
da1ae03491
|
|
@ -1,7 +1,20 @@
|
||||||
import { Module } from "../module";
|
import { Module } from "../module";
|
||||||
import { Feature, WhosOnlineResponse } from "./types";
|
import { Feature, NotifySyncResponse, WhosOnlineResponse } from "./types";
|
||||||
|
|
||||||
export class NotifyModule extends Module {
|
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) {
|
public async fetchOnlineUsers(feature: Feature) {
|
||||||
return this.client._call(
|
return this.client._call(
|
||||||
WhosOnlineResponse,
|
WhosOnlineResponse,
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,5 +1,17 @@
|
||||||
import { TCResponse, TCResponseRaw } from "../types";
|
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 {
|
export class WhosOnlineResponse extends TCResponse {
|
||||||
public users: TruncatedUser[];
|
public users: TruncatedUser[];
|
||||||
|
|
||||||
|
|
@ -14,5 +26,8 @@ export interface TruncatedUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Feature {
|
export enum Feature {
|
||||||
|
FEED = "feed",
|
||||||
|
ASK = "ask",
|
||||||
FORUM = "forum",
|
FORUM = "forum",
|
||||||
|
CHAT = "chat",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue