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

Commit

Permalink
Enable the polls feature (#7581)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam authored Jan 20, 2022
1 parent a7a7cb5 commit c4fc200
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 59 deletions.
8 changes: 2 additions & 6 deletions src/components/views/messages/MessageEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
BodyType = UnknownBody;
}

// TODO: this can be done in eventTypes when Polls stabilise
if (M_POLL_START.matches(type)) {
// TODO: this can all disappear when Polls comes out of labs -
// instead, add something like this into this.evTypes:
// [EventType.Poll]: "messages.MPollBody"
if (SettingsStore.getValue("feature_polls")) {
BodyType = sdk.getComponent('messages.MPollBody');
}
BodyType = sdk.getComponent('messages.MPollBody');
}

if (
Expand Down
7 changes: 0 additions & 7 deletions src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,6 @@ export function getHandlerTile(ev: MatrixEvent): string {
}
}

if (
M_POLL_START.matches(type) &&
!SettingsStore.getValue("feature_polls")
) {
return undefined;
}

if (ev.isState()) {
if (stateEventSingular.has(type) && ev.getStateKey() !== "") return undefined;
return stateEventTileTypes[type];
Expand Down
23 changes: 7 additions & 16 deletions src/components/views/rooms/MessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ interface IState {
isMenuOpen: boolean;
showStickers: boolean;
showStickersButton: boolean;
showPollsButton: boolean;
showLocationButton: boolean;
}

Expand Down Expand Up @@ -285,15 +284,13 @@ export default class MessageComposer extends React.Component<IProps, IState> {
isMenuOpen: false,
showStickers: false,
showStickersButton: SettingsStore.getValue("MessageComposerInput.showStickersButton"),
showPollsButton: SettingsStore.getValue("feature_polls"),
showLocationButton: SettingsStore.getValue("MessageComposerInput.showLocationButton"),
};

this.instanceId = instanceCount++;

SettingsStore.monitorSetting("MessageComposerInput.showStickersButton", null);
SettingsStore.monitorSetting("MessageComposerInput.showLocationButton", null);
SettingsStore.monitorSetting("feature_polls", null);
SettingsStore.monitorSetting("feature_location_share", null);
}

Expand Down Expand Up @@ -341,14 +338,6 @@ export default class MessageComposer extends React.Component<IProps, IState> {
break;
}

case "feature_polls": {
const showPollsButton = SettingsStore.getValue("feature_polls");
if (this.state.showPollsButton !== showPollsButton) {
this.setState({ showPollsButton });
}
break;
}

case "MessageComposerInput.showLocationButton":
case "feature_location_share": {
const showLocationButton = SettingsStore.getValue(
Expand Down Expand Up @@ -519,11 +508,13 @@ export default class MessageComposer extends React.Component<IProps, IState> {
let uploadButtonIndex = 0;
const buttons: JSX.Element[] = [];
if (!this.state.haveRecording) {
if (this.state.showPollsButton) {
buttons.push(
<PollButton key="polls" room={this.props.room} narrowMode={this.state.narrowMode} />,
);
}
buttons.push(
<PollButton
key="polls"
room={this.props.room}
narrowMode={this.state.narrowMode}
/>,
);
uploadButtonIndex = buttons.length;
buttons.push(
<UploadButton key="controls_upload" roomId={this.props.room.roomId} relation={this.props.relation} />,
Expand Down
1 change: 0 additions & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@
"Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms",
"Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices",
"Show extensible event representation of events": "Show extensible event representation of events",
"Polls (under active development)": "Polls (under active development)",
"Location sharing (under active development)": "Location sharing (under active development)",
"Show info about bridges in room settings": "Show info about bridges in room settings",
"New layout switcher (with message bubbles)": "New layout switcher (with message bubbles)",
Expand Down
7 changes: 0 additions & 7 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ export const SETTINGS: {[setting: string]: ISetting} = {
displayName: _td("Show extensible event representation of events"),
default: false,
},
"feature_polls": {
isFeature: true,
labsGroup: LabGroup.Messaging,
supportedLevels: LEVELS_FEATURE,
displayName: _td("Polls (under active development)"),
default: false,
},
"feature_location_share": {
isFeature: true,
labsGroup: LabGroup.Messaging,
Expand Down
32 changes: 10 additions & 22 deletions src/stores/room-list/MessagePreviewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { CallHangupEvent } from "./previews/CallHangupEvent";
import { StickerEventPreview } from "./previews/StickerEventPreview";
import { ReactionEventPreview } from "./previews/ReactionEventPreview";
import { UPDATE_EVENT } from "../AsyncStore";
import SettingsStore from "../../settings/SettingsStore";

// Emitted event for when a room's preview has changed. First argument will the room for which
// the change happened.
Expand Down Expand Up @@ -62,27 +61,16 @@ const PREVIEWS = {
isState: false,
previewer: new ReactionEventPreview(),
},
[M_POLL_START.name]: {
isState: false,
previewer: new PollStartEventPreview(),
},
[M_POLL_START.altName]: {
isState: false,
previewer: new PollStartEventPreview(),
},
};

function previews(): Object {
// TODO: when polls comes out of labs, add this to PREVIEWS
if (SettingsStore.getValue("feature_polls")) {
return {
[M_POLL_START.name]: {
isState: false,
previewer: new PollStartEventPreview(),
},
[M_POLL_START.altName]: {
isState: false,
previewer: new PollStartEventPreview(),
},
...PREVIEWS,
};
} else {
return PREVIEWS;
}
}

// The maximum number of events we're willing to look back on to get a preview.
const MAX_EVENTS_BACKWARDS = 50;

Expand Down Expand Up @@ -133,7 +121,7 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
}

public generatePreviewForEvent(event: MatrixEvent): string {
const previewDef = previews()[event.getType()];
const previewDef = PREVIEWS[event.getType()];
// TODO: Handle case where we don't have
if (!previewDef) return '';
const previewText = previewDef.previewer.getTextFor(event, null, true);
Expand Down Expand Up @@ -165,7 +153,7 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {

await this.matrixClient.decryptEventIfNeeded(event);

const previewDef = previews()[event.getType()];
const previewDef = PREVIEWS[event.getType()];
if (!previewDef) continue;
if (previewDef.isState && isNullOrUndefined(event.getStateKey())) continue;

Expand Down

0 comments on commit c4fc200

Please sign in to comment.