feat: add annotations, user profiles, watchers, stories, search and more
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
import { request } from "$lib/api/client";
|
||||
import type {
|
||||
Account,
|
||||
Alert,
|
||||
Annotation,
|
||||
AvatarHistoryView,
|
||||
CallbackView,
|
||||
CaptureToggles,
|
||||
Chat,
|
||||
ChatLinkView,
|
||||
DayCount,
|
||||
Folder,
|
||||
JobStatus,
|
||||
JobView,
|
||||
LinkView,
|
||||
MediaVersion,
|
||||
MediaView,
|
||||
MessageAt,
|
||||
MessageVersion,
|
||||
MessageView,
|
||||
PeerHistoryView,
|
||||
PeerView,
|
||||
PinnedView,
|
||||
PolicyChatKind,
|
||||
@@ -17,9 +26,12 @@ import type {
|
||||
PolicyRecord,
|
||||
PresenceHourly,
|
||||
PresenceSample,
|
||||
ReactionView,
|
||||
ResponseStats,
|
||||
SearchHit,
|
||||
StoryView,
|
||||
VolumeBucket,
|
||||
Watch,
|
||||
} from "$lib/api/types";
|
||||
import { accounts } from "$lib/stores/accounts.svelte";
|
||||
|
||||
@@ -79,7 +91,11 @@ export function effectivePolicy(query: {
|
||||
|
||||
export function listMessages(
|
||||
chatId: number,
|
||||
options: Page & { include_deleted?: boolean } = {}
|
||||
options: Page & {
|
||||
include_deleted?: boolean;
|
||||
before_id?: number;
|
||||
after_id?: number;
|
||||
} = {}
|
||||
): Promise<MessageView[]> {
|
||||
return request<MessageView[]>(`/chats/${chatId}/messages`, {
|
||||
account: true,
|
||||
@@ -159,6 +175,90 @@ export function getPeer(peerId: number): Promise<PeerView> {
|
||||
return request<PeerView>(`/peers/${peerId}`, { account: true });
|
||||
}
|
||||
|
||||
export function getPeerHistory(peerId: number): Promise<PeerHistoryView[]> {
|
||||
return request<PeerHistoryView[]>(`/peers/${peerId}/history`, {
|
||||
account: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getAvatarHistory(
|
||||
kind: "peer" | "chat",
|
||||
id: number
|
||||
): Promise<AvatarHistoryView[]> {
|
||||
return request<AvatarHistoryView[]>(`/avatars/${kind}/${id}/history`, {
|
||||
account: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getChatMedia(
|
||||
chatId: number,
|
||||
kinds: string[],
|
||||
page: { limit?: number; offset?: number } = {}
|
||||
): Promise<MediaView[]> {
|
||||
return request<MediaView[]>(`/chats/${chatId}/media`, {
|
||||
account: true,
|
||||
query: { kinds: kinds.join(","), ...page },
|
||||
});
|
||||
}
|
||||
|
||||
export function getChatLinks(
|
||||
chatId: number,
|
||||
page: { limit?: number; offset?: number } = {}
|
||||
): Promise<ChatLinkView[]> {
|
||||
return request<ChatLinkView[]>(`/chats/${chatId}/links`, {
|
||||
account: true,
|
||||
query: { ...page },
|
||||
});
|
||||
}
|
||||
|
||||
export function getMessageReactions(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<ReactionView[]> {
|
||||
return request<ReactionView[]>(`/messages/${chatId}/${messageId}/reactions`, {
|
||||
account: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getMessageCallbacks(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<CallbackView[]> {
|
||||
return request<CallbackView[]>(`/messages/${chatId}/${messageId}/callbacks`, {
|
||||
account: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getMessageLinks(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<LinkView[]> {
|
||||
return request<LinkView[]>(`/messages/${chatId}/${messageId}/links`, {
|
||||
account: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function getChatCalendar(chatId: number): Promise<DayCount[]> {
|
||||
return request<DayCount[]>(`/chats/${chatId}/calendar`, { account: true });
|
||||
}
|
||||
|
||||
export function getMessageAt(chatId: number, date: string): Promise<MessageAt> {
|
||||
return request<MessageAt>(`/chats/${chatId}/message-at`, {
|
||||
account: true,
|
||||
query: { date },
|
||||
});
|
||||
}
|
||||
|
||||
export function getStories(
|
||||
peerId: number,
|
||||
page: Page = {}
|
||||
): Promise<StoryView[]> {
|
||||
return request<StoryView[]>("/stories", {
|
||||
account: true,
|
||||
query: { peer_id: peerId, ...page },
|
||||
});
|
||||
}
|
||||
|
||||
export function getPeers(ids: number[]): Promise<PeerView[]> {
|
||||
if (ids.length === 0) {
|
||||
return Promise.resolve([]);
|
||||
@@ -249,3 +349,82 @@ export function fetchMedia(
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function listWatches(): Promise<Watch[]> {
|
||||
return request<Watch[]>("/watches", { account: true });
|
||||
}
|
||||
|
||||
export function createWatch(
|
||||
kind: string,
|
||||
params: Record<string, unknown>,
|
||||
enabled: boolean
|
||||
): Promise<Watch> {
|
||||
return request<Watch>("/watches", {
|
||||
method: "POST",
|
||||
body: { account_id: accounts.selectedId, kind, params, enabled },
|
||||
});
|
||||
}
|
||||
|
||||
export function updateWatch(
|
||||
id: number,
|
||||
params: Record<string, unknown>,
|
||||
enabled: boolean
|
||||
): Promise<Watch> {
|
||||
return request<Watch>(`/watches/${id}`, {
|
||||
method: "PUT",
|
||||
body: { params, enabled },
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteWatch(id: number): Promise<void> {
|
||||
return request<void>(`/watches/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function listAlerts(
|
||||
options: Page & { seen?: boolean } = {}
|
||||
): Promise<Alert[]> {
|
||||
return request<Alert[]>("/alerts", { account: true, query: { ...options } });
|
||||
}
|
||||
|
||||
export function markAlertSeen(id: number): Promise<void> {
|
||||
return request<void>(`/alerts/${id}/seen`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function listAnnotations(
|
||||
options: { chatId?: number; messageId?: number } = {}
|
||||
): Promise<Annotation[]> {
|
||||
return request<Annotation[]>("/annotations", {
|
||||
account: true,
|
||||
query: { chat_id: options.chatId, message_id: options.messageId },
|
||||
});
|
||||
}
|
||||
|
||||
export function createAnnotation(
|
||||
chatId: number,
|
||||
messageId: number,
|
||||
text: string
|
||||
): Promise<Annotation> {
|
||||
return request<Annotation>("/annotations", {
|
||||
method: "POST",
|
||||
body: {
|
||||
account_id: accounts.selectedId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
text,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function updateAnnotation(
|
||||
id: number,
|
||||
text: string
|
||||
): Promise<Annotation> {
|
||||
return request<Annotation>(`/annotations/${id}`, {
|
||||
method: "PUT",
|
||||
body: { text },
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteAnnotation(id: number): Promise<void> {
|
||||
return request<void>(`/annotations/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user