-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Conversation
9420e4a
to
e639e97
Compare
7ef5fb0
to
99dc58c
Compare
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.
@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.
tests/conftest.py
Outdated
@@ -222,7 +222,7 @@ def unicode_emojis(): | |||
'stream_id': 205, | |||
'subject': 'Test', | |||
'reactions': [], | |||
'subject_links': [], | |||
'topic_links': [], |
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.
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.
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.
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.
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.
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.
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.
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)
zulipterminal/ui_tools/boxes.py
Outdated
return | ||
for link in self.message['topic_links']: | ||
self.topic_links[link] = ( | ||
'Link', len(self.topic_links) + 1, True |
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.
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?
e1446a8
to
f32f1bd
Compare
f32f1bd
to
5762ed7
Compare
5762ed7
to
a4e9f5f
Compare
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.
@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 👍
tests/conftest.py
Outdated
@@ -246,7 +247,6 @@ def unicode_emojis(): | |||
'reactions': [], | |||
'type': 'private', | |||
'avatar_url': 'dummy_avatar_url', | |||
'subject_links': [], |
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.
I just checked a connection with czo and it seems PMs send topic_links?
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.
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.
tests/conftest.py
Outdated
@@ -222,7 +222,7 @@ def unicode_emojis(): | |||
'stream_id': 205, | |||
'subject': 'Test', | |||
'reactions': [], | |||
'subject_links': [], | |||
'topic_links': [], |
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.
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.
@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 👍 |
a4e9f5f
to
d0251c4
Compare
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.
@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.
374476a
to
1a91ba5
Compare
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.
@Ezio-Sarthak The modernization pass makes things cleaner 👍
zulipterminal/ui_tools/views.py
Outdated
@@ -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 |
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 doesn't seem connected?
zulipterminal/ui_tools/views.py
Outdated
# slice_index = Number of labels before links + 1 newline | ||
# + 1 '<Any> Links' category label. | ||
slice_index = len(msg_info[0][1]) + 2 |
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.
Does this have any application outside of the conditional below?
zulipterminal/model.py
Outdated
# Convert message reponse to the modern format | ||
response['messages'] = self.modernize_message_response( | ||
response['messages'] | ||
) |
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.
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.
tests/model/test_model.py
Outdated
[{'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', |
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 may be worth adding some empty cases too? The code should already handle it, and the test will then specify that it should.
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.
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 :)
zulipterminal/ui_tools/boxes.py
Outdated
@@ -728,6 +729,19 @@ def need_recipient_header(self) -> bool: | |||
else: | |||
raise RuntimeError("Invalid message type") | |||
|
|||
def _set_topic_links(self) -> 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.
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?
zulipterminal/ui_tools/views.py
Outdated
if topic_links: | ||
slice_index += (len(topic_links) + 2) |
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.
Is this simplified if the slice_index is in the conditional in the earlier commit?
zulipterminal/model.py
Outdated
@staticmethod | ||
def modernize_message_response(response: List[Message]) -> List[Message]: | ||
""" | ||
Cleans recieved messages into the modern format |
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 docstring could be more helpful - why is it useful/helpful?
Also "receive".
1a91ba5
to
1bee412
Compare
@zulipbot add "PR needs review" |
@zulipbot remove "PR awaiting update" |
1bee412
to
5446e08
Compare
5446e08
to
887cc18
Compare
7074d1e
to
40fa0f2
Compare
8281feb
to
16d13df
Compare
a3a1224
to
06014d9
Compare
`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.
06014d9
to
fb6e5d2
Compare
@Ezio-Sarthak Thanks for this! I just merged with the remaining few changes left over after the last back and forth as discussed 🎉 |
This PR is a headstart in handling Topic links in a stream topic.
Commit flow:
OrderedDict
(like message links).Fixes #709.
View: