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

[WIP] Handle media links #740

Closed
wants to merge 5 commits into from

Conversation

preetmishra
Copy link
Member

@preetmishra preetmishra commented Jul 25, 2020

Thanks to @amanagr for his initial work in #359. 👍

The PR extracts a few common elements from the PR but has changes to make the function compatible with MessageLinkButton.

Commits

  • The first commit is cherry-picked from Handle internal links #708.
  • The second commit is from WIP: Support displaying of images in msg in the default viewer. #359 with a few amendments that were necessary to make it work with MessageLinkButton.
  • The third commit integrates the introduced function in MesssageLinkButton to handle media links.
  • The fourth commit makes open_media asynch and shows downloading updates in the footer.
  • The fifth commit is a refactor that extracts PopUpConfirmationView instantiation for its subsequent commit where it is used in open_media.

Potential follow-up

  • Skip downloading existing media.

I would greatly appreciate any early feedback and bug/caveats report.

Partially fixes #764.

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Jul 25, 2020
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels Jul 31, 2020
@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Jul 31, 2020
@preetmishra preetmishra changed the title [WIP] Handle media links Handle media links Jul 31, 2020
@preetmishra preetmishra force-pushed the feat-handle-images branch 2 times, most recently from 83586a7 to 6c60a48 Compare August 6, 2020 17:19
zulipterminal/helper.py Outdated Show resolved Hide resolved
@preetmishra preetmishra marked this pull request as ready for review August 6, 2020 17:37
@preetmishra preetmishra mentioned this pull request Aug 6, 2020
4 tasks
@preetmishra preetmishra changed the title Handle media links [AWAITING] Handle media links Aug 9, 2020
@preetmishra preetmishra removed the PR needs review PR requires feedback to proceed label Aug 14, 2020
@preetmishra preetmishra changed the title [AWAITING] Handle media links [WIP] Handle media links Aug 16, 2020
@preetmishra preetmishra force-pushed the feat-handle-images branch 2 times, most recently from dac7a73 to c79d297 Compare August 22, 2020 15:17
@preetmishra preetmishra changed the title [WIP] Handle media links Handle media links Aug 22, 2020
@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Aug 22, 2020
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@preetmishra Thanks for working on this and pushing this forward 👍 We may be able to merge the core commits quickly and leave the UI tuning for later PRs or merged later from this PR.

zulipterminal/helper.py Outdated Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
tests/helper/test_helper.py Outdated Show resolved Hide resolved
tests/helper/test_helper.py Outdated Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
zulipterminal/core.py Outdated Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Aug 29, 2020
zulipterminal/helper.py Outdated Show resolved Hide resolved
@preetmishra preetmishra changed the title Handle media links [WIP] Handle media links Aug 30, 2020
@preetmishra
Copy link
Member Author

@andersk, @neiljp Thanks for the review. I have updated the pull request to use the safer NamedTemporaryFile and also incorporated the other in-line suggestions.

Re UI tuning, agreed; the pull request only has a minimal downloading setup. We could follow up on this with an extended view separately.

@preetmishra preetmishra changed the title [WIP] Handle media links Handle media links Sep 7, 2020
@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Sep 7, 2020
The parameter is useful for prompts that have long descriptions.

Used 'center' location for show_media_confirmation_popup().
@zulipbot
Copy link
Member

Hello @preetmishra, it seems like you have referenced #764 in your pull request description, but you have not referenced them in your commit message description(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged.

Please run git commit --amend in your command line client to amend your commit message description with Fixes #764..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

Thank you for your contributions to Zulip!

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@preetmishra The latest conflict is small, and I wanted to get this in soon if we can - having just tested it again it seems to work fine, and it'll be great to have merged 👍

It would be good if we could keep the UI out of the helper code, which may require a little restructuring of the control flow but should be fairly straightforward.

@amanagr Could you (or a delegated WSL contributor) check the feasibility of explorer on WSL, as used in this PR?

@andersk Do you have further thoughts or concerns here?

Comment on lines +688 to +696
error = [
' The command ', ('bold', command), ' did not run successfully'
'. Exited with ', ('bold', str(exit_status)),
]
except FileNotFoundError:
error = [' The command ', ('bold', command), ' could not be found']

if error:
controller.view.set_footer_text(error, duration=3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep the UI-centric parts out of helper.py?

Comment on lines +669 to +674
if LINUX:
command = 'xdg-open'
elif WSL:
command = 'explorer' # Needs testing.
elif MACOS:
command = 'open'
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: It would be useful if the user was able to know what the file was going to be opened with in the popup (see other comment)

Comment on lines +305 to +306
if isinstance(self.controller.loop.widget, urwid.Overlay):
self.controller.exit_popup()
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this check avoid? I know you've used it elsewhere, but I don't remember what the conclusion was - can we discuss and then maybe add a comment. Does it belong in exit_popup?

Copy link
Member

Choose a reason for hiding this comment

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

@preetmishra could you elaborate this?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Ezio-Sarthak The pop-ups open in an urwid Overlay. This check is to make sure exit_popup is only called when an Overlay exist.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see that now. If I avoid that check, there is some unwanted synchronous behavior in footer and popup, if that makes any sense.

Comment on lines +668 to +672
controller.view.set_footer_text([
' Downloading ', ('bold', media_name),
])
controller.view.set_footer_text([' Downloaded ', ('bold', media_name)],
duration=3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this will end up needing it's own commit, but perhaps make these callbacks to keep the UI separate in any case?

Copy link
Member

Choose a reason for hiding this comment

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

Now that we have report_* methods, would it be OK to use here?

Comment on lines +180 to +182
'Your requested media has been downloaded at ',
('bold', media_path),
'. Do you want to view it?'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the length of the download URLs for some files, this might well benefit from more vertical spacing, eg.

Your requested media has been downloaded to:
<filename>

Do you want the application to open it with <tool>?

@@ -678,7 +678,7 @@ def process_media(controller: Any, media_link: str) -> None:
elif MACOS:
command = 'open'

open_media(controller, command, media_path)
controller.show_media_confirmation_popup(open_media, command, media_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing you're trying to synchronize the asynch download terminating?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if I fully understood your comment, but I think the callback would be working fine in any case?

@@ -1006,9 +1006,13 @@ def __init__(self, controller: Any, title: str) -> None:
super().__init__(controller, widgets, 'HELP', popup_width, title)


PopUpConfirmationViewLocation = Literal['top-left', 'center']
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this comment should go before the previous one, as there is nowhere near enough space in the top-left for showing the download information :)

Copy link
Member

Choose a reason for hiding this comment

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

You mean commit?

@preetmishra preetmishra changed the title Handle media links [WIP] Handle media links Nov 23, 2020
@amanagr
Copy link
Member

amanagr commented Nov 23, 2020

(Sorry I no longer have access to WSL)

@neiljp
Copy link
Collaborator

neiljp commented Dec 12, 2020

It may be better to use os.startfile on WSL? This still needs testing/exploration, since potentially the appropriate WSL version has xdg features we can use in any case?

@preetmishra preetmishra removed the PR needs review PR requires feedback to proceed label Jan 17, 2021
@neiljp neiljp added this to the Release after next milestone Jan 28, 2021
Base automatically changed from master to main January 30, 2021 20:30
@zulipbot
Copy link
Member

Heads up @preetmishra, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

@neiljp
Copy link
Collaborator

neiljp commented May 16, 2022

The followup to this was merged with slight adjustments in #1223 🎉

Thanks @amanagr, @preetmishra and @Ezio-Sarthak 👍

@neiljp neiljp closed this May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TRACKING: Handle message links
6 participants