-
Notifications
You must be signed in to change notification settings - Fork 309
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
81faeb3
api test: Fix with_ to await callback first, then close
gnprice 1aacda4
api test [nfc]: Factor out common checks in sendMessage tests
gnprice d53f3fb
api test: Add getMessages tests
gnprice e70e13d
store [nfc]: Add todo on keeping zulipVersion updated
gnprice e3a3496
api [nfc]: Carry zulipFeatureLevel on ApiConnection
gnprice fd54070
api: In sendMessage, use "direct" where possible
gnprice 3e797d4
api: In getMessages, use "dm" operator where possible
gnprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,18 +84,30 @@ class FakeHttpClient extends http.BaseClient { | |
|
||
/// An [ApiConnection] that accepts and replays canned responses, for testing. | ||
class FakeApiConnection extends ApiConnection { | ||
FakeApiConnection({Uri? realmUrl}) | ||
: this._(realmUrl: realmUrl ?? eg.realmUrl, client: FakeHttpClient()); | ||
/// Construct an [ApiConnection] that accepts and replays canned responses, for testing. | ||
/// | ||
/// If `zulipFeatureLevel` is omitted, it defaults to [eg.futureZulipFeatureLevel], | ||
/// which causes route bindings to behave as they would for the | ||
/// latest Zulip server versions. | ||
/// To set `zulipFeatureLevel` to null, pass null explicitly. | ||
FakeApiConnection({Uri? realmUrl, int? zulipFeatureLevel = eg.futureZulipFeatureLevel}) | ||
: this._( | ||
realmUrl: realmUrl ?? eg.realmUrl, | ||
zulipFeatureLevel: zulipFeatureLevel, | ||
client: FakeHttpClient(), | ||
); | ||
|
||
FakeApiConnection.fromAccount(Account account) | ||
: this._( | ||
realmUrl: account.realmUrl, | ||
zulipFeatureLevel: account.zulipFeatureLevel, | ||
email: account.email, | ||
apiKey: account.apiKey, | ||
client: FakeHttpClient()); | ||
|
||
FakeApiConnection._({ | ||
required super.realmUrl, | ||
required super.zulipFeatureLevel, | ||
super.email, | ||
super.apiKey, | ||
required this.client, | ||
|
@@ -105,17 +117,24 @@ class FakeApiConnection extends ApiConnection { | |
|
||
/// Run the given callback on a fresh [FakeApiConnection], then close it, | ||
/// using try/finally. | ||
/// | ||
/// If `zulipFeatureLevel` is omitted, it defaults to [eg.futureZulipFeatureLevel], | ||
/// which causes route bindings to behave as they would for the | ||
/// latest Zulip server versions. | ||
/// To set `zulipFeatureLevel` to null, pass null explicitly. | ||
static Future<T> with_<T>( | ||
Future<T> Function(FakeApiConnection connection) fn, { | ||
Uri? realmUrl, | ||
int? zulipFeatureLevel = eg.futureZulipFeatureLevel, | ||
Account? account, | ||
}) async { | ||
assert((account == null) || (realmUrl == null)); | ||
assert((account == null) | ||
|| (realmUrl == null && zulipFeatureLevel == eg.futureZulipFeatureLevel)); | ||
final connection = (account != null) | ||
? FakeApiConnection.fromAccount(account) | ||
: FakeApiConnection(realmUrl: realmUrl); | ||
: FakeApiConnection(realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel); | ||
try { | ||
return fn(connection); | ||
return await fn(connection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Interesting; yeah. I think there's a "gotcha" like this in JavaScript, too. |
||
} finally { | ||
connection.close(); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
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:The idea there is similar, and again it's not something I'd particularly regret going away if we adopted auto-formatting.