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

Commit 14cc44e

Browse files
authored
Add activity toggle for TAC (#12413)
* Add activity toggle for TAC * Update test snapshots for new toggles * Add test for TAC activity setting set to false * Update snapshot for old notifications panel test too * Fix test * Rename setting * Rename variables too * Sort i18n keys * Use functional component
1 parent aadb463 commit 14cc44e

File tree

8 files changed

+262
-46
lines changed

8 files changed

+262
-46
lines changed

src/components/views/settings/Notifications.tsx

+35-35
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { Caption } from "../typography/Caption";
5858
import { SettingsSubsectionHeading } from "./shared/SettingsSubsectionHeading";
5959
import SettingsSubsection from "./shared/SettingsSubsection";
6060
import { doesRoomHaveUnreadMessages } from "../../../Unread";
61+
import SettingsFlag from "../elements/SettingsFlag";
6162

6263
// TODO: this "view" component still has far too much application logic in it,
6364
// which should be factored out to other files.
@@ -200,6 +201,18 @@ const maximumVectorState = (
200201
return vectorState;
201202
};
202203

204+
const NotificationActivitySettings = (): JSX.Element => {
205+
return (
206+
<div>
207+
<SettingsFlag name="Notifications.showbold" level={SettingLevel.DEVICE} />
208+
<SettingsFlag name="Notifications.tac_only_notifications" level={SettingLevel.DEVICE} />
209+
</div>
210+
);
211+
};
212+
213+
/**
214+
* The old, deprecated notifications tab view, only displayed if the user has the labs flag disabled.
215+
*/
203216
export default class Notifications extends React.PureComponent<IProps, IState> {
204217
private settingWatchers: string[];
205218

@@ -731,43 +744,10 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
731744
}
732745

733746
private renderCategory(category: RuleClass): ReactNode {
734-
if (category !== RuleClass.VectorOther && this.isInhibited) {
747+
if (this.isInhibited) {
735748
return null; // nothing to show for the section
736749
}
737750

738-
let clearNotifsButton: JSX.Element | undefined;
739-
if (
740-
category === RuleClass.VectorOther &&
741-
MatrixClientPeg.safeGet()
742-
.getRooms()
743-
.some((r) => doesRoomHaveUnreadMessages(r, true))
744-
) {
745-
clearNotifsButton = (
746-
<AccessibleButton
747-
onClick={this.onClearNotificationsClicked}
748-
disabled={this.state.clearingNotifications}
749-
kind="danger"
750-
className="mx_UserNotifSettings_clearNotifsButton"
751-
data-testid="clear-notifications"
752-
>
753-
{_t("notifications|mark_all_read")}
754-
</AccessibleButton>
755-
);
756-
}
757-
758-
if (category === RuleClass.VectorOther && this.isInhibited) {
759-
// only render the utility buttons (if needed)
760-
if (clearNotifsButton) {
761-
return (
762-
<div className="mx_UserNotifSettings_floatingSection">
763-
<div>{_t("notifications|class_other")}</div>
764-
{clearNotifsButton}
765-
</div>
766-
);
767-
}
768-
return null;
769-
}
770-
771751
let keywordComposer: JSX.Element | undefined;
772752
if (category === RuleClass.VectorMentions) {
773753
const tags = filterBoolean<string>(this.state.vectorKeywordRuleInfo?.rules.map((r) => r.pattern) || []);
@@ -842,7 +822,6 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
842822
<span className="mx_UserNotifSettings_gridColumnLabel">{VectorStateToLabel[VectorState.Loud]}</span>
843823
{fieldsetRows}
844824
</div>
845-
{clearNotifsButton}
846825
{keywordComposer}
847826
</div>
848827
);
@@ -878,13 +857,34 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
878857
return <p data-testid="error-message">{_t("settings|notifications|error_loading")}</p>;
879858
}
880859

860+
let clearNotifsButton: JSX.Element | undefined;
861+
if (
862+
MatrixClientPeg.safeGet()
863+
.getRooms()
864+
.some((r) => doesRoomHaveUnreadMessages(r, true))
865+
) {
866+
clearNotifsButton = (
867+
<AccessibleButton
868+
onClick={this.onClearNotificationsClicked}
869+
disabled={this.state.clearingNotifications}
870+
kind="danger"
871+
className="mx_UserNotifSettings_clearNotifsButton"
872+
data-testid="clear-notifications"
873+
>
874+
{_t("notifications|mark_all_read")}
875+
</AccessibleButton>
876+
);
877+
}
878+
881879
return (
882880
<>
883881
{this.renderTopSection()}
884882
{this.renderCategory(RuleClass.VectorGlobal)}
885883
{this.renderCategory(RuleClass.VectorMentions)}
886884
{this.renderCategory(RuleClass.VectorOther)}
887885
{this.renderTargets()}
886+
<NotificationActivitySettings />
887+
{clearNotifsButton}
888888
</>
889889
);
890890
}

src/components/views/settings/notifications/NotificationSettings2.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { SettingsBanner } from "../shared/SettingsBanner";
4141
import { SettingsSection } from "../shared/SettingsSection";
4242
import SettingsSubsection from "../shared/SettingsSubsection";
4343
import { NotificationPusherSettings } from "./NotificationPusherSettings";
44+
import SettingsFlag from "../../elements/SettingsFlag";
4445

4546
enum NotificationDefaultLevels {
4647
AllMessages = "all_messages",
@@ -71,6 +72,9 @@ function useHasUnreadNotifications(): boolean {
7172
return cli.getRooms().some((room) => room.getUnreadNotificationCount() > 0);
7273
}
7374

75+
/**
76+
* The new notification settings tab view, only displayed if the user has Features.NotificationSettings2 enabled
77+
*/
7478
export default function NotificationSettings2(): JSX.Element {
7579
const cli = useMatrixClientContext();
7680

@@ -352,6 +356,9 @@ export default function NotificationSettings2(): JSX.Element {
352356
label={_t("notifications|keyword")}
353357
placeholder={_t("notifications|keyword_new")}
354358
/>
359+
360+
<SettingsFlag name="Notifications.showbold" level={SettingLevel.DEVICE} />
361+
<SettingsFlag name="Notifications.tac_only_notifications" level={SettingLevel.DEVICE} />
355362
</SettingsSubsection>
356363
<NotificationPusherSettings />
357364
<SettingsSubsection heading={_t("settings|notifications|quick_actions_section")}>

src/components/views/spaces/threads-activity-centre/useUnreadThreadRooms.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ type Result = {
4343
*/
4444
export function useUnreadThreadRooms(forceComputation: boolean): Result {
4545
const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors");
46+
const settingTACOnlyNotifs = useSettingValue<boolean>("Notifications.tac_only_notifications");
4647
const mxClient = useMatrixClientContext();
4748

4849
const [result, setResult] = useState<Result>({ greatestNotificationLevel: NotificationLevel.None, rooms: [] });
4950

5051
const doUpdate = useCallback(() => {
51-
setResult(computeUnreadThreadRooms(mxClient, msc3946ProcessDynamicPredecessor));
52-
}, [mxClient, msc3946ProcessDynamicPredecessor]);
52+
setResult(computeUnreadThreadRooms(mxClient, msc3946ProcessDynamicPredecessor, settingTACOnlyNotifs));
53+
}, [mxClient, msc3946ProcessDynamicPredecessor, settingTACOnlyNotifs]);
5354

5455
// The exhautive deps lint rule can't compute dependencies here since it's not a plain inline func.
5556
// We make this as simple as possible so its only dep is doUpdate itself.
@@ -83,7 +84,11 @@ export function useUnreadThreadRooms(forceComputation: boolean): Result {
8384
* @param mxClient - MatrixClient
8485
* @param msc3946ProcessDynamicPredecessor
8586
*/
86-
function computeUnreadThreadRooms(mxClient: MatrixClient, msc3946ProcessDynamicPredecessor: boolean): Result {
87+
function computeUnreadThreadRooms(
88+
mxClient: MatrixClient,
89+
msc3946ProcessDynamicPredecessor: boolean,
90+
settingTACOnlyNotifs: boolean,
91+
): Result {
8792
// Only count visible rooms to not torment the user with notification counts in rooms they can't see.
8893
// This will include highlights from the previous version of the room internally
8994
const visibleRooms = mxClient.getVisibleRooms(msc3946ProcessDynamicPredecessor);
@@ -98,7 +103,7 @@ function computeUnreadThreadRooms(mxClient: MatrixClient, msc3946ProcessDynamicP
98103
const notificationLevel = getThreadNotificationLevel(room);
99104

100105
// If the room has an activity notification or less, we ignore it
101-
if (notificationLevel <= NotificationLevel.Activity) {
106+
if (settingTACOnlyNotifs && notificationLevel <= NotificationLevel.Activity) {
102107
continue;
103108
}
104109

src/i18n/strings/en_EN.json

+2
Original file line numberDiff line numberDiff line change
@@ -2846,6 +2846,7 @@
28462846
"show_redaction_placeholder": "Show a placeholder for removed messages",
28472847
"show_stickers_button": "Show stickers button",
28482848
"show_typing_notifications": "Show typing notifications",
2849+
"showbold": "Show all activity in the room list (dots or number of unread messages)",
28492850
"sidebar": {
28502851
"metaspaces_favourites_description": "Group all your favourite rooms and people in one place.",
28512852
"metaspaces_home_all_rooms": "Show all rooms",
@@ -2862,6 +2863,7 @@
28622863
"title": "Sidebar"
28632864
},
28642865
"start_automatically": "Start automatically after system login",
2866+
"tac_only_notifications": "Only show notifications in the thread activity centre",
28652867
"use_12_hour_format": "Show timestamps in 12 hour format (e.g. 2:30pm)",
28662868
"use_command_enter_send_message": "Use Command + Enter to send a message",
28672869
"use_command_f_search": "Use Command + F to search timeline",

src/settings/Settings.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright 2017 Travis Ralston
3-
Copyright 2018 - 2023 The Matrix.org Foundation C.I.C.
3+
Copyright 2018 - 2024 The Matrix.org Foundation C.I.C.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -586,14 +586,23 @@ export const SETTINGS: { [setting: string]: ISetting } = {
586586
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
587587
default: false,
588588
},
589+
// Used to be a feature, name kept for backwards compat
589590
"feature_hidebold": {
590-
isFeature: true,
591-
labsGroup: LabGroup.Rooms,
592-
configDisablesSetting: true,
593591
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
594592
displayName: _td("labs|hidebold"),
595593
default: false,
596594
},
595+
"Notifications.showbold": {
596+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
597+
displayName: _td("settings|showbold"),
598+
default: false,
599+
invertedSettingName: "feature_hidebold",
600+
},
601+
"Notifications.tac_only_notifications": {
602+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
603+
displayName: _td("settings|tac_only_notifications"),
604+
default: true,
605+
},
597606
"feature_ask_to_join": {
598607
isFeature: true,
599608
labsGroup: LabGroup.Rooms,

test/components/views/settings/__snapshots__/Notifications-test.tsx.snap

+56
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,61 @@ exports[`<Notifications /> main notification switches renders only enable notifi
3535
/>
3636
</div>
3737
</div>
38+
<div>
39+
<div
40+
class="mx_SettingsFlag"
41+
>
42+
<label
43+
class="mx_SettingsFlag_label"
44+
for="mx_SettingsFlag_testid_1"
45+
>
46+
<span
47+
class="mx_SettingsFlag_labelText"
48+
>
49+
Show all activity in the room list (dots or number of unread messages)
50+
</span>
51+
</label>
52+
<div
53+
aria-checked="true"
54+
aria-disabled="false"
55+
aria-label="Show all activity in the room list (dots or number of unread messages)"
56+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
57+
id="mx_SettingsFlag_testid_1"
58+
role="switch"
59+
tabindex="0"
60+
>
61+
<div
62+
class="mx_ToggleSwitch_ball"
63+
/>
64+
</div>
65+
</div>
66+
<div
67+
class="mx_SettingsFlag"
68+
>
69+
<label
70+
class="mx_SettingsFlag_label"
71+
for="mx_SettingsFlag_testid_2"
72+
>
73+
<span
74+
class="mx_SettingsFlag_labelText"
75+
>
76+
Only show notifications in the thread activity centre
77+
</span>
78+
</label>
79+
<div
80+
aria-checked="true"
81+
aria-disabled="false"
82+
aria-label="Only show notifications in the thread activity centre"
83+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
84+
id="mx_SettingsFlag_testid_2"
85+
role="switch"
86+
tabindex="0"
87+
>
88+
<div
89+
class="mx_ToggleSwitch_ball"
90+
/>
91+
</div>
92+
</div>
93+
</div>
3894
</div>
3995
`;

0 commit comments

Comments
 (0)