From 27345bdbfb3ac13742be90415b00e5fd2e6fbaf1 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Sun, 15 May 2022 15:13:24 -0400 Subject: [PATCH 01/12] added fixes for Issue #2857 --- src/plugins/chatview/tests/chatbox.js | 41 +++++++++++++++++++++++++++ src/shared/rich-text.js | 19 ++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/plugins/chatview/tests/chatbox.js b/src/plugins/chatview/tests/chatbox.js index c1ce92c3bf..69383f95f1 100644 --- a/src/plugins/chatview/tests/chatbox.js +++ b/src/plugins/chatview/tests/chatbox.js @@ -892,6 +892,45 @@ describe("Chatboxes", function () { })); }); }); + + describe("Chatbox Message Styling", function() { + + it("is not applied when sending a chat message containing a HTTP URL with styling template characters( _, \`, \`\`\`, ~, *) in the middle of it", + mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) { + + await mock.waitForRoster(_converse, 'current'); + await mock.openControlBox(_converse); + const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + + spyOn(_converse.api, "trigger").and.callThrough(); + await mock.openChatBoxFor(_converse, contact_jid); + const view = _converse.chatboxviews.get(contact_jid); + let message = 'https://nitter.kavin.rocks/_MG_/~/*/1506109152665382920'; + await mock.sendMessage(view, message); + + expect(view.model.messages.length === 1).toBeTruthy(); + const stored_messages = await view.model.messages.browserStorage.findAll(); + expect(view.model.messages.models[0].attributes.message).toEqual(message); + expect(view.model.messages.length).toBe(1); + + // try second URL + let message2 = 'https://nitter.george.rocks/_G*_/\`/\`\`\`/665382920'; + await mock.sendMessage(view, message2); + + expect(view.model.messages.length === 2).toBeTruthy(); + expect(view.model.messages.models[1].attributes.message).toEqual(message2); + expect(view.model.messages.length).toBe(2); + + // try third URL + let message3 = 'https://nitter.frank.rocks/_OP_/_NP_/\`\`\`/*/~/_qweq_665382920'; + await mock.sendMessage(view, message3); + + expect(view.model.messages.length === 3).toBeTruthy(); + expect(view.model.messages.models[2].attributes.message).toEqual(message3); + expect(view.model.messages.length).toBe(3); + })); + + });; }); describe("Special Messages", function () { @@ -1052,5 +1091,7 @@ describe("Chatboxes", function () { await mock.openChatBoxFor(_converse, sender_jid); expect(select_msgs_indicator().textContent).toBe('1'); })); + + }); }); diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index d260e1e1c9..fa317b3700 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -251,6 +251,13 @@ export class RichText extends String { references.forEach(ref => this.addTemplateResult(ref.begin, ref.end, ref.template)); } + checkIfHttpsUrl (text) { + if(text.slice(0, 8) === "https://"){ + return true; + } + return false; + } + trimMeMessage () { if (this.offset === 0) { // Subtract `/me ` from 3rd person messages @@ -300,7 +307,15 @@ export class RichText extends String { */ await api.trigger('beforeMessageBodyTransformed', this, { 'Synchronous': true }); - this.render_styling && this.addStyling(); + var text = this.toString(); + + if(!this.checkIfHttpsUrl(text)){ + this.render_styling && this.addStyling(); + }else{ + this.render_styling; + } + + // this.render_styling && this.addStyling(); this.addAnnotations(this.addMentions); this.addAnnotations(this.addHyperlinks); this.addAnnotations(this.addMapURLs); @@ -342,6 +357,8 @@ export class RichText extends String { this.references.push({ begin, end, template }); } + + isMeCommand () { const text = this.toString(); if (!text) { From 19f25bcf5fdca6f7c8564ad9eb8b73aef8e286f8 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Sun, 15 May 2022 15:20:54 -0400 Subject: [PATCH 02/12] added changelog entry covering fixes for Issue #2857 --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 33efdef115..94124dca9f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,10 @@ - Remove the `converse-carbons` plugin and make carbons part of the `converse-chat` plugin. - Remove the `message_carbons` configuration setting. Carbons are now always enabled. +## 9.1.2 (2022-05-15) +- Added fixes for Issue #2857. The fix is regarding Converse.js incorrectly applying text styling effects to HTTP URLs that contain special characters(`_`, `\``, `\`\`\``, `~`, `*`). With the fixes applied, the hyperlinks encompass the entire HTTP URL instead of only part of it +- Added integration test for the fixes above to the following file: `/src/plugins/chatview/tests/chatbox.js/` + ## 9.1.1 (2022-05-05) - GIFs don't render inside unfurls and cause a TypeError From c28df0ed39f407853cac195112add19d8809811d Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 17:30:32 -0400 Subject: [PATCH 03/12] implemented new fix based on jcbrand's advice --- src/headless/plugins/muc/muc.js | 2 + src/headless/utils/core.js | 2 + src/shared/chat/message-body.js | 4 +- src/shared/components/rich-text.js | 2 + src/shared/directives/rich-text.js | 4 + src/shared/rich-text.js | 135 ++++++++++++++++++++++++++++- src/shared/styling.js | 16 +++- 7 files changed, 158 insertions(+), 7 deletions(-) diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 5f8916df27..2dc7162815 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -2699,6 +2699,8 @@ const ChatRoomMixin = { */ isUserMentioned (message) { const nick = this.get('nick'); + console.log("isUserMentioned(): "); + console.log(message); if (message.get('references').length) { const mentions = message .get('references') diff --git a/src/headless/utils/core.js b/src/headless/utils/core.js index ea172daf79..6e4b4f36b5 100644 --- a/src/headless/utils/core.js +++ b/src/headless/utils/core.js @@ -108,6 +108,8 @@ u.getLongestSubstring = function (string, candidates) { */ export function prefixMentions (message) { let text = message.getMessageText(); + console.log('prefixMentions(): '); + console.log(text); (message.get('references') || []) .sort((a, b) => b.begin - a.begin) .forEach(ref => { diff --git a/src/shared/chat/message-body.js b/src/shared/chat/message-body.js index b4c7907301..081b5a8069 100644 --- a/src/shared/chat/message-body.js +++ b/src/shared/chat/message-body.js @@ -1,4 +1,4 @@ -import 'shared/registry.js'; +import 'shared/registry.js'; import ImageModal from 'modals/image.js'; import renderRichText from 'shared/directives/rich-text.js'; import { CustomElement } from 'shared/components/element.js'; @@ -41,6 +41,8 @@ export default class MessageBody extends CustomElement { render () { const callback = () => this.model.collection?.trigger('rendered', this.model); const offset = 0; + // console.log("THIS.MODEL"); + // console.log(this.model); const options = { 'media_urls': this.model.get('media_urls'), 'mentions': this.model.get('references'), diff --git a/src/shared/components/rich-text.js b/src/shared/components/rich-text.js index a8b963763c..bcf0f8ab17 100644 --- a/src/shared/components/rich-text.js +++ b/src/shared/components/rich-text.js @@ -64,6 +64,8 @@ export default class RichText extends CustomElement { } render () { + // console.log("components/rich-text.js this.mentions: "); + // console.log(this.mentions); const options = { embed_audio: this.embed_audio, embed_videos: this.embed_videos, diff --git a/src/shared/directives/rich-text.js b/src/shared/directives/rich-text.js index a2edd00308..ab8160d855 100644 --- a/src/shared/directives/rich-text.js +++ b/src/shared/directives/rich-text.js @@ -14,6 +14,10 @@ class RichTextRenderer { } async transform () { + // console.log("RichTextRenderer transform()"); + // console.log(this.text); + // console.log(this.offset); + // console.log(this.options); const text = new RichText(this.text, this.offset, this.options); try { await text.addTemplates(); diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index d260e1e1c9..c1b2dd524e 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -3,7 +3,7 @@ import tpl_gif from 'templates/gif.js'; import tpl_image from 'templates/image.js'; import tpl_video from 'templates/video.js'; import { api } from '@converse/headless/core'; -import { containsDirectives, getDirectiveAndLength, getDirectiveTemplate, isQuoteDirective } from './styling.js'; +import { containsDirectives, getDirectiveAndLength, getDirectiveTemplate, isQuoteDirective, styling_map } from './styling.js'; import { getEmojiMarkup } from './chat/utils.js'; import { getHyperlinkTemplate } from 'utils/html.js'; import { getMediaURLs } from '@converse/headless/shared/chat/utils.js'; @@ -95,6 +95,7 @@ export class RichText extends String { this.options = options; this.payload = []; this.references = []; + this.httpsReferences = []; this.render_styling = options?.render_styling; this.show_images = options?.show_images; this.hide_media_urls = options?.hide_media_urls; @@ -123,9 +124,12 @@ export class RichText extends String { * offset from the start of the original message stanza's body text). */ addHyperlinks (text, local_offset) { + // this.addAnnotations(this.addHttpReferences); + const full_offset = local_offset + this.offset; const urls_meta = this.media_urls || getMediaURLsMetadata(text, local_offset).media_urls || []; const media_urls = getMediaURLs(urls_meta, text, full_offset); + media_urls.filter(o => !o.is_encrypted).forEach(url_obj => { const url_text = url_obj.url; @@ -208,16 +212,86 @@ export class RichText extends String { }); } + /** + * Check for whether a number is within multiple ranges of begin/end references. + * For example: given @param { Array } references array of [{ begin: 23, end: 30, ... }, { begin: 80, end: 100, ... }], function will return false if @param { Integer } search_range = `50`. If @param { Integer } search_range = `90`, function will return true + * @param { Array } references - An array containing reference objects({begin: 1, end: 2, template: {...} }) with ranges of numbers representing begin and end portions of outgoing Chat messages + * @param { Integer } search_range - This value will be compared to all the ranges contained in @param { Array } references in order to determine whether it lying inside any of those ranges + */ + checkNumInRange(references, search_range){ + let v = []; + + let map = new Map(); + + for(var i = 0; i < references.length; i++){ + v.push(references[i].start); + map.set(references[i].start, 1); + v.push(references[i].end); + map.set(references[i].end, 2); + } + + v.sort(function(a, b){ return a - b; }); + let index = this.lowerBound(v, search_range); + + if(index >= 0 && v[index] == search_range){ + return true; + }else{ + if(index >= 0 && map.get(v[index]) == 2){ + return true; + }else{ + return false; + } + } + + } + /** + * Used to obtain the nearest lower bound value for a given @param { Integer } value + * For example: given @param { Array } array contaiing [23, 30, 80, 100], a @param { Integer } value = 90 would return 80 + * @param { Array } array - An array containing a series a integers which are derived from @param { Array } references in `checkNumInRange(references, search_range)` + * @param { Integer } value - This is the search term which a lower bound value nearest to it will be returned by the function + */ + lowerBound(array, value){ + let low = 0; + let high = array.length; + while(low < high){ + let mid = Math.floor((low + high) / 2); + if(value <= array[mid]){ + high = mid; + }else{ + low = mid + 1; + } + } + return low; + } + + /** * Look for XEP-0393 styling directives and add templates for rendering * them. */ addStyling () { const references = []; + var filtered_refs = []; + var urls_coords = []; + + this.addAnnotations(this.addHyperlinks); + + for(var i = 0; i < this.references.length; i++){ + var ending_string = this.references[i].template.strings.length; + if(this.references[i].template.strings[ending_string - 1] == ""){ + + var new_coords = { + start: this.references[i].begin, + end: this.references[i].end + }; + urls_coords.push(new_coords); + } + } if (containsDirectives(this, this.mentions)) { const mention_ranges = this.mentions.map(m => Array.from({ 'length': Number(m.end) }, (v, i) => Number(m.begin) + i) ); + let i = 0; while (i < this.length) { if (mention_ranges.filter(r => r.includes(i)).length) { // eslint-disable-line no-loop-func @@ -226,18 +300,22 @@ export class RichText extends String { i++; continue; } + const { d, length } = getDirectiveAndLength(this, i); if (d && length) { const is_quote = isQuoteDirective(d); const end = i + length; const slice_end = is_quote ? end : end - d.length; let slice_begin = d === '```' ? i + d.length + 1 : i + d.length; + + if (is_quote && this[slice_begin] === ' ') { // Trim leading space inside codeblock slice_begin += 1; } const offset = slice_begin; const text = this.slice(slice_begin, slice_end); + references.push({ 'begin': i, 'template': getDirectiveTemplate(d, text, offset, this.options), @@ -247,10 +325,31 @@ export class RichText extends String { } i++; } + + if(urls_coords.length > 0){ + for(var k = 0; k < references.length; k++){ + try{ + var start_range = this.checkNumInRange(urls_coords, references[k].begin); + var end_range = this.checkNumInRange(urls_coords, references[k].end); + + if(!start_range && !end_range){ + filtered_refs.push(references[k]); + } + }catch(err){ + console.log(err); + } + } + + }else{ + filtered_refs = references; + } + const begin_end_coords = filtered_refs.map(ref => ref.begin); + filtered_refs = filtered_refs.filter(({begin}, index) => !begin_end_coords.includes(begin, index + 1)); } - references.forEach(ref => this.addTemplateResult(ref.begin, ref.end, ref.template)); + filtered_refs.forEach(ref => this.addTemplateResult(ref.begin, ref.end, ref.template)); } + trimMeMessage () { if (this.offset === 0) { // Subtract `/me ` from 3rd person messages @@ -300,6 +399,7 @@ export class RichText extends String { */ await api.trigger('beforeMessageBodyTransformed', this, { 'Synchronous': true }); + this.render_styling && this.addStyling(); this.addAnnotations(this.addMentions); this.addAnnotations(this.addHyperlinks); @@ -339,9 +439,36 @@ export class RichText extends String { * @param { Object } template - The lit TemplateResult instance */ addTemplateResult (begin, end, template) { - this.references.push({ begin, end, template }); + // if(this.references.findIndex(item => item.begin == begin && item.end == end) == -1){ + // duplicate reference not found + this.references.push({ begin, end, template }); + // } + // else{ + // // duplicate reference found + // } + } + // addHttpTemplateResult(begin, end, template){ + // const urls_meta = this.media_urls || getMediaURLsMetadata(text, local_offset).media_urls || []; + // const media_urls = getMediaURLs(urls_meta, text, full_offset); + // media_urls.forEach(media_url => + // this.httpsReferences.push({ begin, end, template }); + + // ); + // } + + + // addHttpReferences(text, local_offset){ + // const urls_meta = this.media_urls || getMediaURLsMetadata(text, local_offset).media_urls || []; + // const media_urls = getMediaURLs(urls_meta, text, full_offset); + // media_urls.forEach(media_url => { + // console.log(media_url); + // this.addHttpTemplateResult(media_url.start, media_url.end, template) + + // }); + // } + isMeCommand () { const text = this.toString(); if (!text) { @@ -368,4 +495,4 @@ export class RichText extends String { [] ); } -} +} \ No newline at end of file diff --git a/src/shared/styling.js b/src/shared/styling.js index d0467a5168..acf1ab5e25 100644 --- a/src/shared/styling.js +++ b/src/shared/styling.js @@ -10,7 +10,7 @@ import { renderStylingDirectiveBody } from 'shared/directives/styling.js'; const bracketing_directives = ['*', '_', '~', '`']; const styling_directives = [...bracketing_directives, '```', '>']; -const styling_map = { +export const styling_map = { '*': {'name': 'strong', 'type': 'span'}, '_': {'name': 'emphasis', 'type': 'span'}, '~': {'name': 'strike', 'type': 'span'}, @@ -18,6 +18,7 @@ const styling_map = { '```': {'name': 'preformatted_block', 'type': 'block'}, '>': {'name': 'quote', 'type': 'block'} }; +const https_directives = ['https']; const dont_escape = ['_', '>', '`', '~']; @@ -140,15 +141,18 @@ export function getDirectiveAndLength (text, i) { export const isQuoteDirective = (d) => ['>', '>'].includes(d); +export const isHTTPDirective = (d) => ['https'].includes(d); export function getDirectiveTemplate (d, text, offset, options) { const template = styling_templates[styling_map[d].name]; + if (isQuoteDirective(d)) { const newtext = text .replace(/\n>/g, '\n') // Don't show the directive itself .replace(/\n$/, ''); // Trim line-break at the end return template(newtext, offset, options); - } else { + } + else { return template(text, offset, options); } } @@ -161,3 +165,11 @@ export function containsDirectives (text) { } } } + +export function containsHTTPUrl (text) { + for (let i=0; i Date: Mon, 13 Jun 2022 20:50:20 -0400 Subject: [PATCH 04/12] removed redundant code from rich-text.js --- src/headless/plugins/muc/muc.js | 2 -- src/headless/utils/core.js | 2 -- src/shared/rich-text.js | 29 ++++++++--------------------- src/shared/styling.js | 16 ++-------------- 4 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/headless/plugins/muc/muc.js b/src/headless/plugins/muc/muc.js index 2dc7162815..5f8916df27 100644 --- a/src/headless/plugins/muc/muc.js +++ b/src/headless/plugins/muc/muc.js @@ -2699,8 +2699,6 @@ const ChatRoomMixin = { */ isUserMentioned (message) { const nick = this.get('nick'); - console.log("isUserMentioned(): "); - console.log(message); if (message.get('references').length) { const mentions = message .get('references') diff --git a/src/headless/utils/core.js b/src/headless/utils/core.js index 6e4b4f36b5..ea172daf79 100644 --- a/src/headless/utils/core.js +++ b/src/headless/utils/core.js @@ -108,8 +108,6 @@ u.getLongestSubstring = function (string, candidates) { */ export function prefixMentions (message) { let text = message.getMessageText(); - console.log('prefixMentions(): '); - console.log(text); (message.get('references') || []) .sort((a, b) => b.begin - a.begin) .forEach(ref => { diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index bffe62873b..297b51734b 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -3,7 +3,7 @@ import tpl_gif from 'templates/gif.js'; import tpl_image from 'templates/image.js'; import tpl_video from 'templates/video.js'; import { api } from '@converse/headless/core'; -import { containsDirectives, getDirectiveAndLength, getDirectiveTemplate, isQuoteDirective, styling_map } from './styling.js'; +import { containsDirectives, getDirectiveAndLength, getDirectiveTemplate, isQuoteDirective } from './styling.js'; import { getEmojiMarkup } from './chat/utils.js'; import { getHyperlinkTemplate } from 'utils/html.js'; import { getMediaURLs } from '@converse/headless/shared/chat/utils.js'; @@ -95,7 +95,6 @@ export class RichText extends String { this.options = options; this.payload = []; this.references = []; - this.httpsReferences = []; this.render_styling = options?.render_styling; this.show_images = options?.show_images; this.hide_media_urls = options?.hide_media_urls; @@ -270,16 +269,15 @@ export class RichText extends String { * them. */ addStyling () { + this.addAnnotations(this.addHyperlinks); + const references = []; var filtered_refs = []; var urls_coords = []; - this.addAnnotations(this.addHyperlinks); - for(var i = 0; i < this.references.length; i++){ var ending_string = this.references[i].template.strings.length; if(this.references[i].template.strings[ending_string - 1] == ""){ - var new_coords = { start: this.references[i].begin, end: this.references[i].end @@ -291,7 +289,6 @@ export class RichText extends String { const mention_ranges = this.mentions.map(m => Array.from({ 'length': Number(m.end) }, (v, i) => Number(m.begin) + i) ); - let i = 0; while (i < this.length) { if (mention_ranges.filter(r => r.includes(i)).length) { // eslint-disable-line no-loop-func @@ -300,22 +297,18 @@ export class RichText extends String { i++; continue; } - const { d, length } = getDirectiveAndLength(this, i); if (d && length) { const is_quote = isQuoteDirective(d); const end = i + length; const slice_end = is_quote ? end : end - d.length; let slice_begin = d === '```' ? i + d.length + 1 : i + d.length; - - if (is_quote && this[slice_begin] === ' ') { // Trim leading space inside codeblock slice_begin += 1; } const offset = slice_begin; const text = this.slice(slice_begin, slice_end); - references.push({ 'begin': i, 'template': getDirectiveTemplate(d, text, offset, this.options), @@ -325,21 +318,15 @@ export class RichText extends String { } i++; } - if(urls_coords.length > 0){ for(var k = 0; k < references.length; k++){ - try{ - var start_range = this.checkNumInRange(urls_coords, references[k].begin); - var end_range = this.checkNumInRange(urls_coords, references[k].end); - - if(!start_range && !end_range){ - filtered_refs.push(references[k]); - } - }catch(err){ - console.log(err); + var start_range = this.checkNumInRange(urls_coords, references[k].begin); + var end_range = this.checkNumInRange(urls_coords, references[k].end); + + if(!start_range && !end_range){ + filtered_refs.push(references[k]); } } - }else{ filtered_refs = references; } diff --git a/src/shared/styling.js b/src/shared/styling.js index acf1ab5e25..0b39b0a272 100644 --- a/src/shared/styling.js +++ b/src/shared/styling.js @@ -10,7 +10,7 @@ import { renderStylingDirectiveBody } from 'shared/directives/styling.js'; const bracketing_directives = ['*', '_', '~', '`']; const styling_directives = [...bracketing_directives, '```', '>']; -export const styling_map = { +const styling_map = { '*': {'name': 'strong', 'type': 'span'}, '_': {'name': 'emphasis', 'type': 'span'}, '~': {'name': 'strike', 'type': 'span'}, @@ -18,7 +18,6 @@ export const styling_map = { '```': {'name': 'preformatted_block', 'type': 'block'}, '>': {'name': 'quote', 'type': 'block'} }; -const https_directives = ['https']; const dont_escape = ['_', '>', '`', '~']; @@ -141,8 +140,6 @@ export function getDirectiveAndLength (text, i) { export const isQuoteDirective = (d) => ['>', '>'].includes(d); -export const isHTTPDirective = (d) => ['https'].includes(d); - export function getDirectiveTemplate (d, text, offset, options) { const template = styling_templates[styling_map[d].name]; @@ -151,8 +148,7 @@ export function getDirectiveTemplate (d, text, offset, options) { .replace(/\n>/g, '\n') // Don't show the directive itself .replace(/\n$/, ''); // Trim line-break at the end return template(newtext, offset, options); - } - else { + } else { return template(text, offset, options); } } @@ -165,11 +161,3 @@ export function containsDirectives (text) { } } } - -export function containsHTTPUrl (text) { - for (let i=0; i Date: Mon, 13 Jun 2022 20:53:37 -0400 Subject: [PATCH 05/12] Removed redundant comment --- src/shared/chat/message-body.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/chat/message-body.js b/src/shared/chat/message-body.js index 081b5a8069..0b18b07d1a 100644 --- a/src/shared/chat/message-body.js +++ b/src/shared/chat/message-body.js @@ -41,8 +41,6 @@ export default class MessageBody extends CustomElement { render () { const callback = () => this.model.collection?.trigger('rendered', this.model); const offset = 0; - // console.log("THIS.MODEL"); - // console.log(this.model); const options = { 'media_urls': this.model.get('media_urls'), 'mentions': this.model.get('references'), From 162f20e08af410e6cc00abe4dafe31b3171448b0 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 20:54:26 -0400 Subject: [PATCH 06/12] Removed redundant comment --- src/shared/components/rich-text.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/components/rich-text.js b/src/shared/components/rich-text.js index bcf0f8ab17..a8b963763c 100644 --- a/src/shared/components/rich-text.js +++ b/src/shared/components/rich-text.js @@ -64,8 +64,6 @@ export default class RichText extends CustomElement { } render () { - // console.log("components/rich-text.js this.mentions: "); - // console.log(this.mentions); const options = { embed_audio: this.embed_audio, embed_videos: this.embed_videos, From fbd5874ebfe91527174a84ccce1ba27400694b01 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 20:55:07 -0400 Subject: [PATCH 07/12] Removed redundant whitespace --- src/shared/chat/message-body.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/chat/message-body.js b/src/shared/chat/message-body.js index 0b18b07d1a..b4c7907301 100644 --- a/src/shared/chat/message-body.js +++ b/src/shared/chat/message-body.js @@ -1,4 +1,4 @@ -import 'shared/registry.js'; +import 'shared/registry.js'; import ImageModal from 'modals/image.js'; import renderRichText from 'shared/directives/rich-text.js'; import { CustomElement } from 'shared/components/element.js'; From 2ec56e799e27867d2d4574f1b162372f17588997 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 20:55:45 -0400 Subject: [PATCH 08/12] Removed redundant comments --- src/shared/directives/rich-text.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/shared/directives/rich-text.js b/src/shared/directives/rich-text.js index ab8160d855..a2edd00308 100644 --- a/src/shared/directives/rich-text.js +++ b/src/shared/directives/rich-text.js @@ -14,10 +14,6 @@ class RichTextRenderer { } async transform () { - // console.log("RichTextRenderer transform()"); - // console.log(this.text); - // console.log(this.offset); - // console.log(this.options); const text = new RichText(this.text, this.offset, this.options); try { await text.addTemplates(); From ed69e11bd41e4c2a42eabed94de2e8e4cd95c8b9 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 20:56:44 -0400 Subject: [PATCH 09/12] Removed redundant comments --- src/shared/rich-text.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index 297b51734b..abd6873fd4 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -123,8 +123,6 @@ export class RichText extends String { * offset from the start of the original message stanza's body text). */ addHyperlinks (text, local_offset) { - // this.addAnnotations(this.addHttpReferences); - const full_offset = local_offset + this.offset; const urls_meta = this.media_urls || getMediaURLsMetadata(text, local_offset).media_urls || []; const media_urls = getMediaURLs(urls_meta, text, full_offset); @@ -455,4 +453,4 @@ export class RichText extends String { [] ); } -} \ No newline at end of file +} From 09dffd82b8bcbf13744f82f9b9c5ecb343eaf6e0 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 20:59:30 -0400 Subject: [PATCH 10/12] Fixed spacing to original specifications --- src/shared/styling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/styling.js b/src/shared/styling.js index 0b39b0a272..d0467a5168 100644 --- a/src/shared/styling.js +++ b/src/shared/styling.js @@ -140,9 +140,9 @@ export function getDirectiveAndLength (text, i) { export const isQuoteDirective = (d) => ['>', '>'].includes(d); + export function getDirectiveTemplate (d, text, offset, options) { const template = styling_templates[styling_map[d].name]; - if (isQuoteDirective(d)) { const newtext = text .replace(/\n>/g, '\n') // Don't show the directive itself From c19b72a66a6c8a6597f5db99b78b792c0cce31dc Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 21:01:15 -0400 Subject: [PATCH 11/12] Fixed spacing to original specifications --- src/shared/rich-text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index abd6873fd4..a096805356 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -424,7 +424,7 @@ export class RichText extends String { * @param { Object } template - The lit TemplateResult instance */ addTemplateResult (begin, end, template) { - this.references.push({ begin, end, template }); + this.references.push({ begin, end, template }); } isMeCommand () { From 662ce1b73059e91f87eb371bf57601b466e27328 Mon Sep 17 00:00:00 2001 From: Sean Atukorala Date: Mon, 13 Jun 2022 21:15:17 -0400 Subject: [PATCH 12/12] Updated docstring --- src/shared/rich-text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/rich-text.js b/src/shared/rich-text.js index a096805356..3545522ca6 100644 --- a/src/shared/rich-text.js +++ b/src/shared/rich-text.js @@ -245,7 +245,7 @@ export class RichText extends String { * Used to obtain the nearest lower bound value for a given @param { Integer } value * For example: given @param { Array } array contaiing [23, 30, 80, 100], a @param { Integer } value = 90 would return 80 * @param { Array } array - An array containing a series a integers which are derived from @param { Array } references in `checkNumInRange(references, search_range)` - * @param { Integer } value - This is the search term which a lower bound value nearest to it will be returned by the function + * @param { Integer } value - This is the search term from which a lower bound value nearest to it will be returned by the function */ lowerBound(array, value){ let low = 0;