From 408a732045f22fe102d60bff008ae9aa2cecc5a9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 9 Nov 2022 09:34:51 +0000 Subject: [PATCH] Add way to create a user notice via config.json --- src/IConfigOptions.ts | 6 ++++++ src/components/structures/MatrixChat.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index b45461618e1..462a78ad2a5 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -183,6 +183,12 @@ export interface IConfigOptions { // length per voice chunk in seconds chunk_length?: number; }; + + user_notice?: { + title: string; + description: string; + show_once?: boolean; + }; } export interface ISsoRedirectOptions { diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 56d1d8d7ab5..e80b99e32dc 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -139,6 +139,8 @@ import { isLocalRoom } from '../../utils/localRoom/isLocalRoom'; import { SdkContextClass, SDKContext } from '../../contexts/SDKContext'; import { viewUserDeviceSettings } from '../../actions/handlers/viewUserDeviceSettings'; import { VoiceBroadcastResumer } from '../../voice-broadcast'; +import GenericToast from "../views/toasts/GenericToast"; +import { Linkify } from "../views/elements/Linkify"; // legacy export export { default as Views } from "../../Views"; @@ -1332,6 +1334,28 @@ export default class MatrixChat extends React.PureComponent { // check if it has been dismissed before, etc. showMobileGuideToast(); } + + const userNotice = SdkConfig.get("user_notice"); + if (userNotice) { + const key = "user_notice_" + userNotice.title; + if (!userNotice.show_once || !localStorage.getItem(key)) { + ToastStore.sharedInstance().addOrReplaceToast({ + key, + title: userNotice.title, + props: { + description: { userNotice.description }, + acceptLabel: _t("OK"), + onAccept: () => { + ToastStore.sharedInstance().dismissToast(key); + localStorage.setItem(key, "1"); + }, + }, + component: GenericToast, + className: "mx_AnalyticsToast", + priority: 100, + }); + } + } } private initPosthogAnalyticsToast() {