Опросы
This commit is contained in:
@@ -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: [],
|
||||
|
||||
Reference in New Issue
Block a user