global fix and update bot Api

This commit is contained in:
lendry
2026-06-26 13:01:52 +03:00
parent d3ea470d02
commit aa228d84eb
29 changed files with 980 additions and 221 deletions

View File

@@ -1,7 +1,7 @@
'use client';
import { useCallback, useEffect, useRef, useState } from 'react';
import { LayoutGrid, Loader2, Send, X } from 'lucide-react';
import { LayoutGrid, Loader2, Pin, Send, X } from 'lucide-react';
import { BotMessageKeyboard } from '@/components/chat/bot-message-keyboard';
import { BotChatMessageContextMenu } from '@/components/chat/bot-chat-message-context-menu';
import { useRealtime } from '@/components/notifications/realtime-provider';
@@ -135,7 +135,9 @@ export function FamilyBotChat({
messageType: typeof payload.messageType === 'string' ? payload.messageType : 'text',
messageId,
createdAt: new Date().toISOString(),
replyMarkupJson
replyMarkupJson,
isPinned: Boolean(payload.isPinned),
pinnedAt: typeof payload.pinnedAt === 'string' ? payload.pinnedAt : null
};
setMessages((current) => {
@@ -183,6 +185,27 @@ export function FamilyBotChat({
: item
)
);
return;
}
if (event.type === 'bot_message_pinned') {
const messageId = Number(payload.messageId);
if (!Number.isFinite(messageId)) {
void loadMessages();
return;
}
setMessages((current) =>
current.map((item) =>
item.messageId === messageId && item.direction === 'out'
? {
...item,
isPinned: Boolean(payload.isPinned),
pinnedAt: typeof payload.pinnedAt === 'string' ? payload.pinnedAt : null
}
: item
)
);
}
});
}, [botRef, loadMessages, subscribe]);
@@ -227,6 +250,12 @@ export function FamilyBotChat({
<div key={message.id} className={cn('flex', mine ? 'justify-end' : 'justify-start')}>
<BotChatMessageContextMenu text={message.text} onCopy={() => showToast('Текст скопирован')}>
<div className={cn('max-w-[78%] rounded-[18px] px-3 py-2 shadow-sm', mine ? 'rounded-br-md bg-[#effdde]' : 'rounded-bl-md bg-white')}>
{message.isPinned ? (
<div className={cn('mb-1 flex items-center gap-1 text-[11px] font-medium', mine ? 'text-[#6c8f56]' : 'text-[#3390ec]')}>
<Pin className="h-3 w-3" />
Закреплено
</div>
) : null}
{!mine ? <p className="mb-0.5 text-[11px] font-semibold text-[#3390ec]">{botName}</p> : null}
<p className="whitespace-pre-wrap text-sm">{message.text || '…'}</p>
{!mine && hasKeyboard && message.messageId > 0 ? (