Send and view photos in chats
- paperclip button and clipboard paste in the chat input, previews with remove, up to 10 photos per message (sent via REST multipart) - photos in message bubbles with reserved size, fullscreen viewer (arrows, swipe, Esc), fresh link when a presigned URL expires - chat list preview shows "Photo" for photo-only messages - keep the feed pinned to the bottom when the preview strip appears Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,7 +98,39 @@ export function useChats() {
|
||||
}
|
||||
}, [clearChatUnread]);
|
||||
|
||||
return { chats, loading, error, fetchChats, findChat, startChat, fetchMessages, markAsRead };
|
||||
/**
|
||||
* Сообщение с фото (и необязательным текстом) — через REST: файлы по
|
||||
* WebSocket не передать. Возвращает сохранённое сообщение; собеседнику
|
||||
* (и нам же) оно придёт и по сокету — дубль отсекается по id.
|
||||
*/
|
||||
const sendPhotoMessage = useCallback(async (chatId, content, files) => {
|
||||
const data = new FormData();
|
||||
if (content) data.append("content", content);
|
||||
files.forEach((file) => data.append("files", file, file.name || "photo.jpg"));
|
||||
const res = await apiFetch(`${API_URL}/api/v1/chats/${chatId}/messages`, {
|
||||
method: "POST",
|
||||
body: data,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await readApiError(res);
|
||||
console.warn("sendPhotoMessage failed:", err.status, err.serverMessage);
|
||||
throw err;
|
||||
}
|
||||
return res.json();
|
||||
}, []);
|
||||
|
||||
/** Свежая ссылка на фото, если выданная вместе с сообщением истекла. */
|
||||
const refreshAttachmentUrl = useCallback(async (chatId, attachmentId) => {
|
||||
const res = await apiFetch(`${API_URL}/api/v1/chats/${chatId}/attachments/${attachmentId}/url`);
|
||||
if (!res.ok) throw new Error(`Error ${res.status}`);
|
||||
const { url } = await res.json();
|
||||
return url;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
chats, loading, error, fetchChats, findChat, startChat, fetchMessages, markAsRead,
|
||||
sendPhotoMessage, refreshAttachmentUrl,
|
||||
};
|
||||
}
|
||||
|
||||
function chatWithUrl(otherUserId, postId, suffix = "") {
|
||||
|
||||
Reference in New Issue
Block a user