family update

This commit is contained in:
lendry
2026-06-24 23:17:24 +03:00
parent 9727cf3f35
commit f2366a69a0
18 changed files with 1374 additions and 103 deletions

View File

@@ -667,6 +667,9 @@ export interface ChatMessage {
mimeType?: string;
metadataJson?: string;
createdAt: string;
editedAt?: string;
isDeleted?: boolean;
readByAll?: boolean;
poll?: {
id: string;
question: string;
@@ -676,14 +679,37 @@ export interface ChatMessage {
};
}
export interface FamilyPresenceMember {
userId: string;
displayName: string;
online: boolean;
lastSeenAt?: string;
}
export interface FamilyPresence {
members: FamilyPresenceMember[];
onlineCount: number;
}
export interface ChatRoomMember {
id: string;
userId: string;
displayName: string;
hasAvatar: boolean;
notificationsMuted: boolean;
familyRole?: string;
isChatCreator?: boolean;
}
export interface ChatRoom {
id: string;
groupId: string;
type: string;
name: string;
hasAvatar: boolean;
createdById?: string;
updatedAt: string;
members: Array<{ id: string; userId: string; displayName: string; hasAvatar: boolean; notificationsMuted: boolean }>;
members: ChatRoomMember[];
lastMessage?: ChatMessage;
}
@@ -738,6 +764,21 @@ export async function createChatRoom(groupId: string, name: string, memberUserId
}, token);
}
export async function addChatRoomMember(roomId: string, memberUserId: string, token?: string | null) {
return apiFetch<ChatRoom>(`/chat/rooms/${roomId}/members`, {
method: 'POST',
body: JSON.stringify({ memberUserId })
}, token);
}
export async function removeChatRoomMember(roomId: string, memberUserId: string, token?: string | null) {
return apiFetch<ChatRoom>(`/chat/rooms/${roomId}/members/${memberUserId}`, { method: 'DELETE' }, token);
}
export async function removeFamilyMember(memberId: string, token?: string | null) {
return apiFetch<{ count: number }>(`/family/members/${memberId}`, { method: 'DELETE' }, token);
}
export async function fetchChatMessages(roomId: string, token?: string | null, beforeMessageId?: string) {
const query = beforeMessageId ? `?beforeMessageId=${beforeMessageId}` : '';
return apiFetch<{ messages?: ChatMessage[] }>(`/chat/rooms/${roomId}/messages${query}`, {}, token);
@@ -767,5 +808,24 @@ export async function setChatRoomMuted(roomId: string, muted: boolean, token?: s
return apiFetch(`/chat/rooms/${roomId}/mute`, { method: 'POST', body: JSON.stringify({ muted }) }, token);
}
export async function editChatMessage(messageId: string, content: string, token?: string | null) {
return apiFetch<ChatMessage>(`/chat/messages/${messageId}`, { method: 'PATCH', body: JSON.stringify({ content }) }, token);
}
export async function deleteChatMessage(messageId: string, token?: string | null) {
return apiFetch<ChatMessage>(`/chat/messages/${messageId}`, { method: 'DELETE' }, token);
}
export async function markChatRoomRead(roomId: string, lastMessageId: string | undefined, token?: string | null) {
return apiFetch<{ count: number }>(`/chat/rooms/${roomId}/read`, {
method: 'POST',
body: JSON.stringify({ lastMessageId })
}, token);
}
export async function fetchFamilyPresence(groupId: string, token?: string | null) {
return apiFetch<FamilyPresence>(`/family/groups/${groupId}/presence`, {}, token);
}
/** @deprecated Используйте getWsUrl() — URL может переключаться на same-origin /idp-api/ws в браузере */
export const WS_URL = configuredWsUrl;

View File

@@ -1,11 +1,15 @@
export async function fetchAuthenticatedMediaBlob(accessUrl: string, token: string) {
export async function fetchAuthenticatedMediaBlob(accessUrl: string, token: string, mimeType?: string) {
const response = await fetch(accessUrl, {
headers: { Authorization: `Bearer ${token}` }
});
if (!response.ok) {
throw new Error('Не удалось загрузить файл');
}
return response.blob();
const raw = await response.blob();
if (mimeType && (!raw.type || raw.type === 'application/octet-stream')) {
return new Blob([await raw.arrayBuffer()], { type: mimeType });
}
return raw;
}
export function createBlobObjectUrl(blob: Blob) {