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] Add support for viewing a message in the web browser #698

Closed
wants to merge 6 commits into from

Conversation

preetmishra
Copy link
Member

@preetmishra preetmishra commented Jun 19, 2020

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 or pm-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.

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Jun 19, 2020
@neiljp
Copy link
Collaborator

neiljp commented Jun 19, 2020

@preetmishra We discussed this on czo, but let me know if you need more specific feedback.

@preetmishra
Copy link
Member Author

@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.

@preetmishra preetmishra changed the title Add support for viewing a messsage in the web browser Add support for viewing a message in the web browser Jun 23, 2020
@neiljp neiljp added the PR needs review PR requires feedback to proceed label Jun 23, 2020
@zulipbot
Copy link
Member

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 git commit --amend in your command line client to amend your commit message description with Fixes #452..

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!

@preetmishra
Copy link
Member Author

Updated to resolve conflicts.

@preetmishra
Copy link
Member Author

Updated to resolve conflicts.

@preetmishra preetmishra marked this pull request as ready for review August 6, 2020 18:07
@neiljp neiljp added this to the Next Release milestone Aug 16, 2020
@preetmishra
Copy link
Member Author

Updated to resolve conflicts.

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 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.

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)
Copy link
Collaborator

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'])
Copy link
Collaborator

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?

Comment on lines +292 to +373
if (not MACOS and not WSL and not os.environ.get('DISPLAY')
and os.environ.get('TERM')):
Copy link
Collaborator

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?

@@ -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:
Copy link
Collaborator

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?

Comment on lines +304 to +371
# Truncate extra '/' from the server url.
self.url = near_message_url(self.model.server_url[:-1], message)
Copy link
Collaborator

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)
Copy link
Collaborator

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:
Copy link
Collaborator

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?

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Aug 31, 2020
@preetmishra preetmishra changed the title Add support for viewing a message in the web browser [WIP] Add support for viewing a message in the web browser Sep 2, 2020
@neiljp neiljp modified the milestones: 0.6.0, Release after next 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.

@zee-bit
Copy link
Member

zee-bit commented Mar 24, 2021

@preetmishra We recently merged #854, which centralizes the logic of generating near_message_url() to a new module server_url.py(along with the tests in a corresponding test_* file). This should simplify this PR to a great extent. :)

(Let me know if you are busy and want me to take this further)

@preetmishra
Copy link
Member Author

@zee-bit, thanks for the update! I will update the PR soon.

punchagan and others added 5 commits April 4, 2021 14:27
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.
@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: XL [Automatic label added by zulipbot] labels Apr 4, 2021
@preetmishra
Copy link
Member Author

@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!

@neiljp
Copy link
Collaborator

neiljp commented Jun 11, 2021

@preetmishra As you know this was replaced by the now-merged #991 so I'm closing this 🎉

@neiljp neiljp closed this Jun 11, 2021
@neiljp neiljp added the enhancement New feature or request label Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has conflicts PR blocks other PR size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TRACKING: Message rendering bugs/enhancements
5 participants