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}/#/`;
|
const linkPrefix = `${baseUrl}/#/`;
|
||||||
|
|
||||||
class Deserializer {
|
class Deserializer {
|
||||||
constructor(result, mediaRepository, allowReplies) {
|
constructor(result, mediaRepository) {
|
||||||
this.allowReplies = allowReplies;
|
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.mediaRepository = mediaRepository;
|
this.mediaRepository = mediaRepository;
|
||||||
}
|
}
|
||||||
@ -289,7 +288,7 @@ class Deserializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isAllowedNode(node) {
|
_isAllowedNode(node) {
|
||||||
return this.allowReplies || !this._ensureElement(node, "MX-REPLY");
|
return !this._ensureElement(node, "MX-REPLY");
|
||||||
}
|
}
|
||||||
|
|
||||||
_parseInlineNodes(nodes, into) {
|
_parseInlineNodes(nodes, into) {
|
||||||
@ -345,13 +344,11 @@ class Deserializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseHTMLBody(platform, mediaRepository, allowReplies, html) {
|
export function parseHTMLBody(platform, mediaRepository, html) {
|
||||||
if (allowReplies) {
|
|
||||||
// todo: might be better to remove mx-reply and children after parsing, need to think
|
// todo: might be better to remove mx-reply and children after parsing, need to think
|
||||||
html = html.replace(/<mx-reply>.+<\/mx-reply>/, "");
|
html = html.replace(/<mx-reply>.+<\/mx-reply>/, "");
|
||||||
}
|
|
||||||
const parseResult = platform.parseHTML(html);
|
const parseResult = platform.parseHTML(html);
|
||||||
const deserializer = new Deserializer(parseResult, mediaRepository, allowReplies);
|
const deserializer = new Deserializer(parseResult, mediaRepository);
|
||||||
const parts = deserializer.parseAnyNodes(parseResult.rootNodes);
|
const parts = deserializer.parseAnyNodes(parseResult.rootNodes);
|
||||||
return new MessageBody(html, parts);
|
return new MessageBody(html, parts);
|
||||||
}
|
}
|
||||||
@ -405,8 +402,8 @@ export async function tests() {
|
|||||||
parseHTML: (html) => new HTMLParseResult(parse(html))
|
parseHTML: (html) => new HTMLParseResult(parse(html))
|
||||||
};
|
};
|
||||||
|
|
||||||
function test(assert, input, output, replies=true) {
|
function test(assert, input, output) {
|
||||||
assert.deepEqual(parseHTMLBody(platform, null, replies, input), new MessageBody(input, output));
|
assert.deepEqual(parseHTMLBody(platform, null, input), new MessageBody(input, output));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -504,23 +501,15 @@ export async function tests() {
|
|||||||
];
|
];
|
||||||
test(assert, input, output);
|
test(assert, input, output);
|
||||||
},
|
},
|
||||||
"Replies are inserted when allowed": assert => {
|
"Reply fallback is always stripped": 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 => {
|
|
||||||
const input = 'Hello, <em><mx-reply>World</mx-reply></em>!';
|
const input = 'Hello, <em><mx-reply>World</mx-reply></em>!';
|
||||||
|
const strippedInput = 'Hello, <em></em>!';
|
||||||
const output = [
|
const output = [
|
||||||
new TextPart('Hello, '),
|
new TextPart('Hello, '),
|
||||||
new FormatPart("em", []),
|
new FormatPart("em", []),
|
||||||
new TextPart('!'),
|
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.
|
/* Doesnt work: HTML library doesn't handle <pre><code> properly.
|
||||||
"Text with code block": assert => {
|
"Text with code block": assert => {
|
||||||
|
@ -56,7 +56,7 @@ export class TextTile extends BaseTextTile {
|
|||||||
_parseBody(body, format) {
|
_parseBody(body, format) {
|
||||||
let messageBody;
|
let messageBody;
|
||||||
if (format === BodyFormat.Html) {
|
if (format === BodyFormat.Html) {
|
||||||
messageBody = parseHTMLBody(this.platform, this._mediaRepository, this._entry.isReply, body);
|
messageBody = parseHTMLBody(this.platform, this._mediaRepository, body);
|
||||||
} else {
|
} else {
|
||||||
messageBody = parsePlainBody(body);
|
messageBody = parsePlainBody(body);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user