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

Commit f40291d

Browse files
authored
Make composer buttons react to settings without having to change room (#7264)
1 parent b5a488b commit f40291d

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

src/components/views/rooms/MessageComposer.tsx

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import ContextMenu, {
3535
} from "../../structures/ContextMenu";
3636
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
3737
import ReplyPreview from "./ReplyPreview";
38-
import { UIFeature } from "../../../settings/UIFeature";
3938
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
4039
import { replaceableComponent } from "../../../utils/replaceableComponent";
4140
import VoiceRecordComposerTile from "./VoiceRecordComposerTile";
@@ -56,6 +55,7 @@ import RoomContext from '../../../contexts/RoomContext';
5655
import { POLL_START_EVENT_TYPE } from "../../../polls/consts";
5756
import ErrorDialog from "../dialogs/ErrorDialog";
5857
import PollCreateDialog from "../elements/PollCreateDialog";
58+
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";
5959

6060
let instanceCount = 0;
6161
const NARROW_MODE_BREAKPOINT = 500;
@@ -249,6 +249,8 @@ interface IState {
249249
narrowMode?: boolean;
250250
isMenuOpen: boolean;
251251
showStickers: boolean;
252+
showStickersButton: boolean;
253+
showPollsButton: boolean;
252254
}
253255

254256
@replaceableComponent("views.rooms.MessageComposer")
@@ -278,9 +280,14 @@ export default class MessageComposer extends React.Component<IProps, IState> {
278280
recordingTimeLeftSeconds: null, // when set to a number, shows a toast
279281
isMenuOpen: false,
280282
showStickers: false,
283+
showStickersButton: SettingsStore.getValue("MessageComposerInput.showStickersButton"),
284+
showPollsButton: SettingsStore.getValue("feature_polls"),
281285
};
282286

283287
this.instanceId = instanceCount++;
288+
289+
SettingsStore.monitorSetting("MessageComposerInput.showStickersButton", null);
290+
SettingsStore.monitorSetting("feature_polls", null);
284291
}
285292

286293
componentDidMount() {
@@ -303,14 +310,39 @@ export default class MessageComposer extends React.Component<IProps, IState> {
303310
};
304311

305312
private onAction = (payload: ActionPayload) => {
306-
if (payload.action === 'reply_to_event' && payload.context === this.context.timelineRenderingType) {
307-
// add a timeout for the reply preview to be rendered, so
308-
// that the ScrollPanel listening to the resizeNotifier can
309-
// correctly measure it's new height and scroll down to keep
310-
// at the bottom if it already is
311-
setTimeout(() => {
312-
this.props.resizeNotifier.notifyTimelineHeightChanged();
313-
}, 100);
313+
switch (payload.action) {
314+
case "reply_to_event":
315+
if (payload.context === this.context.timelineRenderingType) {
316+
// add a timeout for the reply preview to be rendered, so
317+
// that the ScrollPanel listening to the resizeNotifier can
318+
// correctly measure it's new height and scroll down to keep
319+
// at the bottom if it already is
320+
setTimeout(() => {
321+
this.props.resizeNotifier.notifyTimelineHeightChanged();
322+
}, 100);
323+
}
324+
break;
325+
326+
case Action.SettingUpdated: {
327+
const settingUpdatedPayload = payload as SettingUpdatedPayload;
328+
switch (settingUpdatedPayload.settingName) {
329+
case "MessageComposerInput.showStickersButton": {
330+
const showStickersButton = SettingsStore.getValue("MessageComposerInput.showStickersButton");
331+
if (this.state.showStickersButton !== showStickersButton) {
332+
this.setState({ showStickersButton });
333+
}
334+
break;
335+
}
336+
337+
case "feature_polls": {
338+
const showPollsButton = SettingsStore.getValue("feature_polls");
339+
if (this.state.showPollsButton !== showPollsButton) {
340+
this.setState({ showPollsButton });
341+
}
342+
break;
343+
}
344+
}
345+
}
314346
}
315347
};
316348

@@ -452,9 +484,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
452484
};
453485

454486
private shouldShowStickerPicker = (): boolean => {
455-
return SettingsStore.getValue(UIFeature.Widgets)
456-
&& SettingsStore.getValue("MessageComposerInput.showStickersButton")
457-
&& !this.state.haveRecording;
487+
return this.state.showStickersButton && !this.state.haveRecording;
458488
};
459489

460490
private showStickers = (showStickers: boolean) => {
@@ -471,7 +501,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
471501
let uploadButtonIndex = 0;
472502
const buttons: JSX.Element[] = [];
473503
if (!this.state.haveRecording) {
474-
if (SettingsStore.getValue("feature_polls")) {
504+
if (this.state.showPollsButton) {
475505
buttons.push(
476506
<PollButton key="polls" room={this.props.room} />,
477507
);

src/settings/Settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
392392
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
393393
displayName: _td('Show stickers button'),
394394
default: true,
395+
controller: new UIFeatureController(UIFeature.Widgets, false),
395396
},
396397
// TODO: Wire up appropriately to UI (FTUE notifications)
397398
"Notifications.alwaysShowBadgeCounts": {

0 commit comments

Comments
 (0)