Skip to content

Internal_link: Add ApiIsNarrow. #869

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

Merged
merged 4 commits into from
Aug 14, 2024
Merged

Internal_link: Add ApiIsNarrow. #869

merged 4 commits into from
Aug 14, 2024

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Aug 6, 2024

Prep work for #251.

@PIG208 PIG208 force-pushed the is-narrow branch 3 times, most recently from aff00b9 to 1c1d7eb Compare August 7, 2024 05:57
@PIG208
Copy link
Member Author

PIG208 commented Aug 7, 2024

Should be ready for review now.

@PIG208 PIG208 changed the title WIP Add ApiIsNarrow. Internal_links Add ApiIsNarrow. Aug 7, 2024
@PIG208 PIG208 changed the title Internal_links Add ApiIsNarrow. Internal_links: Add ApiIsNarrow. Aug 7, 2024
@PIG208 PIG208 changed the title Internal_links: Add ApiIsNarrow. Internal_link: Add ApiIsNarrow. Aug 7, 2024
@PIG208 PIG208 marked this pull request as ready for review August 7, 2024 05:59
@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Aug 7, 2024
@PIG208 PIG208 requested a review from chrisbobbe August 7, 2024 05:59
@PIG208 PIG208 added the a-api Implementing specific parts of the Zulip server API label Aug 7, 2024
@chrisbobbe
Copy link
Collaborator

Thanks, LGTM! Over to Greg for his review.

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Aug 7, 2024
@PIG208
Copy link
Member Author

PIG208 commented Aug 8, 2024

Extracted a bug fix to make Add generic support for is operands nfc.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks for doing this refactor! Small comments.

@@ -1,3 +1,5 @@
import '../../model/internal_link.dart';
Copy link
Member

Choose a reason for hiding this comment

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

Generally let's avoid importing in lib/api/ from other parts of the code — I'd like to think of that subtree as a Zulip API binding layer, such that if we wanted to we could easily split it out as its own Dart package.

This is for IsOperand, right? That's part of this API (it's part of https://zulip.com/api/construct-narrow ), so let's just put its definition here in this file.

Comment on lines 122 to 124
@override final String operand;

class ApiNarrowIsUnread extends ApiNarrowElement {
@override String get operator => 'is';
@override String get operand => 'unread';
ApiNarrowIs(IsOperand operand, {super.negated}) : operand = operand.toString();
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand this paragraph:

We convert the IsOperand value into a String when constructing
ApiNarrowIs, so that we don't need to mingle with
ApiNarrowElement.toJson to take care of the enum.

What would happen if we had this class store the enum?

Copy link
Member Author

@PIG208 PIG208 Aug 12, 2024

Choose a reason for hiding this comment

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

Testing with that again, I think I was mistaken that we needed special handling for ApiNarrowElement.toJson to support the use of the enum field, but actually the fix is to just provide a toJson method on IsOperand.

Comment on lines 315 to 316
dm,
private, // This is deprecated in FL 177 and equivalent to [dm].
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dm,
private, // This is deprecated in FL 177 and equivalent to [dm].
dm, // TODO(server-7) new in FL 177
private, // TODO(server-7) deprecated in FL 177, equivalent to [dm]

The TODO(server-N) format will help us spot in the future that we can drop private.

For the newly-introduced value, having a comment puts us on guard to not try to use it with old servers. Then we need a TODO-server comment to remind us to delete that warning comment… so it may as well be one line that does both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Somewhat related: how do we deal with deprecated API values? Do we still need to support them post server-7, until they are fully removed in a future version?

Copy link
Member

Choose a reason for hiding this comment

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

When it comes to links, we'll want to accept the old forms forever (as will web). People will have put links to Zulip in all sorts of external places we can't update — for example in GitHub comments, for Zulip users who use GitHub like we do — and so we should keep those links working.

But once we stop supporting the old server versions that lack the new forms, we can stop ever generating the old forms. So for example ApiNarrowDm and its two subclasses will simplify back down to just ApiNarrowDm, and the only wrinkle remaining for the long term will be that we'll accept pm-with in links and translate that to ApiNarrowDm. We'll handle IsOperand.private similarly.

alerted,
mentioned,
starred,
followed,
Copy link
Member

Choose a reason for hiding this comment

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

needs a TODO-server comment, similar to dm above

Comment on lines 309 to 312
/// See also:
/// - https://zulip.com/api/construct-narrow
/// - https://zulip.com/help/search-for-messages#search-your-important-messages
/// - https://zulip.com/help/search-for-messages#search-by-message-status
Copy link
Member

Choose a reason for hiding this comment

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

Cool, thanks for the thorough collection of links — this made it easy for me to verify the list of values.

if (streamElement != null || topicElement != null || dmElement != null) return null;
return const MentionsNarrow();
switch (isElementOperands.singleOrNull) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this more explicit:

Suggested change
switch (isElementOperands.singleOrNull) {
if (isElementOperands.length > 1) return null;
switch (isElementOperands.single) {

I actually started writing a comment asking if the null case was impossible, because this is inside an isNotEmpty conditional. Then I realized there are two different cases that singleOrNull turns to null.

@PIG208
Copy link
Member Author

PIG208 commented Aug 12, 2024

Thanks for the review @gnprice. Updated the PR.

@gnprice
Copy link
Member

gnprice commented Aug 13, 2024

Thanks for the revision! LGTM.

Would you rebase? It looks like this had a few conflicts with #779 which I just merged.

@PIG208
Copy link
Member Author

PIG208 commented Aug 13, 2024

Thanks. This should be fixed now.

PIG208 added 4 commits August 13, 2024 19:34
Previously, `is` elements with operands other than `mentioned` are
ignored when parsing internal links. When the remaining elements
combined are recognized, some non-null narrows can be returned.

Now `is` elements are never ignored, to avoid such false positives.

Signed-off-by: Zixuan James Li <[email protected]>
This replaces ApiNarrowIsMentioned and ApiNarrowIsUnread with the
generic ApiNarrowIs element.

This does not change the internal links behavior, hence the nfc.
This is also why this commit hasn't introduced new tests yet.

Signed-off-by: Zixuan James Li <[email protected]>
This also helps us with having more thorough test coverage for different
`is` operands.

Signed-off-by: Zixuan James Li <[email protected]>
This matches the behavior of the webapp. Such narrow links are
semantically valid and equivalent to the deduplicated link.

Signed-off-by: Zixuan James Li <[email protected]>
@gnprice
Copy link
Member

gnprice commented Aug 14, 2024

Thanks, looks good — merging.

@gnprice gnprice merged commit f9740c2 into zulip:main Aug 14, 2024
1 check passed
@PIG208 PIG208 deleted the is-narrow branch August 14, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-api Implementing specific parts of the Zulip server API integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants