fix(notifications): sync mute state in chat store immediately
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-03-08 20:40:44 +03:00
parent 418c9e6044
commit 20f31cd15e
3 changed files with 8 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ interface Props {
export function ChatInfoPanel({ chatId, open, onClose }: Props) {
const me = useAuthStore((s) => s.me);
const loadChats = useChatStore((s) => s.loadChats);
const updateChatMuted = useChatStore((s) => s.updateChatMuted);
const setActiveChatId = useChatStore((s) => s.setActiveChatId);
const setFocusedMessage = useChatStore((s) => s.setFocusedMessage);
const showToast = useUiStore((s) => s.showToast);
@@ -306,6 +307,7 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
try {
const updated = await updateChatNotificationSettings(chatId, !muted);
setMuted(updated.muted);
updateChatMuted(chatId, updated.muted);
} catch {
setError("Failed to update notifications");
} finally {

View File

@@ -99,6 +99,7 @@ interface ChatState {
setReplyToMessage: (chatId: number, message: Message | null) => void;
setEditingMessage: (chatId: number, message: Message | null) => void;
updateChatPinnedMessage: (chatId: number, pinnedMessageId: number | null) => void;
updateChatMuted: (chatId: number, muted: boolean) => void;
applyPresenceEvent: (chatId: number, userId: number, isOnline: boolean, lastSeenAt?: string) => void;
removeChat: (chatId: number) => void;
setDraft: (chatId: number, text: string) => void;
@@ -416,6 +417,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
set((state) => ({
chats: state.chats.map((chat) => (chat.id === chatId ? { ...chat, pinned_message_id: pinnedMessageId } : chat))
})),
updateChatMuted: (chatId, muted) =>
set((state) => ({
chats: state.chats.map((chat) => (chat.id === chatId ? { ...chat, muted } : chat))
})),
applyPresenceEvent: (chatId, userId, isOnline, lastSeenAt) =>
set((state) => ({
chats: state.chats.map((chat) => {