/* Copyright 2024 New Vector Ltd. Copyright 2023 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import { NotificationCountType, Room, Thread, ReceiptType } from "matrix-js-sdk/src/matrix"; import React, { useContext } from "react"; import { ReadReceipt } from "matrix-js-sdk/src/models/read-receipt"; import MatrixClientContext from "../../../../contexts/MatrixClientContext"; import { useNotificationState } from "../../../../hooks/useRoomNotificationState"; import { _t, _td } from "../../../../languageHandler"; import { determineUnreadState } from "../../../../RoomNotifs"; import { humanReadableNotificationLevel } from "../../../../stores/notifications/NotificationLevel"; import { doesRoomOrThreadHaveUnreadMessages } from "../../../../Unread"; import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool"; function UserReadUpTo({ target }: { target: ReadReceipt }): JSX.Element { const cli = useContext(MatrixClientContext); const userId = cli.getSafeUserId(); const hasPrivate = !!target.getReadReceiptForUserId(userId, false, ReceiptType.ReadPrivate); return ( <>
  • {_t("devtools|user_read_up_to")} {target.getReadReceiptForUserId(userId)?.eventId ?? _t("devtools|no_receipt_found")}
  • {_t("devtools|user_read_up_to_ignore_synthetic")} {target.getReadReceiptForUserId(userId, true)?.eventId ?? _t("devtools|no_receipt_found")}
  • {hasPrivate && ( <>
  • {_t("devtools|user_read_up_to_private")} {target.getReadReceiptForUserId(userId, false, ReceiptType.ReadPrivate)?.eventId ?? _t("devtools|no_receipt_found")}
  • {_t("devtools|user_read_up_to_private_ignore_synthetic")} {target.getReadReceiptForUserId(userId, true, ReceiptType.ReadPrivate)?.eventId ?? _t("devtools|no_receipt_found")}
  • )} ); } export default function RoomNotifications({ onBack }: IDevtoolsProps): JSX.Element { const { room } = useContext(DevtoolsContext); const cli = useContext(MatrixClientContext); const { level, count } = determineUnreadState(room, undefined, false); const [notificationState] = useNotificationState(room); return (

    {_t("devtools|room_status")}

    • {_t( "devtools|room_unread_status_count", { status: humanReadableNotificationLevel(level), count, }, { strong: (sub) => {sub}, }, )}
    • {_t( "devtools|notification_state", { notificationState, }, { strong: (sub) => {sub}, }, )}
    • {_t( cli.isRoomEncrypted(room.roomId!) ? _td("devtools|room_encrypted") : _td("devtools|room_not_encrypted"), {}, { strong: (sub) => {sub}, }, )}

    {_t("devtools|main_timeline")}

    • {_t("devtools|room_notifications_total")}{" "} {room.getRoomUnreadNotificationCount(NotificationCountType.Total)}
    • {_t("devtools|room_notifications_highlight")}{" "} {room.getRoomUnreadNotificationCount(NotificationCountType.Highlight)}
    • {_t("devtools|room_notifications_dot")} {doesRoomOrThreadHaveUnreadMessages(room) + ""}
    • {roomHasUnread(room) && ( <>
    • {_t("devtools|room_notifications_last_event")}
      • {_t("devtools|id")}{" "} {room.timeline[room.timeline.length - 1].getId()}
      • {_t("devtools|room_notifications_type")}{" "} {room.timeline[room.timeline.length - 1].getType()}
      • {_t("devtools|room_notifications_sender")}{" "} {room.timeline[room.timeline.length - 1].getSender()}
    • )}

    {_t("devtools|threads_timeline")}

      {room .getThreads() .filter((thread) => threadHasUnread(thread)) .map((thread) => (
    • {_t("devtools|room_notifications_thread_id")} {thread.id}
      • {_t("devtools|room_notifications_total")} {room.getThreadUnreadNotificationCount( thread.id, NotificationCountType.Total, )}
      • {_t("devtools|room_notifications_highlight")} {room.getThreadUnreadNotificationCount( thread.id, NotificationCountType.Highlight, )}
      • {_t("devtools|room_notifications_dot")}{" "} {doesRoomOrThreadHaveUnreadMessages(thread) + ""}
      • {_t("devtools|room_notifications_last_event")}
        • {_t("devtools|id")} {thread.lastReply()?.getId()}
        • {_t("devtools|room_notifications_type")}{" "} {thread.lastReply()?.getType()}
        • {_t("devtools|room_notifications_sender")}{" "} {thread.lastReply()?.getSender()}
    • ))}
    ); } function threadHasUnread(thread: Thread): boolean { const total = thread.room.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Total); const highlight = thread.room.getThreadUnreadNotificationCount(thread.id, NotificationCountType.Highlight); const dot = doesRoomOrThreadHaveUnreadMessages(thread); return total > 0 || highlight > 0 || dot; } function roomHasUnread(room: Room): boolean { const total = room.getRoomUnreadNotificationCount(NotificationCountType.Total); const highlight = room.getRoomUnreadNotificationCount(NotificationCountType.Highlight); const dot = doesRoomOrThreadHaveUnreadMessages(room); return total > 0 || highlight > 0 || dot; }