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

This commit is contained in:
Michael Telatynski 2023-01-31 12:38:25 +00:00 committed by GitHub
parent e2af97c4de
commit 262c2fcff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

View file

@ -26,7 +26,7 @@ import { MatrixClientPeg } from "./MatrixClientPeg";
import { NotificationColor } from "./stores/notifications/NotificationColor"; import { NotificationColor } from "./stores/notifications/NotificationColor";
import { getUnsentMessages } from "./components/structures/RoomStatusBar"; import { getUnsentMessages } from "./components/structures/RoomStatusBar";
import { doesRoomHaveUnreadMessages, doesRoomOrThreadHaveUnreadMessages } from "./Unread"; import { doesRoomHaveUnreadMessages, doesRoomOrThreadHaveUnreadMessages } from "./Unread";
import { getEffectiveMembership, EffectiveMembership } from "./utils/membership"; import { EffectiveMembership, getEffectiveMembership } from "./utils/membership";
export enum RoomNotifState { export enum RoomNotifState {
AllMessagesLoud = "all_messages_loud", AllMessagesLoud = "all_messages_loud",
@ -202,9 +202,13 @@ function isMuteRule(rule: IPushRule): boolean {
} }
export function determineUnreadState( export function determineUnreadState(
room: Room, room?: Room,
threadId?: string, threadId?: string,
): { color: NotificationColor; symbol: string | null; count: number } { ): { color: NotificationColor; symbol: string | null; count: number } {
if (!room) {
return { symbol: null, count: 0, color: NotificationColor.None };
}
if (getUnsentMessages(room, threadId).length > 0) { if (getUnsentMessages(room, threadId).length > 0) {
return { symbol: "!", count: 1, color: NotificationColor.Unsent }; return { symbol: "!", count: 1, color: NotificationColor.Unsent };
} }

View file

@ -1348,7 +1348,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
)} )}
{msgOption} {msgOption}
<UnreadNotificationBadge room={room} threadId={this.props.mxEvent.getId()} /> <UnreadNotificationBadge room={room || undefined} threadId={this.props.mxEvent.getId()} />
</>, </>,
); );
} }

View file

@ -21,7 +21,7 @@ import { useUnreadNotifications } from "../../../../hooks/useUnreadNotifications
import { StatelessNotificationBadge } from "./StatelessNotificationBadge"; import { StatelessNotificationBadge } from "./StatelessNotificationBadge";
interface Props { interface Props {
room: Room; room?: Room;
threadId?: string; threadId?: string;
} }

View file

@ -19,11 +19,11 @@ import { useCallback, useEffect, useState } from "react";
import type { NotificationCount, Room } from "matrix-js-sdk/src/models/room"; import type { NotificationCount, Room } from "matrix-js-sdk/src/models/room";
import { determineUnreadState } from "../RoomNotifs"; import { determineUnreadState } from "../RoomNotifs";
import type { NotificationColor } from "../stores/notifications/NotificationColor"; import { NotificationColor } from "../stores/notifications/NotificationColor";
import { useEventEmitter } from "./useEventEmitter"; import { useEventEmitter } from "./useEventEmitter";
export const useUnreadNotifications = ( export const useUnreadNotifications = (
room: Room, room?: Room,
threadId?: string, threadId?: string,
): { ): {
symbol: string | null; symbol: string | null;
@ -32,7 +32,7 @@ export const useUnreadNotifications = (
} => { } => {
const [symbol, setSymbol] = useState<string | null>(null); const [symbol, setSymbol] = useState<string | null>(null);
const [count, setCount] = useState<number>(0); const [count, setCount] = useState<number>(0);
const [color, setColor] = useState<NotificationColor>(0); const [color, setColor] = useState<NotificationColor>(NotificationColor.None);
useEventEmitter( useEventEmitter(
room, room,