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

Add unexposed account setting for hiding poll creation #7972

Merged
merged 4 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ interface IState {
isMenuOpen: boolean;
isStickerPickerOpen: boolean;
showStickersButton: boolean;
showPollsButton: boolean;
}

@replaceableComponent("views.rooms.MessageComposer")
Expand Down Expand Up @@ -122,11 +123,13 @@ export default class MessageComposer extends React.Component<IProps, IState> {
isMenuOpen: false,
isStickerPickerOpen: false,
showStickersButton: SettingsStore.getValue("MessageComposerInput.showStickersButton"),
showPollsButton: SettingsStore.getValue("MessageComposerInput.showPollsButton"),
};

this.instanceId = instanceCount++;

SettingsStore.monitorSetting("MessageComposerInput.showStickersButton", null);
SettingsStore.monitorSetting("MessageComposerInput.showPollsButton", null);
}

private get voiceRecording(): Optional<VoiceRecording> {
Expand Down Expand Up @@ -195,6 +198,13 @@ export default class MessageComposer extends React.Component<IProps, IState> {
}
break;
}
case "MessageComposerInput.showPollsButton": {
const showPollsButton = SettingsStore.getValue("MessageComposerInput.showPollsButton");
if (this.state.showPollsButton !== showPollsButton) {
this.setState({ showPollsButton });
}
break;
}
}
}
}
Expand Down Expand Up @@ -482,6 +492,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
}}
setStickerPickerOpen={this.setStickerPickerOpen}
showLocationButton={!window.electron}
showPollsButton={this.state.showPollsButton}
showStickersButton={this.state.showStickersButton}
toggleButtonMenu={this.toggleButtonMenu}
/> }
Expand Down
16 changes: 10 additions & 6 deletions src/components/views/rooms/MessageComposerButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface IProps {
relation?: IEventRelation;
setStickerPickerOpen: (isStickerPickerOpen: boolean) => void;
showLocationButton: boolean;
showPollsButton: boolean;
showStickersButton: boolean;
toggleButtonMenu: () => void;
}
Expand All @@ -73,7 +74,7 @@ const MessageComposerButtons: React.FC<IProps> = (props: IProps) => {
uploadButton(), // props passed via UploadButtonContext
showStickersButton(props),
voiceRecordingButton(props, narrow),
pollButton(room, props.relation),
pollButton(room, props.relation, props.showPollsButton),
showLocationButton(props, room, roomId, matrixClient),
];
} else {
Expand All @@ -84,7 +85,7 @@ const MessageComposerButtons: React.FC<IProps> = (props: IProps) => {
moreButtons = [
showStickersButton(props),
voiceRecordingButton(props, narrow),
pollButton(room, props.relation),
pollButton(room, props.relation, props.showPollsButton),
turt2live marked this conversation as resolved.
Show resolved Hide resolved
showLocationButton(props, room, roomId, matrixClient),
];
}
Expand Down Expand Up @@ -285,17 +286,18 @@ function voiceRecordingButton(props: IProps, narrow: boolean): ReactElement {
);
}

function pollButton(room: Room, relation?: IEventRelation): ReactElement {
return <PollButton key="polls" room={room} relation={relation} />;
function pollButton(room: Room, relation?: IEventRelation, isVisible?: boolean): ReactElement {
return <PollButton key="polls" room={room} relation={relation} isVisible={isVisible} />;
turt2live marked this conversation as resolved.
Show resolved Hide resolved
}

interface IPollButtonProps {
room: Room;
relation?: IEventRelation;
isVisible: boolean;
}

class PollButton extends React.PureComponent<IPollButtonProps> {
static contextType = OverflowMenuContext;
public static contextType = OverflowMenuContext;
public context!: React.ContextType<typeof OverflowMenuContext>;

private onCreateClick = () => {
Expand Down Expand Up @@ -336,7 +338,9 @@ class PollButton extends React.PureComponent<IPollButtonProps> {
}
};

render() {
public render() {
if (!this.props.isVisible) return null;

// do not allow sending polls within threads at this time
if (this.props.relation?.rel_type === RelationType.Thread) return null;

Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@
"Use custom size": "Use custom size",
"Enable Emoji suggestions while typing": "Enable Emoji suggestions while typing",
"Show stickers button": "Show stickers button",
"Show polls button": "Show polls button",
"Use a more compact 'Modern' layout": "Use a more compact 'Modern' layout",
"Show a placeholder for removed messages": "Show a placeholder for removed messages",
"Show join/leave messages (invites/removes/bans unaffected)": "Show join/leave messages (invites/removes/bans unaffected)",
Expand Down
5 changes: 5 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ export const SETTINGS: {[setting: string]: ISetting} = {
default: true,
controller: new UIFeatureController(UIFeature.Widgets, false),
},
"MessageComposerInput.showPollsButton": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Show polls button'),
default: true,
},
// TODO: Wire up appropriately to UI (FTUE notifications)
"Notifications.alwaysShowBadgeCounts": {
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
Expand Down
54 changes: 54 additions & 0 deletions test/components/views/rooms/MessageComposerButtons-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe("MessageComposerButtons", () => {
<MessageComposerButtons
isMenuOpen={false}
showLocationButton={true}
showPollsButton={true}
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
Expand All @@ -57,6 +58,7 @@ describe("MessageComposerButtons", () => {
<MessageComposerButtons
isMenuOpen={true}
showLocationButton={true}
showPollsButton={true}
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
Expand All @@ -81,6 +83,7 @@ describe("MessageComposerButtons", () => {
<MessageComposerButtons
isMenuOpen={false}
showLocationButton={true}
showPollsButton={true}
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
Expand All @@ -98,6 +101,7 @@ describe("MessageComposerButtons", () => {
<MessageComposerButtons
isMenuOpen={true}
showLocationButton={true}
showPollsButton={true}
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
Expand All @@ -115,6 +119,56 @@ describe("MessageComposerButtons", () => {
],
]);
});

describe('polls button', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize this test is a bit weird, but it's probably better than nothing. Testing that the MessageComposer responds to the settings store feels a bit weird, so haven't written the test. Happy to be convinced otherwise though.

it('should render when asked to', () => {
const buttons = wrapAndRender(
<MessageComposerButtons
isMenuOpen={true}
showLocationButton={true}
showPollsButton={true}
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
true,
);

expect(buttonLabels(buttons)).toEqual([
"Emoji",
"More options",
[
"Attachment",
"Sticker",
"Poll",
"Location",
],
]);
});

it('should not render when asked not to', () => {
const buttons = wrapAndRender(
<MessageComposerButtons
isMenuOpen={true}
showLocationButton={true}
showPollsButton={false} // !! the change from the alternate test
showStickersButton={true}
toggleButtonMenu={() => {}}
/>,
true,
);

expect(buttonLabels(buttons)).toEqual([
"Emoji",
"More options",
[
"Attachment",
"Sticker",
// "Poll", // should be hidden
"Location",
],
]);
});
});
});

function wrapAndRender(component: React.ReactElement, narrow: boolean): ReactWrapper {
Expand Down