Skip to content
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

The complete comment system revamp #424

Open
wants to merge 75 commits into
base: master
Choose a base branch
from

Conversation

dwitterer
Copy link
Contributor

(Don't merge yet!)

I was initially going to create just a separate branch for the tests for the new hashtag system, but I ended up having all the new changes in this branch. Anyway, this pull request covers all the new functionalities and improvements for the comment system on Dwitter:

  • The "anchor annihilator", as I affectionately call it, will now remove all links from code blocks. So stuff like colour codes and URLs will not be transformed into tags - this makes hashtags more accurate, and allows users to use code blocks as a mechanism to escape mentions (u/, d/) and links
  • Long, dwitter-specific, URLs will now be "autocropped" into their shorter form upon comment submission - for example, dwitter.net/d/123 will automatically turn into d/123
  • Hashtag requirements updated to allow tags starting with digits - tags must now be preceded by a space (or start of string), and must include at least one letter; old restrictions still apply for the characters allowed in said hashtags
  • New tests were added, per request, to make sure that all the new features work correctly (I know you don't care)

NOTE: The first two bulletpoints seem to require a refresh to work, after you post a comment using them... I'm not sure if this will be the case in production, but it's not a major issue anyway. Just thought I'd let you know, so that you would know. They should show up normally for other users viewing comments.

Overall, just minor things really, but they fix many of the bugs and annoying technical issues with the current comment system, and greatly increase the accuracy of the hashtag system.

Merge in commits from lionleaf's master.
The new restrictions I added should greatly reduce the number of false-positive hashtag identifications, while obviously still keeping existing hashtags working. Also removed some redundant syntax, making the regex nicer, and making it easier to remove the "hashtags cannot start with a digit" rule if we ever decide to do that.
Makes sure there's no clickable pollutants in our code blocks
He's a tough guy, but he just needs us to clear the way for him a little bit, y'know?
Merge in commits from lionleaf's master.
Makes `make lint-python` pass successfully, where lines need to be <100 characters long.
After a discussion on Discord with @lionleaf, I am removing the 2-char minimum limit for hashtags. The problems that one-character hashtags have caused should be fixed anyway, and noone uses single-character hashtags anyway. So, as lionleaf seems to insist on having them, I am adding them back.
Enable hashtags beginning with numbers, since the space precedence check makes them safe to use now. Also make sure that those tags need to have at least one letter, to prevent senseless tags and make it more like twitter (I guess... we can always remove that very easily).
Merge in new commits from lionleaf's master
… magic links

Also works with `http(s)://` and `www.` prefixes. Fixes issue lionleaf#173 (look at the last one or two comments).
General linting clean-ups. Don't know if the wrap_content function is supposed to have 6 spaces on the left, and 4 on the right, but it ain't broke, so I won't fix it.
Just cleaning up the files as I browse through all the .py files in the /tests folder. Made it have 2 newlines before each `def`, as the linter requires us to (?), and also cleaned up some spelling and grammar issues in the long multiline comment.
Copy link
Owner

@lionleaf lionleaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress.

Thanks a lot for adding new tests! That's super helpful to avoid future errors. I added some small comments.

A few more points:

  1. I think you might have issues with a comment like This is some code: \ color: #fff` `. If that works, I'd like to see a test. Can be done in a later pull request, since it's already slightly broken.
  2. I wonder if we could enable number-only hashtags now? They caused problems with character-codes but I think that should be fixed by requiring spaces. Can be done in a separate PR

And I think I know what's causing you some issues:

  1. There is another hashtag regex when the hashtags are added to the database. Take a look at models.py line 138. (This means I would have to do a migration to update all the old hashtags to match the new system, but I can deal with that later)

  2. You mentioned you have to refresh to see the new hashtags. This is likely caused by the ordering of insert_magic_links and insert_code_blocks in get_urlized_text() from serializers.py line 43. This is how the code that makes links in the comment before you refresh the site.

If you fix 1. and 2. I think the tests will start passing.

dwitter/templatetags/insert_code_blocks.py Show resolved Hide resolved
dwitter/templatetags/insert_magic_links.py Show resolved Hide resolved
@@ -20,7 +21,7 @@ def test_insert_magic_links_replaces_user_with_valid_characters(self):
def test_insert_magic_links_bypasses_user_with_invalid_characters(self):
self.assertEqual(
'u/a1$',
'u/a1$'
insert_magic_links('u/a1$')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but now a test fails... So I have to either switch it back, or introduce a new regex test to avoid inserting anchors into partially correct usernames. I have came up with such a regex, but users would have to insert a space after the username. So I thought about allowing dots and commas after the username as well, but I don't know if it's all too good to deal with this issue like that. I said this on discord as well, but noone replied :/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with u/a1$ becoming <a href='/u/a1'>u/a1</a>$ which I believe is how it works today?

You can change this test to insert_magic_links_does_not_linkify_invalid_username_characters or something similar and change it to the way it works now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it's kind of annoying, and doesn't feel right. If a username contains invalid characters, why match it? It's invalid!

I dunno... maybe I can find a better way of handling this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can require a whitespace, end-of-line or punctuation at the end? Similar to with hashtags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, with hashtags it's whitespace or nothing, and that's before the hashtag :/... And then with endings there's the whole ordeal of what to define as punctuation, and what's just an invalid character. But as I said, I need to have a think about this.

dwitter/tests/templatetags/test_insert_magic_links.py Outdated Show resolved Hide resolved
@dwitterer
Copy link
Contributor Author

Thanks for the info. I will certainly have a look at the models.py. The refreshing thing woud be qood to fix, but I think that I'll move that onto another PR. This is already quite a large one, and minor annoyances like this are not a major priority right now. I will also have a look at the code thing you sent, but your formatting kinda messed up there, so not sure exactly what that is supposed to say. As for the number-only hashtags, the requirement for a letter kinda put itself in place, and I just kept it there, as it seems to match the way twitter hashtags work, and y'know, twitter knows their stuff when it comes to hashtags 😉 Also, number-only hashtags probably wouldn't be very meaningful anyway. Also also, wht if I make a comment saying "My dweet is #1"? I don't want the "#1" to be a hashtag!

Anyways, I have quite a lot of school work to do for the next few days, but hopefully I can have a look (and maybe finally get this PR ready) next friday/weekend :)

Thanks again for the stuff!

Also made naming of tests more consistent, and added some tests for http://, since the current autocrop regex handles those, and since it does, it's a nice thing to have. Say, for example, if someone makes a typo typing the long URL manually (new users perhaps?) or otherwise...
@dwitterer
Copy link
Contributor Author

Okay, so I fixed the formatting in that code comment of yours, and pasted it into my localhost version of dwitter. The only thing that I could find that could possibly fail is the double backticks as in `whatever `a``, and we already test for that, so I'll just ignore that for now, unless you can clarify what issue you have found.

So all I need to do now, is solve the usernames thing....

That was easy :D

@dwitterer
Copy link
Contributor Author

Okay, so I fixed all of the stuff you mentioned above, and put tests in place for the new punctuation stuff. As of right now, all d/ links, u/ links, and hashtags have to be followed by a space, end-of-string, comma, colon, semi-colon, question mark, or exclamation point. Parentheses and quotes will be added in soon to fix 2-3 more tests....

However, I kinda need your help, as half of my tests are now failing due to 'unbalanaced parentheses' in the same file, at the same place, when I haven't even touched that file... 🤔

After we fix that, we're pretty much ready to merge :D

@stianjensen
Copy link
Collaborator

dwitter/models.py Outdated Show resolved Hide resolved
@lionleaf
Copy link
Owner

Looks like I messed up github markdown in an earlier comment. Let me try again; what happens with a comment like this (today #FFFFFF would become a clickable hashtag):

This is a comment with some code: ` color:#FFFFFF;` 

Does it look ok? And I guess it might be silently added to hashtags, so even if #FFFFFF doesn't become clickable the dweet can now be found at h/FFFFFF ?

@lionleaf
Copy link
Owner

Should fix #334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants