Опросы

This commit is contained in:
Халимов Рустам
2026-04-07 11:11:35 +03:00
parent c45f4db61c
commit 852efa090e
25 changed files with 530 additions and 175 deletions
@@ -43,6 +43,7 @@ interface ChatState {
clearMessages: (chatId: string) => void;
setPinnedMessage: (chatId: string, message: Message) => void;
removePinnedMessage: (chatId: string, messageId: string, newPinned?: Message[] | null) => void;
jumpToMessage: (chatId: string, sequenceId: number) => Promise<void>;
clearStore: () => void;
}
@@ -188,13 +189,13 @@ export const useChatStore = create<ChatState>((set, get) => ({
updateMessage: (message) => {
set((state) => {
const chatMessages = state.messages[message.chatId] || [];
const updatedMessages = chatMessages.map((m) => (m.id === message.id ? message : m));
const updatedMessages = chatMessages.map((m) => (m.id === message.id ? { ...m, ...message } : m));
const updatedChats = state.chats.map((chat) => {
if (chat.id === message.chatId) {
return {
...chat,
messages: chat.messages?.map((m) => (m.id === message.id ? message : m)),
messages: chat.messages?.map((m) => (m.id === message.id ? { ...m, ...message } : m)),
};
}
return chat;
@@ -545,6 +546,25 @@ export const useChatStore = create<ChatState>((set, get) => ({
});
},
jumpToMessage: async (chatId, sequenceId) => {
try {
set({ isLoadingMessages: true });
const fetched = await ChatApi.getMessages(chatId, undefined, sequenceId, 50);
set((state) => ({
messages: { ...state.messages, [chatId]: fetched },
// Since we jumped, we assume there is more history to load above
hasMoreMessages: { ...state.hasMoreMessages, [chatId]: true },
isLoadingMessages: false,
}));
} catch (error: any) {
console.error('Jump to message error:', error);
set({ isLoadingMessages: false });
const { addNotification } = (await import('../../../core/application/stores/notificationStore')).useNotificationStore.getState();
addNotification('error', error.message || 'Failed to jump to message');
}
},
clearStore: () => {
set({
chats: [],