Merge lp://staging/~kai-mast/friends/links into lp://staging/friends

Proposed by Kai Mast
Status: Merged
Merged at revision: 249
Proposed branch: lp://staging/~kai-mast/friends/links
Merge into: lp://staging/friends
Diff against target: 437 lines (+361/-17)
4 files modified
friends/protocols/twitter.py (+48/-15)
friends/tests/data/twitter-hashtags.dat (+94/-0)
friends/tests/data/twitter-multiple-links.dat (+144/-0)
friends/tests/test_twitter.py (+75/-2)
To merge this branch: bzr merge lp://staging/~kai-mast/friends/links
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Robert Bruce Park Approve
Review via email: mp+202954@code.staging.launchpad.net

Description of the change

This branch likifies mentions and hashtags. Hashtags open a link with the search in a browser. Friends has support for searches but afaik there is no way to add links to them. So this is the best we can do right now. Imo that makes tweets (especially retweets) much more interakctive.

I also fixed a problem when there are multiple links in a tweet and also added a test so this stays fixed.

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

Wow, congrats on the test coverage, that's really impressive ;-)

One thing that I'm a little bit confused about. You named a variable "urls_sorted" but I don't actually see any sorting going on there. Then you go on to use a concept of 'offset' in order to keep track of where each link should go, and I find it a bit sloppy.

What I'd like to see instead, is just iterate over urls_sorted in a sorted way, with descending values of 'begin' (eg, linkify the last URL first and progress backwards through the string). That way there's never an offset to have to worry about as the change in string length does not affect links that appear prior to the change being made.

Another (small) problem is that you used iter() in a useless way. Friends is python3-only, so dict.items() always returns an iter and your extra call to iter() doesn't do anything.

So instead it should probably look like this:

    for key, url in sorted(urls_sorted.items(), reverse=True):

And then...

    if content:
        message = ''.join([message[:begin], content, message[end:]])

Also, I'm slightly annoyed by the inconsistency between the _linkify_mention function which is nearly identical to other linkification techniques that are inlined in the larger function. I'm sure there can be a general purpose _linkify method that can be used to linkify all kinds of links, in a much more consistent and space-efficient manner (ie, fewer lines of code).

review: Needs Fixing
Revision history for this message
Kai Mast (kai-mast) wrote :

Oh okay I thought dictionaries where sorted by default (I am so used to C++ ;) )

I haven't even thought of going through the message in reverse to keep track off the offset. Good point.

Revision history for this message
Kai Mast (kai-mast) wrote :

Better?

I am not sure how to use just one linkify function because some have absolute addresses and some don't, so I now have linkify and linkify_mention, where the latter calls the first.

I also made the links use https which should be used whenever possible in my opinion.

Revision history for this message
Robert Bruce Park (robru) wrote :

This is a ton better, thank you!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Autolanding.
No commit message was specified in the merge proposal. Hit 'Add commit message' on the merge proposal web page or follow the link below. You can approve the merge proposal yourself to rerun.
https://code.launchpad.net/~kai-mast/friends/links/+merge/202954/+edit-commit-message

review: Needs Fixing (continuous-integration)
Revision history for this message
Robert Bruce Park (robru) wrote :

One thing to watch out for is that you have a ton of trailing whitespace all over. I don't like to see that in my code ;-)

Don't worry, I'm cleaning it up for this merge, but if you could start stripping trailing whitespace before committing I'd appreciate it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: