-
-
Notifications
You must be signed in to change notification settings - Fork 775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for Issue #2857: Text Styling Should Not Be Applied In The Middle Of URLs #2918
Open
ShehanAT
wants to merge
15
commits into
conversejs:master
Choose a base branch
from
ShehanAT:text-styling-middle-url-ShehanAT
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
27345bd
added fixes for Issue #2857
ShehanAT 19f25bc
added changelog entry covering fixes for Issue #2857
ShehanAT c28df0e
implemented new fix based on jcbrand's advice
ShehanAT 40e284c
merged with remote
ShehanAT fc844dc
Merge branch 'master' of https://github.com/conversejs/converse.js in…
ShehanAT 9dc2563
removed redundant code from rich-text.js
ShehanAT d02ed40
Removed redundant comment
ShehanAT 162f20e
Removed redundant comment
ShehanAT fbd5874
Removed redundant whitespace
ShehanAT 2ec56e7
Removed redundant comments
ShehanAT ed69e11
Removed redundant comments
ShehanAT 09dffd8
Fixed spacing to original specifications
ShehanAT c19b72a
Fixed spacing to original specifications
ShehanAT 662ce1b
Updated docstring
ShehanAT f481471
Merge branch 'master' into text-styling-middle-url-ShehanAT
ShehanAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time and making this pull request.
The above fix isn't sufficient because the text is not guaranteed to be only a URL. There could be URLs anywhere in the text, not just at the start.
So for example AFAICT your fix wouldn't work on this text:
Here is the link I wanted to send you: https://nitter.kavin.rocks/_MG_/status/1506109152665382920
It's great that you're adding tests, so now you can add a test for the message above, check whether it passes and if it doesn't you can improve the code until it does.
For a better solution, take a look at how
@
mentions are ignored when looking for styled text.See here:
converse.js/src/shared/rich-text.js
Line 218 in 1ad6de2
Similar to how the
mention_ranges
array is used to avoid styling mentions, we need to know where the URLs are so that we can avoid them as well.Looks like the
urls_meta
array has the necessary information (similarly tomention_ranges
).See here:
converse.js/src/shared/rich-text.js
Line 127 in 1ad6de2
So, in
addStyling
, you can computeurls_meta
and then use that to avoid styling URLs, similarly to how we avoid styling mentions.You can probably even combine both URLs and mentions into one array of ranges of text which shouldn't be styled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I see what you mean.
Do you happen to know where
this.model.get('references')
is being populated?I ask because
this.mentions
is populated bythis.model.get('references')
as seen insrc/shared/chat/message-body.js line 48
but I'm not finding where thereferences
field is being populated...If I can find out how
references
are being identified, I can make a similar implementation for HTTP UrlsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For incoming messages, the references are extracted when the stanza is parsed:
converse.js/src/headless/plugins/muc/parsers.js
Line 225 in a228cf2
For outgoing messages it's done somewhere else, I'm not sure where right now. However, I don't think this is relevant to fixing this bug.
The
getMediaURLsMetadata
function does the work for you of getting the URLs and you can call that function insideaddStyling
in order to get a list of URLs to ignore.