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

Commit ddd8bdc

Browse files
committed
Move all the capability copy to its own class
1 parent 55592d3 commit ddd8bdc

File tree

3 files changed

+413
-148
lines changed

3 files changed

+413
-148
lines changed

src/components/views/dialogs/WidgetCapabilitiesPromptDialog.tsx

Lines changed: 15 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -16,113 +16,19 @@ limitations under the License.
1616

1717
import React from 'react';
1818
import BaseDialog from "./BaseDialog";
19-
import { _t, _td, TranslatedString } from "../../../languageHandler";
19+
import { _t } from "../../../languageHandler";
2020
import { IDialogProps } from "./IDialogProps";
21-
import { Capability, EventDirection, MatrixCapabilities, Widget, WidgetEventCapability } from "matrix-widget-api";
21+
import {
22+
Capability,
23+
Widget,
24+
WidgetEventCapability,
25+
WidgetKind
26+
} from "matrix-widget-api";
2227
import { objectShallowClone } from "../../../utils/objects";
23-
import { ElementWidgetCapabilities } from "../../../stores/widgets/ElementWidgetCapabilities";
24-
import { EventType, MsgType } from "matrix-js-sdk/lib/@types/event";
2528
import StyledCheckbox from "../elements/StyledCheckbox";
2629
import DialogButtons from "../elements/DialogButtons";
2730
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
28-
29-
// TODO: These messaging things can probably get their own store of some sort
30-
const SIMPLE_CAPABILITY_MESSAGES = {
31-
[MatrixCapabilities.AlwaysOnScreen]: _td("Remain on your screen while running"),
32-
[MatrixCapabilities.StickerSending]: _td("Send stickers into your active room"),
33-
[ElementWidgetCapabilities.CanChangeViewedRoom]: _td("Change which room you're viewing"),
34-
};
35-
const SEND_RECV_EVENT_CAPABILITY_MESSAGES = {
36-
[EventType.RoomTopic]: {
37-
// TODO: We probably want to say "this room" when we can
38-
[EventDirection.Send]: _td("Change the topic of your active room"),
39-
[EventDirection.Receive]: _td("See when the topic changes in your active room"),
40-
},
41-
[EventType.RoomName]: {
42-
[EventDirection.Send]: _td("Change the name of your active room"),
43-
[EventDirection.Receive]: _td("See when the name changes in your active room"),
44-
},
45-
[EventType.RoomAvatar]: {
46-
[EventDirection.Send]: _td("Change the avatar of your active room"),
47-
[EventDirection.Receive]: _td("See when the avatar changes in your active room"),
48-
},
49-
// TODO: Add more as needed
50-
};
51-
function textForEventCapabilitiy(cap: WidgetEventCapability): { primary: TranslatedString, byline: TranslatedString } {
52-
let primary: TranslatedString;
53-
let byline: TranslatedString;
54-
55-
if (cap.isState) {
56-
byline = cap.keyStr
57-
? _t("with state key %(stateKey)s", {stateKey: cap.keyStr})
58-
: _t("with an empty state key");
59-
}
60-
61-
const srMessages = SEND_RECV_EVENT_CAPABILITY_MESSAGES[cap.eventType];
62-
if (srMessages && srMessages[cap.direction]) {
63-
primary = _t(srMessages[cap.direction]);
64-
} else {
65-
if (cap.eventType === EventType.RoomMessage) {
66-
if (cap.direction === EventDirection.Receive) {
67-
if (!cap.keyStr) {
68-
primary = _t("See messages sent in your active room");
69-
} else {
70-
if (cap.keyStr === MsgType.Text) {
71-
primary = _t("See text messages sent in your active room");
72-
} else if (cap.keyStr === MsgType.Emote) {
73-
primary = _t("See emotes sent in your active room");
74-
} else if (cap.keyStr === MsgType.Image) {
75-
primary = _t("See images sent in your active room");
76-
} else if (cap.keyStr === MsgType.Video) {
77-
primary = _t("See videos sent in your active room");
78-
} else if (cap.keyStr === MsgType.File) {
79-
primary = _t("See general files sent in your active room");
80-
} else {
81-
primary = _t(
82-
"See <code>%(msgtype)s</code> messages sent in your active room",
83-
{msgtype: cap.keyStr}, {code: sub => <code>{sub}</code>},
84-
);
85-
}
86-
}
87-
} else {
88-
if (!cap.keyStr) {
89-
primary = _t("Send messages as you in your active room");
90-
} else {
91-
if (cap.keyStr === MsgType.Text) {
92-
primary = _t("Send text messages as you in your active room");
93-
} else if (cap.keyStr === MsgType.Emote) {
94-
primary = _t("Send emotes as you in your active room");
95-
} else if (cap.keyStr === MsgType.Image) {
96-
primary = _t("Send images as you in your active room");
97-
} else if (cap.keyStr === MsgType.Video) {
98-
primary = _t("Send videos as you in your active room");
99-
} else if (cap.keyStr === MsgType.File) {
100-
primary = _t("Send general files as you in your active room");
101-
} else {
102-
primary = _t(
103-
"Send <code>%(msgtype)s</code> messages as you in your active room",
104-
{msgtype: cap.keyStr}, {code: sub => <code>{sub}</code>},
105-
);
106-
}
107-
}
108-
}
109-
} else {
110-
if (cap.direction === EventDirection.Receive) {
111-
primary = _t(
112-
"See <code>%(eventType)s</code> events sent in your active room",
113-
{eventType: cap.eventType}, {code: sub => <code>{sub}</code>},
114-
);
115-
} else {
116-
primary = _t(
117-
"Send <code>%(eventType)s</code> events as you in your active room",
118-
{eventType: cap.eventType}, {code: sub => <code>{sub}</code>},
119-
);
120-
}
121-
}
122-
}
123-
124-
return {primary, byline};
125-
}
31+
import { CapabilityText } from "../../../widgets/CapabilityText";
12632

12733
export function getRememberedCapabilitiesForWidget(widget: Widget): Capability[] {
12834
return JSON.parse(localStorage.getItem(`widget_${widget.id}_approved_caps`) || "[]");
@@ -135,6 +41,7 @@ function setRememberedCapabilitiesForWidget(widget: Widget, caps: Capability[])
13541
interface IProps extends IDialogProps {
13642
requestedCapabilities: Set<Capability>;
13743
widget: Widget;
44+
widgetKind: WidgetKind; // TODO: Refactor into the Widget class
13845
}
13946

14047
interface IBooleanStates {
@@ -194,31 +101,19 @@ export default class WidgetCapabilitiesPromptDialog extends React.PureComponent<
194101

195102
public render() {
196103
const checkboxRows = Object.entries(this.state.booleanStates).map(([cap, isChecked], i) => {
197-
const evCap = this.eventPermissionsMap.get(cap);
198-
199-
let text: TranslatedString;
200-
let byline: TranslatedString;
201-
if (evCap) {
202-
const t = textForEventCapabilitiy(evCap);
203-
text = t.primary;
204-
byline = t.byline;
205-
} else if (SIMPLE_CAPABILITY_MESSAGES[cap]) {
206-
text = _t(SIMPLE_CAPABILITY_MESSAGES[cap]);
207-
} else {
208-
text = _t(
209-
"The <code>%(capability)s</code> capability",
210-
{capability: cap}, {code: sub => <code>{sub}</code>},
211-
);
212-
}
104+
const text = CapabilityText.for(cap, this.props.widgetKind);
105+
const byline = text.byline
106+
? <span className="mx_WidgetCapabilitiesPromptDialog_byline">{text.byline}</span>
107+
: null;
213108

214109
return (
215110
<div className="mx_WidgetCapabilitiesPromptDialog_cap">
216111
<StyledCheckbox
217112
key={cap + i}
218113
checked={isChecked}
219114
onChange={() => this.onToggle(cap)}
220-
>{text}</StyledCheckbox>
221-
{byline ? <span className="mx_WidgetCapabilitiesPromptDialog_byline">{byline}</span> : null}
115+
>{text.primary}</StyledCheckbox>
116+
{byline}
222117
</div>
223118
);
224119
});

src/i18n/strings/en_EN.json

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,62 @@
569569
"%(names)s and %(count)s others are typing …|other": "%(names)s and %(count)s others are typing …",
570570
"%(names)s and %(count)s others are typing …|one": "%(names)s and one other is typing …",
571571
"%(names)s and %(lastPerson)s are typing …": "%(names)s and %(lastPerson)s are typing …",
572+
"Remain on your screen when you leave this room (when running)": "Remain on your screen when you leave this room (when running)",
573+
"Remain on your screen while running": "Remain on your screen while running",
574+
"Send stickers into this room": "Send stickers into this room",
575+
"Send stickers into your active room": "Send stickers into your active room",
576+
"Change which room you're viewing": "Change which room you're viewing",
577+
"Change the topic of this room": "Change the topic of this room",
578+
"See when the topic changes in this room": "See when the topic changes in this room",
579+
"Change the topic of your active room": "Change the topic of your active room",
580+
"See when the topic changes in your active room": "See when the topic changes in your active room",
581+
"Change the name of this room": "Change the name of this room",
582+
"See when the name changes in this room": "See when the name changes in this room",
583+
"Change the name of your active room": "Change the name of your active room",
584+
"See when the name changes in your active room": "See when the name changes in your active room",
585+
"Change the avatar of this room": "Change the avatar of this room",
586+
"See when the avatar changes in this room": "See when the avatar changes in this room",
587+
"Change the avatar of your active room": "Change the avatar of your active room",
588+
"See when the avatar changes in your active room": "See when the avatar changes in your active room",
589+
"Send stickers to this room as you": "Send stickers to this room as you",
590+
"See when a sticker is posted in this room": "See when a sticker is posted in this room",
591+
"Send stickers to your active room as you": "Send stickers to your active room as you",
592+
"See when anyone posts a sticker to your active room": "See when anyone posts a sticker to your active room",
593+
"with an empty state key": "with an empty state key",
594+
"with state key %(stateKey)s": "with state key %(stateKey)s",
595+
"Send <b>%(eventType)s</b> events as you in this room": "Send <b>%(eventType)s</b> events as you in this room",
596+
"See <b>%(eventType)s</b> events posted to this room": "See <b>%(eventType)s</b> events posted to this room",
597+
"Send <b>%(eventType)s</b> events as you in your active room": "Send <b>%(eventType)s</b> events as you in your active room",
598+
"See <b>%(eventType)s</b> events posted to your active room": "See <b>%(eventType)s</b> events posted to your active room",
599+
"The <b>%(capability)s</b> capability": "The <b>%(capability)s</b> capability",
600+
"Send messages as you in this room": "Send messages as you in this room",
601+
"Send messages as you in your active room": "Send messages as you in your active room",
602+
"See messages posted to this room": "See messages posted to this room",
603+
"See messages posted to your active room": "See messages posted to your active room",
604+
"Send text messages as you in this room": "Send text messages as you in this room",
605+
"Send text messages as you in your active room": "Send text messages as you in your active room",
606+
"See text messages posted to this room": "See text messages posted to this room",
607+
"See text messages posted to your active room": "See text messages posted to your active room",
608+
"Send emotes as you in this room": "Send emotes as you in this room",
609+
"Send emotes as you in your active room": "Send emotes as you in your active room",
610+
"See emotes posted to this room": "See emotes posted to this room",
611+
"See emotes posted to your active room": "See emotes posted to your active room",
612+
"Send images as you in this room": "Send images as you in this room",
613+
"Send images as you in your active room": "Send images as you in your active room",
614+
"See images posted to this room": "See images posted to this room",
615+
"See images posted to your active room": "See images posted to your active room",
616+
"Send videos as you in this room": "Send videos as you in this room",
617+
"Send videos as you in your active room": "Send videos as you in your active room",
618+
"See videos posted to this room": "See videos posted to this room",
619+
"See videos posted to your active room": "See videos posted to your active room",
620+
"Send general files as you in this room": "Send general files as you in this room",
621+
"Send general files as you in your active room": "Send general files as you in your active room",
622+
"See general files posted to this room": "See general files posted to this room",
623+
"See general files posted to your active room": "See general files posted to your active room",
624+
"Send <b>%(msgtype)s</b> messages as you in this room": "Send <b>%(msgtype)s</b> messages as you in this room",
625+
"Send <b>%(msgtype)s</b> messages as you in your active room": "Send <b>%(msgtype)s</b> messages as you in your active room",
626+
"See <b>%(msgtype)s</b> messages posted to this room": "See <b>%(msgtype)s</b> messages posted to this room",
627+
"See <b>%(msgtype)s</b> messages posted to your active room": "See <b>%(msgtype)s</b> messages posted to your active room",
572628
"Cannot reach homeserver": "Cannot reach homeserver",
573629
"Ensure you have a stable internet connection, or get in touch with the server admin": "Ensure you have a stable internet connection, or get in touch with the server admin",
574630
"Your %(brand)s is misconfigured": "Your %(brand)s is misconfigured",
@@ -2123,34 +2179,6 @@
21232179
"Upload Error": "Upload Error",
21242180
"Verify other session": "Verify other session",
21252181
"Verification Request": "Verification Request",
2126-
"Remain on your screen while running": "Remain on your screen while running",
2127-
"Send stickers into your active room": "Send stickers into your active room",
2128-
"Change which room you're viewing": "Change which room you're viewing",
2129-
"Change the topic of your active room": "Change the topic of your active room",
2130-
"See when the topic changes in your active room": "See when the topic changes in your active room",
2131-
"Change the name of your active room": "Change the name of your active room",
2132-
"See when the name changes in your active room": "See when the name changes in your active room",
2133-
"Change the avatar of your active room": "Change the avatar of your active room",
2134-
"See when the avatar changes in your active room": "See when the avatar changes in your active room",
2135-
"with state key %(stateKey)s": "with state key %(stateKey)s",
2136-
"with an empty state key": "with an empty state key",
2137-
"See messages sent in your active room": "See messages sent in your active room",
2138-
"See text messages sent in your active room": "See text messages sent in your active room",
2139-
"See emotes sent in your active room": "See emotes sent in your active room",
2140-
"See images sent in your active room": "See images sent in your active room",
2141-
"See videos sent in your active room": "See videos sent in your active room",
2142-
"See general files sent in your active room": "See general files sent in your active room",
2143-
"See <code>%(msgtype)s</code> messages sent in your active room": "See <code>%(msgtype)s</code> messages sent in your active room",
2144-
"Send messages as you in your active room": "Send messages as you in your active room",
2145-
"Send text messages as you in your active room": "Send text messages as you in your active room",
2146-
"Send emotes as you in your active room": "Send emotes as you in your active room",
2147-
"Send images as you in your active room": "Send images as you in your active room",
2148-
"Send videos as you in your active room": "Send videos as you in your active room",
2149-
"Send general files as you in your active room": "Send general files as you in your active room",
2150-
"Send <code>%(msgtype)s</code> messages as you in your active room": "Send <code>%(msgtype)s</code> messages as you in your active room",
2151-
"See <code>%(eventType)s</code> events sent in your active room": "See <code>%(eventType)s</code> events sent in your active room",
2152-
"Send <code>%(eventType)s</code> events as you in your active room": "Send <code>%(eventType)s</code> events as you in your active room",
2153-
"The <code>%(capability)s</code> capability": "The <code>%(capability)s</code> capability",
21542182
"Approve widget permissions": "Approve widget permissions",
21552183
"This widget would like to:": "This widget would like to:",
21562184
"Remember my selection for this widget": "Remember my selection for this widget",

0 commit comments

Comments
 (0)