Files
Messenger/web/src/api/users.ts
benya 4122882b7e
Some checks are pending
CI / test (push) Has started running
feat(privacy): support nobody option for group invites
2026-03-08 20:32:29 +03:00

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