fix chat list image taken from the clicked card instead of the chat
createOrGetChat stored the clicked card's post for the returned chat id, even when the backend returned an existing chat about another ad. The chat then showed the new ad's image until the next list fetch replaced it with the real one. The backend's chat.post is now the source of truth; card data only adds the emoji for the same ad. Also limit the chat input to 4000 characters, matching the backend. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
// Тот же лимит, что ChatService.MAX_MESSAGE_LENGTH на бэкенде
|
||||||
|
const MAX_MESSAGE_LENGTH = 4000;
|
||||||
|
|
||||||
export default function ChatInputBar({
|
export default function ChatInputBar({
|
||||||
input,
|
input,
|
||||||
onInputChange,
|
onInputChange,
|
||||||
@@ -13,6 +16,7 @@ export default function ChatInputBar({
|
|||||||
onChange={(e) => onInputChange(e.target.value)}
|
onChange={(e) => onInputChange(e.target.value)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
className="chat-input"
|
className="chat-input"
|
||||||
|
maxLength={MAX_MESSAGE_LENGTH}
|
||||||
/>
|
/>
|
||||||
<button type="submit" className="chat-send-btn" disabled={!connected}>
|
<button type="submit" className="chat-send-btn" disabled={!connected}>
|
||||||
➤
|
➤
|
||||||
|
|||||||
@@ -49,8 +49,17 @@ export function useChats() {
|
|||||||
const res = await apiFetch(url, { method: "POST" });
|
const res = await apiFetch(url, { method: "POST" });
|
||||||
if (!res.ok) throw new Error(t('chats.createError'));
|
if (!res.ok) throw new Error(t('chats.createError'));
|
||||||
const chat = await res.json();
|
const chat = await res.json();
|
||||||
if (postInfo && chat.id) {
|
// Объявление чата берём из ответа бэкенда: если он вернул существующий чат по
|
||||||
setPostForChat(chat.id, postInfo);
|
// другому объявлению, postInfo с карточки привязал бы к нему чужую картинку.
|
||||||
|
// postInfo — только дополнение (emoji) для того же объявления.
|
||||||
|
if (chat.id) {
|
||||||
|
const sameAd = postInfo && (chat.post?.id ?? chat.postId) != null
|
||||||
|
&& String(chat.post?.id ?? chat.postId) === String(postInfo.id);
|
||||||
|
if (chat.post) {
|
||||||
|
setPostForChat(chat.id, { ...(sameAd ? postInfo : {}), ...chat.post });
|
||||||
|
} else if (sameAd) {
|
||||||
|
setPostForChat(chat.id, postInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return chat;
|
return chat;
|
||||||
}, [t]);
|
}, [t]);
|
||||||
|
|||||||
Reference in New Issue
Block a user