feat(gui): Display developer responses to feedback (#302)

This commit is contained in:
Mohan 2025-04-28 13:12:43 +02:00 committed by GitHub
parent f1e5cdfbfe
commit 53a994e6dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 1216 additions and 45 deletions

View file

@ -146,4 +146,47 @@ export function usePendingApprovals(): PendingApprovalRequest[] {
export function usePendingLockBitcoinApproval(): PendingLockBitcoinApprovalRequest[] {
const approvals = usePendingApprovals();
return approvals.filter((c) => c.content.details.type === "LockBitcoin");
}
/**
* Calculates the number of unread messages from staff for a specific feedback conversation.
* @param feedbackId The ID of the feedback conversation.
* @returns The number of unread staff messages.
*/
export function useUnreadMessagesCount(feedbackId: string): number {
const { conversationsMap, seenMessagesSet } = useAppSelector((state) => ({
conversationsMap: state.conversations.conversations,
// Convert seenMessages array to a Set for efficient lookup
seenMessagesSet: new Set(state.conversations.seenMessages),
}));
const messages = conversationsMap[feedbackId] || [];
const unreadStaffMessages = messages.filter(
(msg) => msg.is_from_staff && !seenMessagesSet.has(msg.id.toString()),
);
return unreadStaffMessages.length;
}
/**
* Calculates the total number of unread messages from staff across all feedback conversations.
* @returns The total number of unread staff messages.
*/
export function useTotalUnreadMessagesCount(): number {
const { conversationsMap, seenMessagesSet } = useAppSelector((state) => ({
conversationsMap: state.conversations.conversations,
seenMessagesSet: new Set(state.conversations.seenMessages),
}));
let totalUnreadCount = 0;
for (const feedbackId in conversationsMap) {
const messages = conversationsMap[feedbackId] || [];
const unreadStaffMessages = messages.filter(
(msg) => msg.is_from_staff && !seenMessagesSet.has(msg.id.toString()),
);
totalUnreadCount += unreadStaffMessages.length;
}
return totalUnreadCount;
}