Fix poll creation from a thread (#7706)
This commit is contained in:
parent
75b03ca101
commit
f0446a23d5
2 changed files with 18 additions and 5 deletions
|
@ -30,6 +30,7 @@ import Spinner from "./Spinner";
|
||||||
|
|
||||||
interface IProps extends IDialogProps {
|
interface IProps extends IDialogProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
threadId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState extends IScrollableBaseState {
|
interface IState extends IScrollableBaseState {
|
||||||
|
@ -103,7 +104,12 @@ export default class PollCreateDialog extends ScrollableBaseModal<IProps, IState
|
||||||
this.state.options.map(a => a.trim()).filter(a => !!a),
|
this.state.options.map(a => a.trim()).filter(a => !!a),
|
||||||
M_POLL_KIND_DISCLOSED,
|
M_POLL_KIND_DISCLOSED,
|
||||||
).serialize();
|
).serialize();
|
||||||
this.matrixClient.sendEvent(this.props.room.roomId, pollEvent.type, pollEvent.content).then(
|
this.matrixClient.sendEvent(
|
||||||
|
this.props.room.roomId,
|
||||||
|
this.props.threadId,
|
||||||
|
pollEvent.type,
|
||||||
|
pollEvent.content,
|
||||||
|
).then(
|
||||||
() => this.props.onFinished(true),
|
() => this.props.onFinished(true),
|
||||||
).catch(e => {
|
).catch(e => {
|
||||||
console.error("Failed to post poll:", e);
|
console.error("Failed to post poll:", e);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { M_POLL_START } from "matrix-events-sdk";
|
||||||
import React, { createContext, ReactElement, useContext } from 'react';
|
import React, { createContext, ReactElement, useContext } from 'react';
|
||||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||||
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
import { MatrixClient } from 'matrix-js-sdk/src/client';
|
||||||
|
import { RelationType } from 'matrix-js-sdk/src/@types/event';
|
||||||
|
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
||||||
|
@ -73,7 +74,7 @@ const MessageComposerButtons: React.FC<IProps> = (props: IProps) => {
|
||||||
uploadButton(props, roomId),
|
uploadButton(props, roomId),
|
||||||
showStickersButton(props),
|
showStickersButton(props),
|
||||||
voiceRecordingButton(props),
|
voiceRecordingButton(props),
|
||||||
pollButton(room),
|
pollButton(room, props.relation),
|
||||||
showLocationButton(props, room, roomId, matrixClient),
|
showLocationButton(props, room, roomId, matrixClient),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,7 +85,7 @@ const MessageComposerButtons: React.FC<IProps> = (props: IProps) => {
|
||||||
moreButtons = [
|
moreButtons = [
|
||||||
showStickersButton(props),
|
showStickersButton(props),
|
||||||
voiceRecordingButton(props),
|
voiceRecordingButton(props),
|
||||||
pollButton(room),
|
pollButton(room, props.relation),
|
||||||
showLocationButton(props, room, roomId, matrixClient),
|
showLocationButton(props, room, roomId, matrixClient),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -288,12 +289,13 @@ function voiceRecordingButton(props: IProps): ReactElement {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollButton(room: Room): ReactElement {
|
function pollButton(room: Room, relation?: IEventRelation): ReactElement {
|
||||||
return <PollButton key="polls" room={room} />;
|
return <PollButton key="polls" room={room} relation={relation} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IPollButtonProps {
|
interface IPollButtonProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
relation?: IEventRelation;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PollButton extends React.PureComponent<IPollButtonProps> {
|
class PollButton extends React.PureComponent<IPollButtonProps> {
|
||||||
|
@ -319,12 +321,17 @@ class PollButton extends React.PureComponent<IPollButtonProps> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
const threadId = this.props.relation.rel_type === RelationType.Thread
|
||||||
|
? this.props.relation.event_id
|
||||||
|
: null;
|
||||||
|
|
||||||
Modal.createTrackedDialog(
|
Modal.createTrackedDialog(
|
||||||
'Polls',
|
'Polls',
|
||||||
'create',
|
'create',
|
||||||
PollCreateDialog,
|
PollCreateDialog,
|
||||||
{
|
{
|
||||||
room: this.props.room,
|
room: this.props.room,
|
||||||
|
threadId,
|
||||||
},
|
},
|
||||||
'mx_CompoundDialog',
|
'mx_CompoundDialog',
|
||||||
false, // isPriorityModal
|
false, // isPriorityModal
|
||||||
|
|
Loading…
Reference in a new issue