When deleting a voice broadcast, also delete related events (#9737)

This commit is contained in:
Michael Weimann 2022-12-23 16:44:01 +01:00 committed by GitHub
parent a2777d3a03
commit 32140855fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 178 additions and 3 deletions

View file

@ -14,12 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
import { MatrixEvent, RelationType } from "matrix-js-sdk/src/matrix";
import React from "react";
import { _t } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import Modal from "../../../Modal";
import { isVoiceBroadcastStartedEvent } from "../../../voice-broadcast/utils/isVoiceBroadcastStartedEvent";
import ErrorDialog from "./ErrorDialog";
import TextInputDialog from "./TextInputDialog";
@ -55,6 +57,14 @@ export function createRedactEventDialog({
mxEvent: MatrixEvent;
onCloseDialog?: () => void;
}) {
const eventId = mxEvent.getId();
if (!eventId) throw new Error("cannot redact event without ID");
const roomId = mxEvent.getRoomId();
if (!roomId) throw new Error(`cannot redact event ${mxEvent.getId()} without room ID`);
Modal.createDialog(
ConfirmRedactDialog,
{
@ -62,10 +72,27 @@ export function createRedactEventDialog({
if (!proceed) return;
const cli = MatrixClientPeg.get();
const withRelations: { with_relations?: RelationType[] } = {};
// redact related events if this is a voice broadcast started event and
// server has support for relation based redactions
if (isVoiceBroadcastStartedEvent(mxEvent)) {
const relationBasedRedactionsSupport = cli.canSupport.get(Feature.RelationBasedRedactions);
if (
relationBasedRedactionsSupport &&
relationBasedRedactionsSupport !== ServerSupport.Unsupported
) {
withRelations.with_relations = [RelationType.Reference];
}
}
try {
onCloseDialog?.();
await cli.redactEvent(mxEvent.getRoomId(), mxEvent.getId(), undefined, reason ? { reason } : {});
} catch (e) {
await cli.redactEvent(roomId, eventId, undefined, {
...(reason ? { reason } : {}),
...withRelations,
});
} catch (e: any) {
const code = e.errcode || e.statusCode;
// only show the dialog if failing for something other than a network error
// (e.g. no errcode or statusCode) as in that case the redactions end up in the