mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Remove allowReplies
This commit is contained in:
parent
73c5562fd3
commit
aa3bb9c6ef
@ -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>.+<\/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>.+<\/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, <em><mx-reply>World</mx-reply></em>!';
|
||||
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, <em><mx-reply>World</mx-reply></em>!';
|
||||
const strippedInput = 'Hello, <em></em>!';
|
||||
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 <pre><code> properly.
|
||||
"Text with code block": assert => {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user