Move editEvent() to EventUtils (#7836)

This commit is contained in:
Šimon Brandner 2022-02-18 16:01:32 +01:00 committed by GitHub
parent 34567b9aab
commit fe7f1688dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 63 deletions

View file

@ -38,6 +38,9 @@ import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
import StyledRadioButton from '../elements/StyledRadioButton';
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import ErrorDialog from '../dialogs/ErrorDialog';
import { GetRelationsForEvent } from "../rooms/EventTile";
import PollCreateDialog from "../elements/PollCreateDialog";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
interface IState {
selected?: string; // Which option was clicked by the local user
@ -169,6 +172,43 @@ export function isPollEnded(
return authorisedRelations.length > 0;
}
export function pollAlreadyHasVotes(mxEvent: MatrixEvent, getRelationsForEvent?: GetRelationsForEvent): boolean {
if (!getRelationsForEvent) return false;
const voteRelations = createVoteRelations(getRelationsForEvent, mxEvent.getId());
return voteRelations.getRelations().length > 0;
}
export function launchPollEditor(mxEvent: MatrixEvent, getRelationsForEvent?: GetRelationsForEvent): void {
if (pollAlreadyHasVotes(mxEvent, getRelationsForEvent)) {
Modal.createTrackedDialog(
'Not allowed to edit poll',
'',
ErrorDialog,
{
title: _t("Can't edit poll"),
description: _t(
"Sorry, you can't edit a poll after votes have been cast.",
),
},
);
} else {
Modal.createTrackedDialog(
'Polls',
'create',
PollCreateDialog,
{
room: MatrixClientPeg.get().getRoom(mxEvent.getRoomId()),
threadId: mxEvent.getThread()?.id ?? null,
editingMxEvent: mxEvent,
},
'mx_CompoundDialog',
false, // isPriorityModal
true, // isStaticModal
);
}
}
@replaceableComponent("views.messages.MPollBody")
export default class MPollBody extends React.Component<IBodyProps, IState> {
public static contextType = MatrixClientContext;