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

Commit

Permalink
Fix useUnreadNotifications exploding with falsey room, like in notif …
Browse files Browse the repository at this point in the history
…panel (#10030)
  • Loading branch information
t3chguy authored Jan 31, 2023
1 parent e2af97c commit 262c2fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/RoomNotifs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { MatrixClientPeg } from "./MatrixClientPeg";
import { NotificationColor } from "./stores/notifications/NotificationColor";
import { getUnsentMessages } from "./components/structures/RoomStatusBar";
import { doesRoomHaveUnreadMessages, doesRoomOrThreadHaveUnreadMessages } from "./Unread";
import { getEffectiveMembership, EffectiveMembership } from "./utils/membership";
import { EffectiveMembership, getEffectiveMembership } from "./utils/membership";

export enum RoomNotifState {
AllMessagesLoud = "all_messages_loud",
Expand Down Expand Up @@ -202,9 +202,13 @@ function isMuteRule(rule: IPushRule): boolean {
}

export function determineUnreadState(
room: Room,
room?: Room,
threadId?: string,
): { color: NotificationColor; symbol: string | null; count: number } {
if (!room) {
return { symbol: null, count: 0, color: NotificationColor.None };
}

if (getUnsentMessages(room, threadId).length > 0) {
return { symbol: "!", count: 1, color: NotificationColor.Unsent };
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
)}

{msgOption}
<UnreadNotificationBadge room={room} threadId={this.props.mxEvent.getId()} />
<UnreadNotificationBadge room={room || undefined} threadId={this.props.mxEvent.getId()} />
</>,
);
}
Expand Down
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
6 changes: 3 additions & 3 deletions src/hooks/useUnreadNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { useCallback, useEffect, useState } from "react";

import type { NotificationCount, Room } from "matrix-js-sdk/src/models/room";
import { determineUnreadState } from "../RoomNotifs";
import type { NotificationColor } from "../stores/notifications/NotificationColor";
import { NotificationColor } from "../stores/notifications/NotificationColor";
import { useEventEmitter } from "./useEventEmitter";

export const useUnreadNotifications = (
room: Room,
room?: Room,
threadId?: string,
): {
symbol: string | null;
Expand All @@ -32,7 +32,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 Down

0 comments on commit 262c2fc

Please sign in to comment.