/* Copyright 2024 New Vector Ltd. Copyright 2021 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 { Room } from "matrix-js-sdk/src/matrix"; import React from "react"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { useNotificationState } from "../../../hooks/useRoomNotificationState"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { _t } from "../../../languageHandler"; import { RoomNotifState } from "../../../RoomNotifs"; import { IProps as IContextMenuProps } from "../../structures/ContextMenu"; import IconizedContextMenu, { IconizedContextMenuOptionList, IconizedContextMenuRadio, } from "../context_menus/IconizedContextMenu"; import { ButtonEvent } from "../elements/AccessibleButton"; interface IProps extends IContextMenuProps { room: Room; } export const RoomNotificationContextMenu: React.FC = ({ room, onFinished, ...props }) => { const [notificationState, setNotificationState] = useNotificationState(room); const wrapHandler = (handler: (ev: ButtonEvent) => void, persistent = false): ((ev: ButtonEvent) => void) => { return (ev: ButtonEvent) => { ev.preventDefault(); ev.stopPropagation(); handler(ev); const action = getKeyBindingsManager().getAccessibilityAction(ev as React.KeyboardEvent); if (!persistent || action === KeyBindingAction.Enter) { onFinished(); } }; }; const defaultOption: JSX.Element = ( setNotificationState(RoomNotifState.AllMessages))} /> ); const allMessagesOption: JSX.Element = ( setNotificationState(RoomNotifState.AllMessagesLoud))} /> ); const mentionsOption: JSX.Element = ( setNotificationState(RoomNotifState.MentionsOnly))} /> ); const muteOption: JSX.Element = ( setNotificationState(RoomNotifState.Mute))} /> ); return ( {defaultOption} {allMessagesOption} {mentionsOption} {muteOption} ); };