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

@ -23,8 +23,12 @@ import { M_POLL_START } from "matrix-events-sdk";
import { MatrixClientPeg } from '../MatrixClientPeg';
import shouldHideEvent from "../shouldHideEvent";
import { getHandlerTile, haveTileForEvent } from "../components/views/rooms/EventTile";
import { getHandlerTile, GetRelationsForEvent, haveTileForEvent } from "../components/views/rooms/EventTile";
import SettingsStore from "../settings/SettingsStore";
import defaultDispatcher from "../dispatcher/dispatcher";
import { TimelineRenderingType } from "../contexts/RoomContext";
import { launchPollEditor } from "../components/views/messages/MPollBody";
import { Action } from "../dispatcher/actions";
/**
* Returns whether an event should allow actions like reply, reactions, edit, etc.
@ -312,3 +316,21 @@ export async function fetchInitialEvent(
return initialEvent;
}
export function editEvent(
mxEvent: MatrixEvent,
timelineRenderingType: TimelineRenderingType,
getRelationsForEvent?: GetRelationsForEvent,
): void {
if (!canEditContent(mxEvent)) return;
if (M_POLL_START.matches(mxEvent.getType())) {
launchPollEditor(mxEvent, getRelationsForEvent);
} else {
defaultDispatcher.dispatch({
action: Action.EditEvent,
event: mxEvent,
timelineRenderingType: timelineRenderingType,
});
}
}