-
-
Notifications
You must be signed in to change notification settings - Fork 257
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] Add support for viewing a message in the web browser #698
Conversation
@preetmishra We discussed this on czo, but let me know if you need more specific feedback. |
7efdafd
to
6657f4d
Compare
@neiljp I have updated the PR based on your suggestions on CZO. 👍 I have split the commit from the original PR into three, without any alternations, and added my changes into separate commits. I will proceed to work on other enhancements that we discussed once the commit structure looks good to you. |
6657f4d
to
5316996
Compare
Hello @preetmishra, it seems like you have referenced #452 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 An example of a correctly-formatted commit:
Thank you for your contributions to Zulip! |
Updated to resolve conflicts. |
5316996
to
aa51e10
Compare
Updated to resolve conflicts. |
aa51e10
to
3912780
Compare
Updated to resolve conflicts. |
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.
@preetmishra Thanks for continuing to build on @punchagan 's work 👍
I've left come feedback inline, but we'll definitely want to do a solid review before final merge to ensure our URL opening is secure.
zulipterminal/core.py
Outdated
and not os.environ.get('DISPLAY') and os.environ.get('TERM')): | ||
# Don't try to open web browser if running without a GUI | ||
return | ||
webbrowser.open(url) |
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.
This can raise an exception?
@@ -978,6 +978,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |||
elif is_command_key('MSG_INFO', key): | |||
self.model.controller.show_msg_info(self.message, | |||
self.message_links) | |||
elif is_command_key('VIEW_IN_BROWSER', key): | |||
self.model.controller.view_in_browser(self.message['id']) |
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.
If this fails (exception, unsupported environment, etc), could we let the user know?
if (not MACOS and not WSL and not os.environ.get('DISPLAY') | ||
and os.environ.get('TERM')): |
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.
Our platform code relies on only one of the platforms being set; we definitely want to improve that handling (see #791), but we should probably be able to rely on the 'other' option being set for now, ie LINUX
.
In the more general sense, the webbrowser module can run terminal browsers, so it would be interesting to see how DISPLAY-less systems handle that. Another aspect is whether graphical non-X11 systems set DISPLAY meaningfully?
Did you mean to capitalize the commit title?
zulipterminal/helper.py
Outdated
@@ -666,3 +667,63 @@ def suppress_output() -> Iterator[None]: | |||
finally: | |||
os.dup2(out, 1) | |||
os.dup2(err, 2) | |||
|
|||
|
|||
def hash_util_encode(string: str) -> str: |
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.
Let's use a different file for these, since we could combine these with the URL deconstruction too and/or put them into the API repo like that other method in future?
# Truncate extra '/' from the server url. | ||
self.url = near_message_url(self.model.server_url[:-1], message) |
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.
It's good to use the pre-existing code here, though using urljoin
in the new code would mean we don't need to worry about this. I'm guessing the server code avoids this since it knows the url exactly and relies on tests, which we should too really :)
if (not MACOS and not WSL and not os.environ.get('DISPLAY') | ||
and os.environ.get('TERM')): | ||
# Don't try to open web browser if running without a GUI | ||
return | ||
with suppress_output(): | ||
# Suppress anything on stdout or stderr when opening the browser | ||
webbrowser.open(url) | ||
webbrowser.open(self.url) |
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.
Why do we need the self
?
@@ -298,15 +300,16 @@ def show_all_mentions(self, button: Any) -> None: | |||
anchor=None, | |||
mentioned=True) | |||
|
|||
def view_in_browser(self, message_id: int) -> None: | |||
url = '{}#narrow/near/{}'.format(self.model.server_url, message_id) | |||
def view_in_browser(self, message: Message) -> None: |
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.
This change breaks the other use of this method - but no tests break?
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 |
@preetmishra We recently merged #854, which centralizes the logic of generating (Let me know if you are busy and want me to take this further) |
@zee-bit, thanks for the update! I will update the PR soon. |
This adds view_in_browser to add support for viewing any message in the web browser. For now, the message is always opened in the 'All messages' narrow. A message can be viewed in the browser by pressing VIEW_IN_BROWSER key(s) directly. Test added.
This makes MsgInfoView handle VIEW_IN_BROWSER keypress in order to avoid too many/unintended triggers. Tests amended and added.
This improves view_in_browser() to open messages in the exact/topic narrow for streams and in the pm-with narrow for PMs and huddles. Tests amended.
3912780
to
584c94e
Compare
@zee-bit Hey! I am a bit busy with work. However, I rebased my local branch onto master. Feel free to take it further. Best of luck! |
@preetmishra As you know this was replaced by the now-merged #991 so I'm closing this 🎉 |
Thanks to @punchagan for the initial work in #397. 👍
Unlike the original PR, which narrowed every message to All Messages in the web app, this opens a message in
stream/topic/near
if it belongs to a stream orpm-with/near
narrow if it belongs to a PM/huddle (see discussion).The original commit has been split to facilitate reviews. Moreover, the test has been improved based on @neiljp's feedback on the original PR.
The logic for generating near message URLs has been borrowed from Zulip's
zerver/lib/url_encoding.py
.Partially fixes #452.