Add a flag to strip replies
This commit is contained in:
parent
06961ff693
commit
b5f16468ce
2 changed files with 15 additions and 6 deletions
|
@ -34,7 +34,8 @@ const baseUrl = 'https://matrix.to';
|
||||||
const linkPrefix = `${baseUrl}/#/`;
|
const linkPrefix = `${baseUrl}/#/`;
|
||||||
|
|
||||||
class Deserializer {
|
class Deserializer {
|
||||||
constructor(result, mediaRepository) {
|
constructor(result, mediaRepository, allowReplies) {
|
||||||
|
this.allowReplies = allowReplies;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.mediaRepository = mediaRepository;
|
this.mediaRepository = mediaRepository;
|
||||||
}
|
}
|
||||||
|
@ -287,6 +288,10 @@ class Deserializer {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_isAllowedNode(node) {
|
||||||
|
return this.allowReplies || !this._ensureElement(node, "MX-REPLY");
|
||||||
|
}
|
||||||
|
|
||||||
_parseInlineNodes(nodes, into) {
|
_parseInlineNodes(nodes, into) {
|
||||||
for (const htmlNode of nodes) {
|
for (const htmlNode of nodes) {
|
||||||
if (this._parseTextParts(htmlNode, into)) {
|
if (this._parseTextParts(htmlNode, into)) {
|
||||||
|
@ -301,7 +306,9 @@ class Deserializer {
|
||||||
}
|
}
|
||||||
// Node is either block or unrecognized. In
|
// Node is either block or unrecognized. In
|
||||||
// both cases, just move on to its children.
|
// both cases, just move on to its children.
|
||||||
this._parseInlineNodes(this.result.getChildNodes(htmlNode), into);
|
if (this._isAllowedNode(htmlNode)) {
|
||||||
|
this._parseInlineNodes(this.result.getChildNodes(htmlNode), into);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +332,9 @@ class Deserializer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Node is unrecognized. Just move on to its children.
|
// Node is unrecognized. Just move on to its children.
|
||||||
this._parseAnyNodes(this.result.getChildNodes(htmlNode), into);
|
if (this._isAllowedNode(htmlNode)) {
|
||||||
|
this._parseAnyNodes(this.result.getChildNodes(htmlNode), into);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,9 +345,9 @@ class Deserializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseHTMLBody(platform, mediaRepository, html) {
|
export function parseHTMLBody(platform, mediaRepository, allowReplies, html) {
|
||||||
const parseResult = platform.parseHTML(html);
|
const parseResult = platform.parseHTML(html);
|
||||||
const deserializer = new Deserializer(parseResult, mediaRepository);
|
const deserializer = new Deserializer(parseResult, mediaRepository, allowReplies);
|
||||||
const parts = deserializer.parseAnyNodes(parseResult.rootNodes);
|
const parts = deserializer.parseAnyNodes(parseResult.rootNodes);
|
||||||
return new MessageBody(html, parts);
|
return new MessageBody(html, parts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class TextTile extends BaseTextTile {
|
||||||
|
|
||||||
_parseBody(body, format) {
|
_parseBody(body, format) {
|
||||||
if (format === BodyFormat.Html) {
|
if (format === BodyFormat.Html) {
|
||||||
return parseHTMLBody(this.platform, this._mediaRepository, body);
|
return parseHTMLBody(this.platform, this._mediaRepository, this._entry.isReply, body);
|
||||||
} else {
|
} else {
|
||||||
return parsePlainBody(body);
|
return parsePlainBody(body);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue