-
Notifications
You must be signed in to change notification settings - Fork 308
api: Carry zulipFeatureLevel on ApiConnection, and use it for sending "direct" and "dm" #159
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
Conversation
As is, the `finally` block gets run before the future returned by the callback has completed. I believe the underlying issue here is this one in the Dart SDK: dart-lang/sdk#44395 The fix is to await the future and return the result of that, rather than returning the future directly. The Dart language folks (or at least some of them) hope to eventually deal with this by making the old code here a type error, requiring the value passed to `return` to have type T rather than Future<T>: dart-lang/language#870
This will help when we add more complexity to this route binding and correspondingly more tests.
These should suffice to cover all the logic in this route binding.
This doesn't yet do anything, but it provides the infrastructure for taking care of zulip#146: it sets us up to have individual route bindings condition their behavior on the Zulip feature level as appropriate.
class ApiNarrowDm extends ApiNarrowElement { | ||
@override String get operator => 'pm-with'; // TODO(#146): use 'dm' where possible | ||
@override String get operator { |
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 sort of thing was why I was asking about the dart format. I see both this style and the more traditional style throughout the codebase.
@override
String get operator {}
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.
Yeah, for the classes in this file (before this PR, anyway), they're all so short and simple and parallel to each other that I felt the one-line form like
@override String get operator => 'topic';
was helpful for reading, by helping make the parallelism easy to see.
If we did adopt automated formatting, though, I wouldn't really mind these going into multi-line form as a consequence of that.
At a quick grep (git grep '@override '
), I'm only finding one other spot in the codebase where we use the one-line form:
class UriConverter extends TypeConverter<Uri, String> {
const UriConverter();
@override String toSql(Uri value) => value.toString();
@override Uri fromSql(String fromDb) => Uri.parse(fromDb);
}
The idea there is similar, and again it's not something I'd particularly regret going away if we adopted auto-formatting.
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.
Thanks, LGTM! Please merge at will.
@@ -115,7 +115,7 @@ class FakeApiConnection extends ApiConnection { | |||
? FakeApiConnection.fromAccount(account) | |||
: FakeApiConnection(realmUrl: realmUrl); | |||
try { | |||
return fn(connection); | |||
return await fn(connection); |
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.
api test: Fix with_ to await callback first, then close
As is, the `finally` block gets run before the future returned by
the callback has completed. I believe the underlying issue here
is this one in the Dart SDK:
https://github.com/dart-lang/sdk/issues/44395
The fix is to await the future and return the result of that,
rather than returning the future directly.
The Dart language folks (or at least some of them) hope to
eventually deal with this by making the old code here a type error,
requiring the value passed to `return` to have type T rather
than Future<T>:
https://github.com/dart-lang/language/issues/870
Interesting; yeah. I think there's a "gotcha" like this in JavaScript, too.
Fixes: #146
In #146 I listed these two spots where we'd want to use this capability once we added it, and mentioned that there might be others. On scanning through a grep for
TODO.server
, though, these are the only such places that I find.