Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Stop sending reply and edit fallbacks (MSC2781) #6964

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 4 additions & 31 deletions src/components/views/rooms/EditMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,6 @@ import { withMatrixClientHOC, MatrixClientProps } from '../../../contexts/Matrix
import RoomContext from '../../../contexts/RoomContext';
import { ComposerType } from "../../../dispatcher/payloads/ComposerInsertPayload";

function getHtmlReplyFallback(mxEvent: MatrixEvent): string {
const html = mxEvent.getContent().formatted_body;
if (!html) {
return "";
}
const rootNode = new DOMParser().parseFromString(html, "text/html").body;
const mxReply = rootNode.querySelector("mx-reply");
return (mxReply && mxReply.outerHTML) || "";
}

function getTextReplyFallback(mxEvent: MatrixEvent): string {
const body = mxEvent.getContent().body;
const lines = body.split("\n").map(l => l.trim());
if (lines.length > 2 && lines[0].startsWith("> ") && lines[1].length === 0) {
return `${lines[0]}\n\n`;
}
return "";
}

function createEditContent(
model: EditorModel,
editedEvent: MatrixEvent,
Expand All @@ -75,14 +56,6 @@ function createEditContent(
if (isEmote) {
model = stripEmoteCommand(model);
}
const isReply = !!editedEvent.replyEventId;
let plainPrefix = "";
let htmlPrefix = "";

if (isReply) {
plainPrefix = getTextReplyFallback(editedEvent);
htmlPrefix = getHtmlReplyFallback(editedEvent);
}

const body = textSerialize(model);

Expand All @@ -91,16 +64,16 @@ function createEditContent(
"body": body,
};
const contentBody: IContent = {
msgtype: newContent.msgtype,
body: `${plainPrefix} * ${body}`,
"msgtype": newContent.msgtype,
"body": body,
};

const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: isReply });
const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: false });
if (formattedBody) {
newContent.format = "org.matrix.custom.html";
newContent.formatted_body = formattedBody;
contentBody.format = newContent.format;
contentBody.formatted_body = `${htmlPrefix} * ${formattedBody}`;
contentBody.formatted_body = formattedBody;
}

const relation = {
Expand Down
13 changes: 2 additions & 11 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ function addReplyToMessageContent(
): void {
const replyContent = ReplyChain.makeReplyMixIn(replyToEvent);
Object.assign(content, replyContent);

// Part of Replies fallback support - prepend the text we're sending
// with the text we're replying to
const nestedReply = ReplyChain.getNestedReplyText(replyToEvent, permalinkCreator);
if (nestedReply) {
if (content.formatted_body) {
content.formatted_body = nestedReply.html + content.formatted_body;
}
content.body = nestedReply.body + content.body;
}
}

export function attachRelation(
Expand Down Expand Up @@ -112,7 +102,8 @@ export function createMessageContent(
msgtype: isEmote ? "m.emote" : "m.text",
body: body,
};
const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: !!replyToEvent });

const formattedBody = htmlSerializeIfNeeded(model, { forceHTML: false });
if (formattedBody) {
content.format = "org.matrix.custom.html";
content.formatted_body = formattedBody;
Expand Down