From d671bcec31a0ae6090063fcf7bbcd2f4e0b17bee Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 17 May 2021 20:32:35 +0530 Subject: [PATCH 1/4] Add js-docs for linkify function Signed-off-by: RMidhunSuresh --- src/domain/session/room/timeline/linkify/linkify.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/domain/session/room/timeline/linkify/linkify.js b/src/domain/session/room/timeline/linkify/linkify.js index 333705c1..58641055 100644 --- a/src/domain/session/room/timeline/linkify/linkify.js +++ b/src/domain/session/room/timeline/linkify/linkify.js @@ -1,5 +1,13 @@ import { regex } from "./regex.js"; +/** + * Splits text into links and non-links. + * For each such separated token, callback is called + * with the token and a boolean passed as argument. + * The boolean indicates whether the token is a link or not. + * @param {string} text Text to split + * @param {function(string, boolean)} callback A function to call with split tokens + */ export function linkify(text, callback) { const matches = text.matchAll(regex); let curr = 0; From 11d551f8a3029084bd449f35d9bcd71c31da1704 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 17 May 2021 20:39:23 +0530 Subject: [PATCH 2/4] Add js-doc for parsePlainBody Signed-off-by: RMidhunSuresh --- src/domain/session/room/timeline/MessageBody.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/domain/session/room/timeline/MessageBody.js b/src/domain/session/room/timeline/MessageBody.js index a2250dfb..de8fcc73 100644 --- a/src/domain/session/room/timeline/MessageBody.js +++ b/src/domain/session/room/timeline/MessageBody.js @@ -1,5 +1,10 @@ import { linkify } from "./linkify/linkify.js"; +/** + * Parse text into parts such as newline, links and text. + * @param {string} body A string to parse into parts + * @returns {MessageBody} Parsed result + */ export function parsePlainBody(body) { const parts = []; const lines = body.split("\n"); From 1d63799c9b00b45e0876eb7bbcc82e621436a787 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 17 May 2021 20:56:12 +0530 Subject: [PATCH 3/4] Added js-doc for formatFunction Signed-off-by: RMidhunSuresh --- src/platform/web/ui/session/room/timeline/TextMessageView.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/web/ui/session/room/timeline/TextMessageView.js b/src/platform/web/ui/session/room/timeline/TextMessageView.js index 4af5e5a2..dc5550ee 100644 --- a/src/platform/web/ui/session/room/timeline/TextMessageView.js +++ b/src/platform/web/ui/session/room/timeline/TextMessageView.js @@ -28,6 +28,9 @@ export class TextMessageView extends TemplateView { } } +/** + * Map from part to function that outputs DOM for the part + */ const formatFunction = { text: textPart => text(textPart.text), link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, [linkPart.text]), From 72f58b6001a91dff0632942c172eb6463bfc79da Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 18 May 2021 14:26:56 +0530 Subject: [PATCH 4/4] Change lines[i] to line Signed-off-by: RMidhunSuresh --- src/domain/session/room/timeline/MessageBody.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/session/room/timeline/MessageBody.js b/src/domain/session/room/timeline/MessageBody.js index de8fcc73..42f3c951 100644 --- a/src/domain/session/room/timeline/MessageBody.js +++ b/src/domain/session/room/timeline/MessageBody.js @@ -21,7 +21,7 @@ export function parsePlainBody(body) { for (let i = 0; i < lines.length; i += 1) { const line = lines[i]; if (line.length) { - linkify(lines[i], linkifyCallback); + linkify(line, linkifyCallback); } const isLastLine = i >= (lines.length - 1); if (!isLastLine) {