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

Handle topic links in message info view #867

Closed
wants to merge 5 commits into from

Conversation

Ezio-Sarthak
Copy link
Member

@Ezio-Sarthak Ezio-Sarthak commented Jan 6, 2021

This PR is a headstart in handling Topic links in a stream topic.

Commit flow:

  • Generate link buttons in message info view via a static method (Refactor).
  • Add API return types for new and old topic links' responses.
  • Convert message responses to support modern formats (in general) via a model helper (Refactor).
  • Topic links stored by parsing into OrderedDict (like message links).
  • Topic links appended in the message info view.

Fixes #709.

View:
Topic links

@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] enhancement New feature or request labels Jan 6, 2021
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 4 times, most recently from 9420e4a to e639e97 Compare January 6, 2021 15:56
@neiljp neiljp added the PR needs review PR requires feedback to proceed label Jan 6, 2021
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 4 times, most recently from 7ef5fb0 to 99dc58c Compare January 16, 2021 16:23
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.

@Ezio-Sarthak Thanks for looking into this - when we have the open-in-browser feature this will be really helpful 👍

This works OK for me on czo but I think it needs generalizing for Zulip 2.1+, and could be simpler both in code and possibly in commit structure too. Let me know if you have any questions.

zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
@@ -222,7 +222,7 @@ def unicode_emojis():
'stream_id': 205,
'subject': 'Test',
'reactions': [],
'subject_links': [],
'topic_links': [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that we aim to support Zulip 2.1+, which is prior to feature level 1, so we need to support subject_links as well as topic_links.

Given the text below, you might consider whether we can refactor more tests to use the same message templates - so we don't need to make as many changes in multiple places.

Copy link
Member Author

@Ezio-Sarthak Ezio-Sarthak Jan 19, 2021

Choose a reason for hiding this comment

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

For now, I've added topic_links wherever we have subject_links so that there is no version support issue. I've done this keeping in mind my reply to the comment below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Both are never present together, unless there was some overlap in feature levels? We could potentially make these fixtures over feature-level, at the risk of getting more complex.

Copy link
Member Author

@Ezio-Sarthak Ezio-Sarthak Feb 17, 2021

Choose a reason for hiding this comment

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

Makes sense. My suggestion would be that we let subject_links stay untouched for now in the tests and fixtures. We're validating for both *_links parameter in the helper of later commit, in such a way that only one could possibly exist (I don't know why I didn't consider that for this commit 😆)

(By untouched I'm not considering my below comment regarding PMs and group PMs)

return
for link in self.message['topic_links']:
self.topic_links[link] = (
'Link', len(self.topic_links) + 1, True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not having the link text available is a little frustrating ☹️

Perhaps the backend could be improved in this regard, as at least for linkifiers like we regularly use, we know there is "link text", like #T867 here.

For now could we maybe special-case the view for empty link text and put it on one line?

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Jan 17, 2021
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 4 times, most recently from e1446a8 to f32f1bd Compare January 23, 2021 06:37
Base automatically changed from master to main January 30, 2021 20:31
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.

@Ezio-Sarthak I just realized I had an outstanding set of responses to this PR so sending them now - let me know if they still make sense 👍

zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
@@ -246,7 +247,6 @@ def unicode_emojis():
'reactions': [],
'type': 'private',
'avatar_url': 'dummy_avatar_url',
'subject_links': [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just checked a connection with czo and it seems PMs send topic_links?

Copy link
Member Author

@Ezio-Sarthak Ezio-Sarthak Feb 17, 2021

Choose a reason for hiding this comment

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

Ideally, this shouldn't be the case 🤔, as there's no such 'topic' in PMs (or group PMs) as you mentioned earlier. This could be potentially filed in the main repo in any case, if not done already.

EDIT: Looking through a successful JSON response for get_messages API, I see the subject parameter is said to be present only for stream messages but is present in form of an empty string for PMs too. Although an empty string/list results in a fallacy of the conditional statements, I feel they sort of mislead a user looking over the API for the first time :)

Since we should sync with our API in any case, I'll let subject links remain there for now if that seems reasonable.

@@ -222,7 +222,7 @@ def unicode_emojis():
'stream_id': 205,
'subject': 'Test',
'reactions': [],
'subject_links': [],
'topic_links': [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both are never present together, unless there was some overlap in feature levels? We could potentially make these fixtures over feature-level, at the risk of getting more complex.

zulipterminal/ui_tools/boxes.py Outdated Show resolved Hide resolved
@Ezio-Sarthak
Copy link
Member Author

Ezio-Sarthak commented Feb 17, 2021

@neiljp Thanks for the review! Your outstanding comments made us discuss client + server related aspects of the PR in detail :)

The motive of this PR would get complete potentially once @sumanthvrao's PR zulip/zulip#17124 gets merged. Till then, we might continue resolving refactor/implementation/code related aspects 😅

EDIT: Upated the PR (after rebasing some commits from upstream). Seems like there's a drop in test coverage. I'll add more tests in the coming iterations 👍

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.

@Ezio-Sarthak Thanks for continuing to work on this 👍

This looks to work fine, though I do think that having a "message modernization" method when receiving messages will probably be useful in general - for example with 'subject' and 'topic' themselves too! Having an accessor method is generally good over just accessing the data, but the UI already has the Message right now so get_topic_links isn't really an accessor so much as asking the model to simplify the data on-demand.

zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/views.py Outdated Show resolved Hide resolved
zulipterminal/api_types.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 2 times, most recently from 374476a to 1a91ba5 Compare February 22, 2021 10:38
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.

@Ezio-Sarthak The modernization pass makes things cleaner 👍

@@ -1213,6 +1213,7 @@ def __init__(self, controller: Any, msg: Message, title: str,
time_mentions: List[Tuple[str, str]],
) -> None:
self.msg = msg
self.controller = controller
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 seem connected?

Comment on lines 1264 to 1266
# slice_index = Number of labels before links + 1 newline
# + 1 '<Any> Links' category label.
slice_index = len(msg_info[0][1]) + 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this have any application outside of the conditional below?

Comment on lines 484 to 487
# Convert message reponse to the modern format
response['messages'] = self.modernize_message_response(
response['messages']
)
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 the comment is necessary - it duplicates the function name? :)

Note that we need to call this for all new messages, both on explicit message fetch and for message events.

Comment on lines 616 to 622
[{'subject_links': ['www.foo1.com', 'www.bar1.com']}],
[{'topic_links': ['www.foo1.com', 'www.bar1.com']}]), (
[{'topic_links': ['www.foo2.com', 'www.bar2.com']}],
[{'topic_links': ['www.foo2.com', 'www.bar2.com']}]),
], ids=[
'param_old_server_release',
'param_new_server_release',
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may be worth adding some empty cases too? The code should already handle it, and the test will then specify that it should.

Copy link
Member Author

Choose a reason for hiding this comment

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

By empty do you mean list() or None? We don't have a None value response for topic_links from API call anyways. That said I'll add some empty list tests. Thanks for pointing out :)

@@ -728,6 +729,19 @@ def need_recipient_header(self) -> bool:
else:
raise RuntimeError("Invalid message type")

def _set_topic_links(self) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you expect to expand upon this in future or call it in more than one place? If not then right now this appears to be a dict comprehension, so I think we can have it inline at the one call site?

Comment on lines 1282 to 1283
if topic_links:
slice_index += (len(topic_links) + 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this simplified if the slice_index is in the conditional in the earlier commit?

@staticmethod
def modernize_message_response(response: List[Message]) -> List[Message]:
"""
Cleans recieved messages into the modern format
Copy link
Collaborator

Choose a reason for hiding this comment

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

This docstring could be more helpful - why is it useful/helpful?

Also "receive".

@Ezio-Sarthak
Copy link
Member Author

@zulipbot add "PR needs review"

@zulipbot zulipbot added the PR needs review PR requires feedback to proceed label Feb 26, 2021
@Ezio-Sarthak
Copy link
Member Author

@zulipbot remove "PR awaiting update"

@zulipbot zulipbot removed the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Feb 26, 2021
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 2 times, most recently from 7074d1e to 40fa0f2 Compare March 27, 2021 16:09
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 3 times, most recently from 8281feb to 16d13df Compare March 31, 2021 06:53
@Ezio-Sarthak Ezio-Sarthak force-pushed the handle-topic-links branch 2 times, most recently from a3a1224 to 06014d9 Compare April 8, 2021 03:13
`topic_links` param is new in Zulip 3.0 (feature level 1) release.
Previously it was called as `subject_links`.

Successful `topic_links` response earlier vs now:
 * earlier: ['www.link1.com']
 * now:     [{'url': 'www.link1.com', 'text': 'My link']}
This commit:
 * adds a 'message modernization' helper, that converts old
   release params and their corresponding responses (in general)
   to modern messages format. This could be extended to other
   message responses potentially in future.
 * hooks the helper to suitable model methods/event listeners.

Helper: Model.modernize_message_response()

Test added.
This commit:
- sets the OrderedDict of topic links in a message.
  (using the new modernized `topic_links` response)
- passes argument topic links in suitable calls.

Tests updated.
This commit adds a static method to create link buttons in message
information popup.

Tests added.
This is a wrapper commit that appends topic links in message info
view (if present). If the link text is empty, the link is appended
in a single line.

Tests amended.
Fixes zulip#709.
@neiljp neiljp added this to the Next Release milestone Apr 8, 2021
@neiljp
Copy link
Collaborator

neiljp commented Apr 8, 2021

@Ezio-Sarthak Thanks for this! I just merged with the remaining few changes left over after the last back and forth as discussed 🎉
(mainly removing the need for .keys() on a dict and simplifying some text/comments)

@neiljp neiljp closed this Apr 8, 2021
@neiljp neiljp added missing feature: user A missing feature for all users, present in another Zulip client and removed enhancement New feature or request PR needs review PR requires feedback to proceed labels Feb 28, 2022
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 size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle topic links
3 participants