Make composer buttons react to settings without having to change room (#7264)
This commit is contained in:
parent
b5a488b01b
commit
f40291d408
2 changed files with 44 additions and 13 deletions
|
@ -35,7 +35,6 @@ import ContextMenu, {
|
||||||
} from "../../structures/ContextMenu";
|
} from "../../structures/ContextMenu";
|
||||||
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
||||||
import ReplyPreview from "./ReplyPreview";
|
import ReplyPreview from "./ReplyPreview";
|
||||||
import { UIFeature } from "../../../settings/UIFeature";
|
|
||||||
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
|
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
import VoiceRecordComposerTile from "./VoiceRecordComposerTile";
|
import VoiceRecordComposerTile from "./VoiceRecordComposerTile";
|
||||||
|
@ -56,6 +55,7 @@ import RoomContext from '../../../contexts/RoomContext';
|
||||||
import { POLL_START_EVENT_TYPE } from "../../../polls/consts";
|
import { POLL_START_EVENT_TYPE } from "../../../polls/consts";
|
||||||
import ErrorDialog from "../dialogs/ErrorDialog";
|
import ErrorDialog from "../dialogs/ErrorDialog";
|
||||||
import PollCreateDialog from "../elements/PollCreateDialog";
|
import PollCreateDialog from "../elements/PollCreateDialog";
|
||||||
|
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";
|
||||||
|
|
||||||
let instanceCount = 0;
|
let instanceCount = 0;
|
||||||
const NARROW_MODE_BREAKPOINT = 500;
|
const NARROW_MODE_BREAKPOINT = 500;
|
||||||
|
@ -249,6 +249,8 @@ interface IState {
|
||||||
narrowMode?: boolean;
|
narrowMode?: boolean;
|
||||||
isMenuOpen: boolean;
|
isMenuOpen: boolean;
|
||||||
showStickers: boolean;
|
showStickers: boolean;
|
||||||
|
showStickersButton: boolean;
|
||||||
|
showPollsButton: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.rooms.MessageComposer")
|
@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
|
recordingTimeLeftSeconds: null, // when set to a number, shows a toast
|
||||||
isMenuOpen: false,
|
isMenuOpen: false,
|
||||||
showStickers: false,
|
showStickers: false,
|
||||||
|
showStickersButton: SettingsStore.getValue("MessageComposerInput.showStickersButton"),
|
||||||
|
showPollsButton: SettingsStore.getValue("feature_polls"),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.instanceId = instanceCount++;
|
this.instanceId = instanceCount++;
|
||||||
|
|
||||||
|
SettingsStore.monitorSetting("MessageComposerInput.showStickersButton", null);
|
||||||
|
SettingsStore.monitorSetting("feature_polls", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -303,14 +310,39 @@ export default class MessageComposer extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private onAction = (payload: ActionPayload) => {
|
private onAction = (payload: ActionPayload) => {
|
||||||
if (payload.action === 'reply_to_event' && payload.context === this.context.timelineRenderingType) {
|
switch (payload.action) {
|
||||||
// add a timeout for the reply preview to be rendered, so
|
case "reply_to_event":
|
||||||
// that the ScrollPanel listening to the resizeNotifier can
|
if (payload.context === this.context.timelineRenderingType) {
|
||||||
// correctly measure it's new height and scroll down to keep
|
// add a timeout for the reply preview to be rendered, so
|
||||||
// at the bottom if it already is
|
// that the ScrollPanel listening to the resizeNotifier can
|
||||||
setTimeout(() => {
|
// correctly measure it's new height and scroll down to keep
|
||||||
this.props.resizeNotifier.notifyTimelineHeightChanged();
|
// at the bottom if it already is
|
||||||
}, 100);
|
setTimeout(() => {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -452,9 +484,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private shouldShowStickerPicker = (): boolean => {
|
private shouldShowStickerPicker = (): boolean => {
|
||||||
return SettingsStore.getValue(UIFeature.Widgets)
|
return this.state.showStickersButton && !this.state.haveRecording;
|
||||||
&& SettingsStore.getValue("MessageComposerInput.showStickersButton")
|
|
||||||
&& !this.state.haveRecording;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private showStickers = (showStickers: boolean) => {
|
private showStickers = (showStickers: boolean) => {
|
||||||
|
@ -471,7 +501,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
|
||||||
let uploadButtonIndex = 0;
|
let uploadButtonIndex = 0;
|
||||||
const buttons: JSX.Element[] = [];
|
const buttons: JSX.Element[] = [];
|
||||||
if (!this.state.haveRecording) {
|
if (!this.state.haveRecording) {
|
||||||
if (SettingsStore.getValue("feature_polls")) {
|
if (this.state.showPollsButton) {
|
||||||
buttons.push(
|
buttons.push(
|
||||||
<PollButton key="polls" room={this.props.room} />,
|
<PollButton key="polls" room={this.props.room} />,
|
||||||
);
|
);
|
||||||
|
|
|
@ -392,6 +392,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
|
||||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||||
displayName: _td('Show stickers button'),
|
displayName: _td('Show stickers button'),
|
||||||
default: true,
|
default: true,
|
||||||
|
controller: new UIFeatureController(UIFeature.Widgets, false),
|
||||||
},
|
},
|
||||||
// TODO: Wire up appropriately to UI (FTUE notifications)
|
// TODO: Wire up appropriately to UI (FTUE notifications)
|
||||||
"Notifications.alwaysShowBadgeCounts": {
|
"Notifications.alwaysShowBadgeCounts": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue