feat: implement bulk mute/unmute functionality for all conversations in MessagingPage

This commit is contained in:
pradeepkumar
2026-04-15 19:37:53 +05:30
parent fc0e34293e
commit d764fe02c9

View File

@@ -153,7 +153,6 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const [isPageMenuOpen, setIsPageMenuOpen] = useState(false); const [isPageMenuOpen, setIsPageMenuOpen] = useState(false);
const [isAllMuted, setIsAllMuted] = useState(false);
const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null); const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
const [isUploading, setIsUploading] = useState(false); const [isUploading, setIsUploading] = useState(false);
const [showScrollButton, setShowScrollButton] = useState(false); const [showScrollButton, setShowScrollButton] = useState(false);
@@ -488,6 +487,13 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
setConfirmDeleteId(null); setConfirmDeleteId(null);
}, [confirmDeleteId, deleteConversation]); }, [confirmDeleteId, deleteConversation]);
// True only when every conversation is currently muted for this user's role.
const isAllMuted =
conversations.length > 0 &&
conversations.every((c) =>
userRole === 'AGENT' ? c.agentMuted : c.userMuted,
);
// Page header menu items // Page header menu items
const pageMenuItems: DropdownMenuItem[] = [ const pageMenuItems: DropdownMenuItem[] = [
{ {
@@ -498,7 +504,21 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
}, },
{ {
label: isAllMuted ? 'Unmute All Notifications' : 'Mute All Notifications', label: isAllMuted ? 'Unmute All Notifications' : 'Mute All Notifications',
onClick: () => setIsAllMuted((prev) => !prev), onClick: async () => {
const targetMuted = !isAllMuted;
// Flip every conversation whose current mute state doesn't match the target
const tasks = conversations
.filter((c) => {
const current = userRole === 'AGENT' ? c.agentMuted : c.userMuted;
return !!current !== targetMuted;
})
.map((c) => toggleMute(c.id, targetMuted));
try {
await Promise.all(tasks);
} catch (err) {
console.error('Failed to toggle mute on all conversations:', err);
}
},
}, },
]; ];