-
Notifications
You must be signed in to change notification settings - Fork 316
Prep for supporting set typing status #888
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
6 commits
Select commit
Hold shift + click to select a range
b45a7c0
api [nfc]: Fix outdated update instructions.
PIG208 d764cea
api [nfc]: Support const constructor for MessageDestination.
PIG208 850e59f
typing_status [nfc]: Remove debugLog for adding self as typist.
PIG208 d458496
fake_api: Allow recording and taking multiple requests.
PIG208 7fe8048
fake_api: Support preparing a queue of responses.
PIG208 e974ed3
api: Add route setTypingStatus.
PIG208 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '../core.dart'; | ||
import '../model/events.dart'; | ||
import 'messages.dart'; | ||
|
||
|
||
/// https://zulip.com/api/set-typing-status | ||
Future<void> setTypingStatus(ApiConnection connection, { | ||
required TypingOp op, | ||
required MessageDestination destination, | ||
}) { | ||
switch (destination) { | ||
case StreamDestination(): | ||
final supportsTypeChannel = connection.zulipFeatureLevel! >= 248; // TODO(server-9) | ||
final supportsStreamId = connection.zulipFeatureLevel! >= 215; // TODO(server-8) | ||
return connection.post('setTypingStatus', (_) {}, 'typing', { | ||
'op': RawParameter(op.toJson()), | ||
'type': RawParameter(supportsTypeChannel ? 'channel' : 'stream'), | ||
if (supportsStreamId) 'stream_id': destination.streamId | ||
else 'to': [destination.streamId], | ||
'topic': RawParameter(destination.topic), | ||
}); | ||
case DmDestination(): | ||
final supportsDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7) | ||
return connection.post('setTypingStatus', (_) {}, 'typing', { | ||
'op': RawParameter(op.toJson()), | ||
'type': RawParameter(supportsDirect ? 'direct' : 'private'), | ||
'to': destination.userIds, | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/api/model/events.dart'; | ||
import 'package:zulip/api/route/messages.dart'; | ||
import 'package:zulip/api/route/typing.dart'; | ||
|
||
import '../../stdlib_checks.dart'; | ||
import '../fake_api.dart'; | ||
|
||
void main() { | ||
const streamId = 123; | ||
const topic = 'topic'; | ||
const userIds = [101, 102, 103]; | ||
|
||
Future<void> checkSetTypingStatus(FakeApiConnection connection, | ||
TypingOp op, { | ||
required MessageDestination destination, | ||
required Map<String, String> expectedBodyFields, | ||
}) async { | ||
connection.prepare(json: {}); | ||
await setTypingStatus(connection, op: op, destination: destination); | ||
check(connection.lastRequest).isA<http.Request>() | ||
..method.equals('POST') | ||
..url.path.equals('/api/v1/typing') | ||
..bodyFields.deepEquals(expectedBodyFields); | ||
} | ||
|
||
Future<void> checkSetTypingStatusForTopic(TypingOp op, String expectedOp) { | ||
return FakeApiConnection.with_((connection) { | ||
return checkSetTypingStatus(connection, op, | ||
destination: const StreamDestination(streamId, topic), | ||
expectedBodyFields: { | ||
'op': expectedOp, | ||
'type': 'channel', | ||
'stream_id': streamId.toString(), | ||
'topic': topic, | ||
}); | ||
}); | ||
} | ||
|
||
test('send typing status start for topic', () { | ||
return checkSetTypingStatusForTopic(TypingOp.start, 'start'); | ||
}); | ||
|
||
test('send typing status stop for topic', () { | ||
return checkSetTypingStatusForTopic(TypingOp.stop, 'stop'); | ||
}); | ||
|
||
test('send typing status start for dm', () { | ||
return FakeApiConnection.with_((connection) { | ||
return checkSetTypingStatus(connection, TypingOp.start, | ||
destination: const DmDestination(userIds: userIds), | ||
expectedBodyFields: { | ||
'op': 'start', | ||
'type': 'direct', | ||
'to': jsonEncode(userIds), | ||
}); | ||
}); | ||
}); | ||
|
||
test('legacy: use "stream" instead of "channel"', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 247, (connection) { | ||
return checkSetTypingStatus(connection, TypingOp.start, | ||
destination: const StreamDestination(streamId, topic), | ||
expectedBodyFields: { | ||
'op': 'start', | ||
'type': 'stream', | ||
'stream_id': streamId.toString(), | ||
'topic': topic, | ||
}); | ||
}); | ||
}); | ||
|
||
test('legacy: use to=[streamId] instead of stream_id=streamId', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 214, (connection) { | ||
return checkSetTypingStatus(connection, TypingOp.start, | ||
destination: const StreamDestination(streamId, topic), | ||
expectedBodyFields: { | ||
'op': 'start', | ||
'type': 'stream', | ||
'to': jsonEncode([streamId]), | ||
'topic': topic, | ||
}); | ||
}); | ||
}); | ||
|
||
test('legacy: use "private" instead of "direct"', () { | ||
return FakeApiConnection.with_(zulipFeatureLevel: 173, (connection) { | ||
return checkSetTypingStatus(connection, TypingOp.start, | ||
destination: const DmDestination(userIds: userIds), | ||
expectedBodyFields: { | ||
'op': 'start', | ||
'type': 'private', | ||
'to': jsonEncode(userIds), | ||
}); | ||
}); | ||
}); | ||
} |
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
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.
How about also making the return type
Iterable
here?Uh oh!
There was an error while loading. Please reload this page.
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 didn't apply the same refactor there because
takeRequests
do not need to protect the list from modification, whereList
would be an accurate return type.