Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix useUnreadNotifications exploding with falsey room, like in notif panel #10030

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useUnreadNotifications } from "../../../../hooks/useUnreadNotifications
import { StatelessNotificationBadge } from "./StatelessNotificationBadge";

interface Props {
room: Room;
room?: Room;
threadId?: string;
}

Expand Down
10 changes: 7 additions & 3 deletions src/hooks/useUnreadNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EffectiveMembership, getEffectiveMembership } from "../utils/membership
import { useEventEmitter } from "./useEventEmitter";

export const useUnreadNotifications = (
room: Room,
room?: Room,
threadId?: string,
): {
symbol: string | null;
Expand All @@ -35,7 +35,7 @@ export const useUnreadNotifications = (
} => {
const [symbol, setSymbol] = useState<string | null>(null);
const [count, setCount] = useState<number>(0);
const [color, setColor] = useState<NotificationColor>(0);
const [color, setColor] = useState<NotificationColor>(NotificationColor.None);

useEventEmitter(
room,
Expand All @@ -53,7 +53,11 @@ export const useUnreadNotifications = (
useEventEmitter(room, RoomEvent.MyMembership, () => updateNotificationState());

const updateNotificationState = useCallback(() => {
if (getUnsentMessages(room, threadId).length > 0) {
if (!room) {
setSymbol(null);
setCount(0);
setColor(NotificationColor.None);
} else if (getUnsentMessages(room, threadId).length > 0) {
setSymbol("!");
setCount(1);
setColor(NotificationColor.Unsent);
Expand Down