Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add way to create a user notice via config.json #9559

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/IConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ export interface IConfigOptions {
// length per voice chunk in seconds
chunk_length?: number;
};

user_notice?: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it should be an array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'd want any user to be tormented that much :P

title: string;
description: string;
show_once?: boolean;
};
}

export interface ISsoRedirectOptions {
Expand Down
24 changes: 24 additions & 0 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1332,6 +1334,28 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// 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: <Linkify>{ userNotice.description }</Linkify>,
acceptLabel: _t("OK"),
onAccept: () => {
ToastStore.sharedInstance().dismissToast(key);
localStorage.setItem(key, "1");
},
},
component: GenericToast,
className: "mx_AnalyticsToast",
priority: 100,
});
}
}
}

private initPosthogAnalyticsToast() {
Expand Down