/* Copyright 2019-2021 The Matrix.org Foundation C.I.C. Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React from "react"; import { _t } from "../../../../../languageHandler"; import { UseCase } from "../../../../../settings/enums/UseCase"; import SettingsStore from "../../../../../settings/SettingsStore"; import Field from "../../../elements/Field"; import { SettingLevel } from "../../../../../settings/SettingLevel"; import SettingsFlag from "../../../elements/SettingsFlag"; import AccessibleButton from "../../../elements/AccessibleButton"; import dis from "../../../../../dispatcher/dispatcher"; import { UserTab } from "../../../dialogs/UserTab"; import { OpenToTabPayload } from "../../../../../dispatcher/payloads/OpenToTabPayload"; import { Action } from "../../../../../dispatcher/actions"; import SdkConfig from "../../../../../SdkConfig"; import { MatrixClientPeg } from "../../../../../MatrixClientPeg"; import { showUserOnboardingPage } from "../../../user-onboarding/UserOnboardingPage"; interface IProps { closeSettingsFn(success: boolean): void; } interface IState { disablingReadReceiptsSupported: boolean; autocompleteDelay: string; readMarkerInViewThresholdMs: string; readMarkerOutOfViewThresholdMs: string; } export default class PreferencesUserSettingsTab extends React.Component { private static ROOM_LIST_SETTINGS = ["breadcrumbs", "FTUE.userOnboardingButton"]; private static SPACES_SETTINGS = ["Spaces.allRoomsInHome"]; private static KEYBINDINGS_SETTINGS = ["ctrlFForSearch"]; private static PRESENCE_SETTINGS = [ "sendTypingNotifications", // sendReadReceipts - handled specially due to server needing support ]; private static COMPOSER_SETTINGS = [ "MessageComposerInput.autoReplaceEmoji", "MessageComposerInput.useMarkdown", "MessageComposerInput.suggestEmoji", "MessageComposerInput.ctrlEnterToSend", "MessageComposerInput.surroundWith", "MessageComposerInput.showStickersButton", "MessageComposerInput.insertTrailingColon", ]; private static TIME_SETTINGS = ["showTwelveHourTimestamps", "alwaysShowTimestamps"]; private static CODE_BLOCKS_SETTINGS = [ "enableSyntaxHighlightLanguageDetection", "expandCodeByDefault", "showCodeLineNumbers", ]; private static IMAGES_AND_VIDEOS_SETTINGS = ["urlPreviewsEnabled", "autoplayGifs", "autoplayVideo", "showImages"]; private static TIMELINE_SETTINGS = [ "showTypingNotifications", "showRedactions", "showReadReceipts", "showJoinLeaves", "showDisplaynameChanges", "showChatEffects", "showAvatarChanges", "Pill.shouldShowPillAvatar", "TextualBody.enableBigEmoji", "scrollToBottomOnMessageSent", "useOnlyCurrentProfiles", ]; private static GENERAL_SETTINGS = [ "promptBeforeInviteUnknownUsers", // Start automatically after startup (electron-only) // Autocomplete delay (niche text box) ]; public constructor(props) { super(props); this.state = { disablingReadReceiptsSupported: false, autocompleteDelay: SettingsStore.getValueAt(SettingLevel.DEVICE, "autocompleteDelay").toString(10), readMarkerInViewThresholdMs: SettingsStore.getValueAt( SettingLevel.DEVICE, "readMarkerInViewThresholdMs", ).toString(10), readMarkerOutOfViewThresholdMs: SettingsStore.getValueAt( SettingLevel.DEVICE, "readMarkerOutOfViewThresholdMs", ).toString(10), }; } public async componentDidMount(): Promise { const cli = MatrixClientPeg.get(); this.setState({ disablingReadReceiptsSupported: (await cli.doesServerSupportUnstableFeature("org.matrix.msc2285.stable")) || (await cli.isVersionSupported("v1.4")), }); } private onAutocompleteDelayChange = (e: React.ChangeEvent): void => { this.setState({ autocompleteDelay: e.target.value }); SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value); }; private onReadMarkerInViewThresholdMs = (e: React.ChangeEvent): void => { this.setState({ readMarkerInViewThresholdMs: e.target.value }); SettingsStore.setValue("readMarkerInViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; private onReadMarkerOutOfViewThresholdMs = (e: React.ChangeEvent): void => { this.setState({ readMarkerOutOfViewThresholdMs: e.target.value }); SettingsStore.setValue("readMarkerOutOfViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; private renderGroup(settingIds: string[], level = SettingLevel.ACCOUNT): React.ReactNodeArray { return settingIds.map((i) => { const disabled = !SettingsStore.isEnabled(i); return ; }); } private onKeyboardShortcutsClicked = (): void => { dis.dispatch({ action: Action.ViewUserSettings, initialTabId: UserTab.Keyboard, }); }; public render(): JSX.Element { const useCase = SettingsStore.getValue("FTUE.useCaseSelection"); const roomListSettings = PreferencesUserSettingsTab.ROOM_LIST_SETTINGS // Only show the breadcrumbs setting if breadcrumbs v2 is disabled .filter((it) => it !== "breadcrumbs" || !SettingsStore.getValue("feature_breadcrumbs_v2")) // Only show the user onboarding setting if the user should see the user onboarding page .filter((it) => it !== "FTUE.userOnboardingButton" || showUserOnboardingPage(useCase)); return (
{_t("Preferences")}
{roomListSettings.length > 0 && (
{_t("Room list")} {this.renderGroup(roomListSettings)}
)}
{_t("Spaces")} {this.renderGroup(PreferencesUserSettingsTab.SPACES_SETTINGS, SettingLevel.ACCOUNT)}
{_t("Keyboard shortcuts")}
{_t( "To view all keyboard shortcuts, click here.", {}, { a: (sub) => ( {sub} ), }, )}
{this.renderGroup(PreferencesUserSettingsTab.KEYBINDINGS_SETTINGS)}
{_t("Displaying time")} {this.renderGroup(PreferencesUserSettingsTab.TIME_SETTINGS)}
{_t("Presence")} {_t("Share your activity and status with others.")} {this.renderGroup(PreferencesUserSettingsTab.PRESENCE_SETTINGS)}
{_t("Composer")} {this.renderGroup(PreferencesUserSettingsTab.COMPOSER_SETTINGS)}
{_t("Code blocks")} {this.renderGroup(PreferencesUserSettingsTab.CODE_BLOCKS_SETTINGS)}
{_t("Images, GIFs and videos")} {this.renderGroup(PreferencesUserSettingsTab.IMAGES_AND_VIDEOS_SETTINGS)}
{_t("Timeline")} {this.renderGroup(PreferencesUserSettingsTab.TIMELINE_SETTINGS)}
{_t("General")} {this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS)}
); } }