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

@ -20,14 +20,13 @@ import React, { ReactElement, useEffect } from 'react';
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames';
import { MsgType } from 'matrix-js-sdk/src/@types/event';
import { M_POLL_START } from 'matrix-events-sdk';
import type { Relations } from 'matrix-js-sdk/src/models/relations';
import { _t } from '../../../languageHandler';
import dis from '../../../dispatcher/dispatcher';
import { Action } from '../../../dispatcher/actions';
import ContextMenu, { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from '../../structures/ContextMenu';
import { isContentActionable, canEditContent } from '../../../utils/EventUtils';
import { isContentActionable, canEditContent, editEvent } from '../../../utils/EventUtils';
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
import Toolbar from "../../../accessibility/Toolbar";
import { RovingAccessibleTooltipButton, useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
@ -40,13 +39,9 @@ import DownloadActionButton from "./DownloadActionButton";
import SettingsStore from '../../../settings/SettingsStore';
import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks';
import ReplyChain from '../elements/ReplyChain';
import { showThread } from '../../../dispatcher/dispatch-actions/threads';
import ReactionPicker from "../emojipicker/ReactionPicker";
import { CardContext } from '../right_panel/BaseCard';
import Modal from '../../../Modal';
import PollCreateDialog from '../elements/PollCreateDialog';
import ErrorDialog from '../dialogs/ErrorDialog';
import { createVoteRelations } from './MPollBody';
import { showThread } from "../../../dispatcher/dispatch-actions/threads";
interface IOptionsButtonProps {
mxEvent: MatrixEvent;
@ -233,59 +228,8 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
});
};
private pollAlreadyHasVotes = (): boolean => {
if (!this.props.getRelationsForEvent) {
return false;
}
const voteRelations = createVoteRelations(
this.props.getRelationsForEvent,
this.props.mxEvent.getId(),
);
return voteRelations.getRelations().length > 0;
};
private launchPollEditor = (): void => {
if (this.pollAlreadyHasVotes()) {
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: this.context.room,
threadId: this.context.threadId ?? null,
editingMxEvent: this.props.mxEvent,
},
'mx_CompoundDialog',
false, // isPriorityModal
true, // isStaticModal
);
}
};
private onEditClick = (): void => {
if (M_POLL_START.matches(this.props.mxEvent.getType())) {
this.launchPollEditor();
} else {
dis.dispatch({
action: Action.EditEvent,
event: this.props.mxEvent,
timelineRenderingType: this.context.timelineRenderingType,
});
}
editEvent(this.props.mxEvent, this.context.timelineRenderingType);
};
private readonly forbiddenThreadHeadMsgType = [