2026-08-16 14:45:02 +07:00
|
|
|
import { orpc } from "@/lib/orpc/client";
|
2026-08-18 15:11:01 +07:00
|
|
|
import type {
|
|
|
|
|
AttachmentRecord,
|
2026-09-23 19:45:14 +07:00
|
|
|
Channel,
|
2026-08-18 20:45:12 +07:00
|
|
|
EditHistoryRow,
|
2026-09-23 19:45:14 +07:00
|
|
|
Guild,
|
2026-08-18 17:43:02 +07:00
|
|
|
MessageActivityBucket,
|
2026-08-18 15:11:01 +07:00
|
|
|
MessageRecord,
|
|
|
|
|
} from "@/lib/types";
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
export const messagesApi = {
|
2026-09-23 19:45:14 +07:00
|
|
|
getGuilds: () => orpc.messages.guilds() as unknown as Promise<Guild[]>,
|
|
|
|
|
|
|
|
|
|
getTextChannels: (guildId: string) =>
|
|
|
|
|
orpc.messages.textChannels({ guildId }) as unknown as Promise<Channel[]>,
|
|
|
|
|
|
2026-07-26 11:27:21 +07:00
|
|
|
list: (
|
|
|
|
|
guildId: string,
|
|
|
|
|
limit?: number,
|
|
|
|
|
channelId?: string,
|
|
|
|
|
cursor?: string,
|
2026-08-16 13:25:10 +07:00
|
|
|
) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.list({
|
2026-08-16 13:25:10 +07:00
|
|
|
guildId,
|
|
|
|
|
limit,
|
|
|
|
|
channelId,
|
|
|
|
|
cursor,
|
|
|
|
|
}) as unknown as Promise<{
|
|
|
|
|
data: MessageRecord[];
|
|
|
|
|
nextCursor: string | null;
|
|
|
|
|
}>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-16 13:25:10 +07:00
|
|
|
getByChannel: (channelId: string, limit?: number, cursor?: string) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.byChannel({
|
2026-08-16 13:25:10 +07:00
|
|
|
channelId,
|
|
|
|
|
query: { channelId, limit, cursor },
|
|
|
|
|
}) as unknown as Promise<{
|
|
|
|
|
data: MessageRecord[];
|
|
|
|
|
nextCursor: string | null;
|
|
|
|
|
}>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
|
|
|
|
getDetail: (id: string) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.detail({ id }) as unknown as Promise<MessageRecord>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-16 13:25:10 +07:00
|
|
|
getImages: (guildId: string, limit?: number) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.images({ guildId, limit }) as unknown as Promise<{
|
2026-08-16 13:25:10 +07:00
|
|
|
data: MessageRecord[];
|
|
|
|
|
nextCursor: string | null;
|
|
|
|
|
}>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-01 10:59:54 +07:00
|
|
|
getAttachments: (
|
|
|
|
|
channelId: string,
|
|
|
|
|
limit?: number,
|
|
|
|
|
cursor?: string,
|
|
|
|
|
messageId?: string,
|
2026-08-16 13:25:10 +07:00
|
|
|
) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.attachmentsByChannel({
|
2026-08-16 13:25:10 +07:00
|
|
|
channelId,
|
|
|
|
|
query: { channelId, limit, cursor, messageId },
|
|
|
|
|
}) as unknown as Promise<{
|
|
|
|
|
data: AttachmentRecord[];
|
|
|
|
|
nextCursor: string | null;
|
|
|
|
|
}>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-16 13:25:10 +07:00
|
|
|
getReview: (limit?: number, channelId?: string) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.messages.review({ limit, channelId }) as unknown as Promise<{
|
2026-08-16 13:25:10 +07:00
|
|
|
results: MessageRecord[];
|
|
|
|
|
limit: number;
|
|
|
|
|
cursor: null;
|
|
|
|
|
}>,
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-16 14:45:02 +07:00
|
|
|
// Analysis search (formerly /api/analysis/search → oRPC analysis.search)
|
2026-08-16 13:25:10 +07:00
|
|
|
search: (q: string, limit?: number) =>
|
2026-08-16 14:45:02 +07:00
|
|
|
orpc.analysis.search({ q, limit }) as unknown as Promise<{
|
2026-08-16 13:25:10 +07:00
|
|
|
results: MessageRecord[];
|
|
|
|
|
}>,
|
2026-08-18 15:11:01 +07:00
|
|
|
|
2026-08-18 17:43:02 +07:00
|
|
|
// Public, read-only activity heatmap data (per-hour volume by channel).
|
|
|
|
|
getActivity: (days = 30) =>
|
|
|
|
|
orpc.messages.activity({ days }) as unknown as Promise<
|
|
|
|
|
MessageActivityBucket[]
|
|
|
|
|
>,
|
2026-08-18 20:45:12 +07:00
|
|
|
|
|
|
|
|
// Public, read-only recent message edits (evasion tracker).
|
|
|
|
|
getRecentEdits: (limit = 50, channelId?: string) =>
|
|
|
|
|
orpc.messages.editHistory({ limit, channelId }) as unknown as Promise<
|
|
|
|
|
EditHistoryRow[]
|
|
|
|
|
>,
|
2026-07-26 11:27:21 +07:00
|
|
|
};
|