Make composer buttons react to settings without having to change room (#7264)

pull/21833/head
Michael Telatynski 2021-12-02 14:09:57 +00:00 committed by GitHub
parent b5a488b01b
commit f40291d408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 13 deletions

View File

@ -35,7 +35,6 @@ import ContextMenu, {
} from "../../structures/ContextMenu";
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import ReplyPreview from "./ReplyPreview";
import { UIFeature } from "../../../settings/UIFeature";
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import VoiceRecordComposerTile from "./VoiceRecordComposerTile";
@ -56,6 +55,7 @@ import RoomContext from '../../../contexts/RoomContext';
import { POLL_START_EVENT_TYPE } from "../../../polls/consts";
import ErrorDialog from "../dialogs/ErrorDialog";
import PollCreateDialog from "../elements/PollCreateDialog";
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";
let instanceCount = 0;
const NARROW_MODE_BREAKPOINT = 500;
@ -249,6 +249,8 @@ interface IState {
narrowMode?: boolean;
isMenuOpen: boolean;
showStickers: boolean;
showStickersButton: boolean;
showPollsButton: boolean;
}
@replaceableComponent("views.rooms.MessageComposer")
@ -278,9 +280,14 @@ export default class MessageComposer extends React.Component<IProps, IState> {
recordingTimeLeftSeconds: null, // when set to a number, shows a toast
isMenuOpen: false,
showStickers: false,
showStickersButton: SettingsStore.getValue("MessageComposerInput.showStickersButton"),
showPollsButton: SettingsStore.getValue("feature_polls"),
};
this.instanceId = instanceCount++;
SettingsStore.monitorSetting("MessageComposerInput.showStickersButton", null);
SettingsStore.monitorSetting("feature_polls", null);
}
componentDidMount() {
@ -303,7 +310,9 @@ export default class MessageComposer extends React.Component<IProps, IState> {
};
private onAction = (payload: ActionPayload) => {
if (payload.action === 'reply_to_event' && payload.context === this.context.timelineRenderingType) {
switch (payload.action) {
case "reply_to_event":
if (payload.context === this.context.timelineRenderingType) {
// add a timeout for the reply preview to be rendered, so
// that the ScrollPanel listening to the resizeNotifier can
// correctly measure it's new height and scroll down to keep
@ -312,6 +321,29 @@ export default class MessageComposer extends React.Component<IProps, IState> {
this.props.resizeNotifier.notifyTimelineHeightChanged();
}, 100);
}
break;
case Action.SettingUpdated: {
const settingUpdatedPayload = payload as SettingUpdatedPayload;
switch (settingUpdatedPayload.settingName) {
case "MessageComposerInput.showStickersButton": {
const showStickersButton = SettingsStore.getValue("MessageComposerInput.showStickersButton");
if (this.state.showStickersButton !== showStickersButton) {
this.setState({ showStickersButton });
}
break;
}
case "feature_polls": {
const showPollsButton = SettingsStore.getValue("feature_polls");
if (this.state.showPollsButton !== showPollsButton) {
this.setState({ showPollsButton });
}
break;
}
}
}
}
};
private waitForOwnMember() {
@ -452,9 +484,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
};
private shouldShowStickerPicker = (): boolean => {
return SettingsStore.getValue(UIFeature.Widgets)
&& SettingsStore.getValue("MessageComposerInput.showStickersButton")
&& !this.state.haveRecording;
return this.state.showStickersButton && !this.state.haveRecording;
};
private showStickers = (showStickers: boolean) => {
@ -471,7 +501,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
let uploadButtonIndex = 0;
const buttons: JSX.Element[] = [];
if (!this.state.haveRecording) {
if (SettingsStore.getValue("feature_polls")) {
if (this.state.showPollsButton) {
buttons.push(
<PollButton key="polls" room={this.props.room} />,
);

View File

@ -392,6 +392,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Show stickers button'),
default: true,
controller: new UIFeatureController(UIFeature.Widgets, false),
},
// TODO: Wire up appropriately to UI (FTUE notifications)
"Notifications.alwaysShowBadgeCounts": {