From aa3bb9c6ef8ecf6178a0d86ddcc96d2977f52f4c Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 14 Dec 2021 16:21:54 +0530 Subject: [PATCH] Remove allowReplies --- .../session/room/timeline/deserialize.js | 33 +++++++------------ .../session/room/timeline/tiles/TextTile.js | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/domain/session/room/timeline/deserialize.js b/src/domain/session/room/timeline/deserialize.js index b66804a5..bd362206 100644 --- a/src/domain/session/room/timeline/deserialize.js +++ b/src/domain/session/room/timeline/deserialize.js @@ -34,8 +34,7 @@ const baseUrl = 'https://matrix.to'; const linkPrefix = `${baseUrl}/#/`; class Deserializer { - constructor(result, mediaRepository, allowReplies) { - this.allowReplies = allowReplies; + constructor(result, mediaRepository) { this.result = result; this.mediaRepository = mediaRepository; } @@ -289,7 +288,7 @@ class Deserializer { } _isAllowedNode(node) { - return this.allowReplies || !this._ensureElement(node, "MX-REPLY"); + return !this._ensureElement(node, "MX-REPLY"); } _parseInlineNodes(nodes, into) { @@ -345,13 +344,11 @@ class Deserializer { } } -export function parseHTMLBody(platform, mediaRepository, allowReplies, html) { - if (allowReplies) { - // todo: might be better to remove mx-reply and children after parsing, need to think - html = html.replace(/.+<\/mx-reply>/, ""); - } +export function parseHTMLBody(platform, mediaRepository, html) { + // todo: might be better to remove mx-reply and children after parsing, need to think + html = html.replace(/.+<\/mx-reply>/, ""); const parseResult = platform.parseHTML(html); - const deserializer = new Deserializer(parseResult, mediaRepository, allowReplies); + const deserializer = new Deserializer(parseResult, mediaRepository); const parts = deserializer.parseAnyNodes(parseResult.rootNodes); return new MessageBody(html, parts); } @@ -405,8 +402,8 @@ export async function tests() { parseHTML: (html) => new HTMLParseResult(parse(html)) }; - function test(assert, input, output, replies=true) { - assert.deepEqual(parseHTMLBody(platform, null, replies, input), new MessageBody(input, output)); + function test(assert, input, output) { + assert.deepEqual(parseHTMLBody(platform, null, input), new MessageBody(input, output)); } return { @@ -504,23 +501,15 @@ export async function tests() { ]; test(assert, input, output); }, - "Replies are inserted when allowed": assert => { - const input = 'Hello, World!'; - const output = [ - new TextPart('Hello, '), - new FormatPart("em", [new TextPart('World')]), - new TextPart('!'), - ]; - test(assert, input, output); - }, - "Replies are stripped when not allowed": assert => { + "Reply fallback is always stripped": assert => { const input = 'Hello, World!'; + const strippedInput = 'Hello, !'; const output = [ new TextPart('Hello, '), new FormatPart("em", []), new TextPart('!'), ]; - test(assert, input, output, false); + assert.deepEqual(parseHTMLBody(platform, null, input), new MessageBody(strippedInput, output)); } /* Doesnt work: HTML library doesn't handle
 properly.
         "Text with code block": assert => {
diff --git a/src/domain/session/room/timeline/tiles/TextTile.js b/src/domain/session/room/timeline/tiles/TextTile.js
index 29c2311b..acd904a4 100644
--- a/src/domain/session/room/timeline/tiles/TextTile.js
+++ b/src/domain/session/room/timeline/tiles/TextTile.js
@@ -56,7 +56,7 @@ export class TextTile extends BaseTextTile {
     _parseBody(body, format) {
         let messageBody;
         if (format === BodyFormat.Html) {
-            messageBody = parseHTMLBody(this.platform, this._mediaRepository, this._entry.isReply, body);
+            messageBody = parseHTMLBody(this.platform, this._mediaRepository, body);
         } else {
             messageBody = parsePlainBody(body);
         }