mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-06 20:56:33 +02:00
evil temporary hack to apply event transforms in one place
This commit is contained in:
parent
29be1e29d8
commit
675be154c0
@ -60,7 +60,6 @@ import { type IDiff } from "../../../editor/diff";
|
||||
import { getBlobSafeMimeType } from "../../../utils/blobs";
|
||||
import { EMOJI_REGEX } from "../../../HtmlUtils";
|
||||
import { attachMentions, attachRelation } from "../../../utils/messages";
|
||||
import { ModuleApi } from "../../../modules/Api";
|
||||
|
||||
// The prefix used when persisting editor drafts to localstorage.
|
||||
export const EDITOR_STATE_STORAGE_PREFIX = "mx_cider_state_";
|
||||
@ -417,11 +416,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||
// don't bother sending an empty message
|
||||
if (!content.body.trim()) return;
|
||||
|
||||
// Apply module event content transforms
|
||||
for (const cb of ModuleApi.instance.extras.eventContentTransformCallbacks) {
|
||||
content = cb(roomId, content as Record<string, unknown>) as RoomMessageEventContent;
|
||||
}
|
||||
|
||||
if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) {
|
||||
decorateStartSendingTime(content);
|
||||
}
|
||||
|
||||
@ -28,7 +28,6 @@ import { createRedactEventDialog } from "../../../dialogs/ConfirmRedactDialog";
|
||||
import { endEditing, cancelPreviousPendingEdit } from "./editing";
|
||||
import type EditorStateTransfer from "../../../../../utils/EditorStateTransfer";
|
||||
import { createMessageContent, EMOTE_PREFIX } from "./createMessageContent";
|
||||
import { ModuleApi } from "../../../../../modules/Api";
|
||||
import { isContentModified } from "./isContentModified";
|
||||
import { CommandCategories, getCommand } from "../../../../../slash-commands/SlashCommands";
|
||||
import { runSlashCommand, shouldSendAnyway } from "../../../../../editor/commands";
|
||||
@ -123,11 +122,6 @@ export async function sendMessage(
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply module event content transforms
|
||||
for (const cb of ModuleApi.instance.extras.eventContentTransformCallbacks) {
|
||||
content = cb(roomId, content as Record<string, unknown>) as RoomMessageEventContent;
|
||||
}
|
||||
|
||||
if (SettingsStore.getValue("Performance.addSendMessageTimingMetadata")) {
|
||||
decorateStartSendingTime(content);
|
||||
}
|
||||
|
||||
@ -111,6 +111,29 @@ export class ModuleApi implements Api {
|
||||
public static patchClientForEnvelopeTransforms(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const proto = MatrixClient.prototype as any;
|
||||
|
||||
// Patch sendCompleteEvent to apply plaintext content transforms before
|
||||
// encryption. This is the single funnel point for all event sends
|
||||
// (messages, edits, media, stickers, etc.) and has a clean
|
||||
// { roomId, eventObject: { type, content } } shape.
|
||||
const originalSendComplete = proto.sendCompleteEvent;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
proto.sendCompleteEvent = function (this: MatrixClient, params: any) {
|
||||
if (
|
||||
params?.roomId &&
|
||||
params?.eventObject?.content &&
|
||||
ModuleApi._instance?.extras.eventContentTransformCallbacks.length
|
||||
) {
|
||||
let content = params.eventObject.content;
|
||||
for (const cb of ModuleApi._instance.extras.eventContentTransformCallbacks) {
|
||||
content = cb(params.roomId, content);
|
||||
}
|
||||
params.eventObject.content = content;
|
||||
}
|
||||
return originalSendComplete.call(this, params);
|
||||
};
|
||||
|
||||
// Patch sendEventHttpRequest to apply envelope transforms after encryption.
|
||||
const original = proto.sendEventHttpRequest;
|
||||
proto.sendEventHttpRequest = function (
|
||||
this: MatrixClient,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user