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

Commit 848adfd

Browse files
authored
Add way to create a user notice via config.json (#9559)
1 parent 985119d commit 848adfd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/IConfigOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ export interface IConfigOptions {
183183
// length per voice chunk in seconds
184184
chunk_length?: number;
185185
};
186+
187+
user_notice?: {
188+
title: string;
189+
description: string;
190+
show_once?: boolean;
191+
};
186192
}
187193

188194
export interface ISsoRedirectOptions {

src/components/structures/MatrixChat.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ import { isLocalRoom } from '../../utils/localRoom/isLocalRoom';
139139
import { SdkContextClass, SDKContext } from '../../contexts/SDKContext';
140140
import { viewUserDeviceSettings } from '../../actions/handlers/viewUserDeviceSettings';
141141
import { VoiceBroadcastResumer } from '../../voice-broadcast';
142+
import GenericToast from "../views/toasts/GenericToast";
143+
import { Linkify } from "../views/elements/Linkify";
142144

143145
// legacy export
144146
export { default as Views } from "../../Views";
@@ -1332,6 +1334,28 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13321334
// check if it has been dismissed before, etc.
13331335
showMobileGuideToast();
13341336
}
1337+
1338+
const userNotice = SdkConfig.get("user_notice");
1339+
if (userNotice) {
1340+
const key = "user_notice_" + userNotice.title;
1341+
if (!userNotice.show_once || !localStorage.getItem(key)) {
1342+
ToastStore.sharedInstance().addOrReplaceToast({
1343+
key,
1344+
title: userNotice.title,
1345+
props: {
1346+
description: <Linkify>{ userNotice.description }</Linkify>,
1347+
acceptLabel: _t("OK"),
1348+
onAccept: () => {
1349+
ToastStore.sharedInstance().dismissToast(key);
1350+
localStorage.setItem(key, "1");
1351+
},
1352+
},
1353+
component: GenericToast,
1354+
className: "mx_AnalyticsToast",
1355+
priority: 100,
1356+
});
1357+
}
1358+
}
13351359
}
13361360

13371361
private initPosthogAnalyticsToast() {

0 commit comments

Comments
 (0)