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

Add support for copying raw message. #1470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sushmey
Copy link
Collaborator

@Sushmey Sushmey commented Feb 14, 2024

What does this PR do, and why?

Adding a key to copy raw message content since manually copying text in a terminal is pretty difficult due to the bars on the sides. Implemented using preexisting copy_to_clipboard function.

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

Screenshot 2024-02-14 at 7 45 35 PM

@zulipbot zulipbot added the size: M [Automatic label added by zulipbot] label Feb 14, 2024
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.

@Sushmey This looks to work well for the most part 👍

I've left some mostly-minor feedback inline.

An alternative/follow-up to this would be to improve our popups more generally to include general & specific keys, as per #1002, so we could include c in the popup itself.

@@ -1939,14 +1939,21 @@ def __init__(

# Get rendered message header and footer
msg_box = MessageBox(message, controller.model, None)
msg_box.footer = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

This changes the existing behavior, since the footer stores footlinks and reactions in message boxes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I noticed that but it's still a widget_list that is being returned and since originally footer was an empty list in the FullRawMsgView so the earlier assertion passes so didn't need to change anything in test_init.

Adding two new assertions now to check if the widget_list element is urwid.Text and to check if the text is what it's supposed to be.

msg_box.footer = [
(
urwid.Text(
("msg_bold", "\nPress [c] to copy message to clipboard"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

For specific keys, we always want to avoid hard-coding the key in the text, and rather lookup the key name via it's symbolic name: COPY_MESSAGE.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that makes more sense! Making that change.

Comment on lines 602 to 605
"key",
{
*keys_for_command("COPY_MESSAGE"),
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this fits on one line? It's probably only the extra comma(s) that's forcing black to spread it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Changed.

msg_box.footer = [
(
urwid.Text(
("msg_bold", "\nPress [c] to copy message to clipboard"),
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 of the wording here, but including content in the text seems useful, particularly if we keep the footer and header as they are in main.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How's "Press [c] to copy raw message content to clipboard" ?

response = controller.model.fetch_raw_message_content(message["id"])

if response is None:
self.response = controller.model.fetch_raw_message_content(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.

Since we're using this more widely now, it would be useful to give it a name which is clearer - so that we don't have to return here to look up what it means. That seems to be what you do when you use it on line ~1978?

You could also consider this change to be a refactor prep commit, since you've not updated test_init.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean changing the variable name to something like self.raw_message_content?

I'll create a different refactor PR changing the variable name and then rebase this one.

docs/hotkeys.md Outdated
@@ -64,6 +64,7 @@
|View current message in browser (from message information)|<kbd>v</kbd>|
|Show/hide full rendered message (from message information)|<kbd>f</kbd>|
|Show/hide full raw message (from message information)|<kbd>r</kbd>|
|Copy message content to clipboard|<kbd>c</kbd>|
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't have any (from ...) suffix like the others, which could imply that it works just when a message is selected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Missed that text. Adding (from message information). Or should I add something like (from raw message view)? Although it might be confusing for new users since they might not know where raw message view is.

@neiljp neiljp added missing feature: user A missing feature for all users, present in another Zulip client PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Feb 22, 2024
Using c as the key to copy messages to clipboard.

Adding c to be excluded since c is already being used in same group.
@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: M [Automatic label added by zulipbot] labels Feb 22, 2024
Adding a feature to copy the text you see in the raw msg popup.

Added hint text in the popup.

Updated tests for the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing feature: user A missing feature for all users, present in another Zulip client PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants