62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { http } from "./http";
|
|
import type { AuthUser, UserSearchItem } from "../chat/types";
|
|
|
|
export async function searchUsers(query: string, limit = 20): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/search", {
|
|
params: { query, limit }
|
|
});
|
|
return data;
|
|
}
|
|
|
|
interface UserProfileUpdatePayload {
|
|
name?: string;
|
|
username?: string;
|
|
bio?: string | null;
|
|
avatar_url?: string | null;
|
|
allow_private_messages?: boolean;
|
|
privacy_private_messages?: "everyone" | "contacts" | "nobody";
|
|
privacy_last_seen?: "everyone" | "contacts" | "nobody";
|
|
privacy_avatar?: "everyone" | "contacts" | "nobody";
|
|
privacy_group_invites?: "everyone" | "contacts" | "nobody";
|
|
}
|
|
|
|
export async function updateMyProfile(payload: UserProfileUpdatePayload): Promise<AuthUser> {
|
|
const { data } = await http.put<AuthUser>("/users/profile", payload);
|
|
return data;
|
|
}
|
|
|
|
export async function getUserById(userId: number): Promise<AuthUser> {
|
|
const { data } = await http.get<AuthUser>(`/users/${userId}`);
|
|
return data;
|
|
}
|
|
|
|
export async function listBlockedUsers(): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/blocked");
|
|
return data;
|
|
}
|
|
|
|
export async function blockUser(userId: number): Promise<void> {
|
|
await http.post(`/users/${userId}/block`);
|
|
}
|
|
|
|
export async function unblockUser(userId: number): Promise<void> {
|
|
await http.delete(`/users/${userId}/block`);
|
|
}
|
|
|
|
export async function listContacts(): Promise<UserSearchItem[]> {
|
|
const { data } = await http.get<UserSearchItem[]>("/users/contacts");
|
|
return data;
|
|
}
|
|
|
|
export async function addContact(userId: number): Promise<void> {
|
|
await http.post(`/users/${userId}/contacts`);
|
|
}
|
|
|
|
export async function addContactByEmail(email: string): Promise<void> {
|
|
await http.post("/users/contacts/by-email", { email });
|
|
}
|
|
|
|
export async function removeContact(userId: number): Promise<void> {
|
|
await http.delete(`/users/${userId}/contacts`);
|
|
}
|