Skip to content
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

Prep for supporting set typing status #888

Merged
merged 6 commits into from
Sep 16, 2024
Merged

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Aug 14, 2024

No description provided.

}

Future<void> _notifyStart(PerAccountStore store) async {
_nextStartTime = DateTime.now().add(typingStartedWaitPeriod);
Copy link
Member

Choose a reason for hiding this comment

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

Quick high-level comment: let's write this so that we definitely don't have to think about time zones to reason about it. 🙂

I think an OK version could be made with DateTime.timestamp(), which uses UTC. Probably a cleaner approach is to use Stopwatch — then we're really not thinking about calendar dates or anything like that, just elapsed durations, which is exactly right for this subsystem.

@PIG208 PIG208 force-pushed the set-typing branch 10 times, most recently from 382289d to fe71eea Compare August 20, 2024 06:46
@PIG208 PIG208 changed the title WIP Set typing status Add set typing status route Aug 20, 2024
@PIG208 PIG208 changed the title Add set typing status route Prep for supporting set typing status Aug 20, 2024
@PIG208
Copy link
Member Author

PIG208 commented Aug 20, 2024

Moved the main commits to #897, so that we can get some earlier independent changes reviewed separately.

@PIG208 PIG208 marked this pull request as ready for review August 20, 2024 06:50
@PIG208 PIG208 requested a review from chrisbobbe August 20, 2024 06:50
@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Aug 20, 2024
@PIG208 PIG208 force-pushed the set-typing branch 3 times, most recently from 58a36d9 to e19c4de Compare August 20, 2024 23:13
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! Comments below.

@@ -29,11 +29,11 @@ class _PreparedSuccess extends _PreparedResponse {
/// An [http.Client] that accepts and replays canned responses, for testing.
class FakeHttpClient extends http.BaseClient {

http.BaseRequest? lastRequest;
List<http.BaseRequest> requestHistory = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be helpful to make this a getter that returns an Iterable, which is backed by a private field that's a List? Then consumers of the request history can't mess with things by modifying the list.

Comment on lines 61 to 63
// TODO: Prevent a source of bugs by ensuring that there is no outstanding
// prepared responses when the test ends.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: "that there are no outstanding prepared responses"

Comment on lines 21 to 28
return connection.post('setTypingStatus', (_) {}, 'typing', {
'op': RawParameter(op.toJson()),
'to': destination.userIds,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the effect of not passing 'type' in the DM case? From the doc, it looks like the preferred client behavior (assuming Zulip Server 4+) is to pass 'private' when FL is <174, else 'direct'. I'm not sure I've read closely enough to know what happens across the range of supported servers if we just don't pass 'type' at all.

Copy link
Member Author

@PIG208 PIG208 Aug 22, 2024

Choose a reason for hiding this comment

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

This was intended to match the mobile apps' implementation, where we omit the type field for dm typing notifications. I think it is not clear that the default was "private" back then. Skipping type this way allows us to not worry about the "private" -> "direct" transition of this API.

See: https://chat.zulip.org/#narrow/stream/378-api-design/topic/stream.20typing.20indicator

Copy link
Collaborator

@chrisbobbe chrisbobbe Aug 22, 2024

Choose a reason for hiding this comment

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

I see. I guess since zulip-mobile does that not-preferred thing and presumably still works, probably makes it harmless if we also do the not-preferred thing. 🙂 But also, the burden of handling the "private" -> "direct" transition isn't heavy—

pass 'private' when FL is <174, else 'direct'

—so I'd be in favor of just doing that. If not, though, let's include a comment to make it clear that we're intentionally doing something that's different from the thing that seems natural/expected from a reading of the API doc.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, cleanest to just do the thing that's preferred in the current API.

(And then adapt for old servers as necessary — but "type" has been accepted since server-4, so effectively forever now.)

return connection.post('setTypingStatus', (_) {}, 'typing', {
'type': RawParameter((supportsTypeChannel) ? 'channel' : 'stream'),
'op': RawParameter(op.toJson()),
'stream_id': destination.streamId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The API doc says 'stream_id' is new in FL 215, and there's a different way we need to express the destination for <215.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, thanks for catching that!

Comment on lines 26 to 27
destination: destination,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
destination: destination,
);
destination: destination);

Comment on lines 77 to 78
},
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
},
);
});

@PIG208 PIG208 force-pushed the set-typing branch 4 times, most recently from 6ff98a9 to 3bac13a Compare August 22, 2024 22:33
@PIG208
Copy link
Member Author

PIG208 commented Aug 22, 2024

Thanks for the review @chrisbobbe! I have updated the PR.

  • Dropped fromSendableNarrow to keep the api code from depending on lib/model.
  • Reorganized the tests and made them shorter.
  • Handle the legacy case for FL 215.

@PIG208
Copy link
Member Author

PIG208 commented Aug 23, 2024

Thanks! I should push an update later addressing these comments.

@PIG208 PIG208 force-pushed the set-typing branch 2 times, most recently from eec2173 to c823d5c Compare August 23, 2024 22:01
@PIG208 PIG208 requested a review from gnprice August 23, 2024 22:03
@PIG208
Copy link
Member Author

PIG208 commented Aug 23, 2024

OK, this has been updated :)

@PIG208 PIG208 linked an issue Aug 29, 2024 that may be closed by this pull request
@PIG208 PIG208 removed a link to an issue Aug 29, 2024
@PIG208
Copy link
Member Author

PIG208 commented Sep 5, 2024

Fixed indentation in a test.

@PIG208
Copy link
Member Author

PIG208 commented Sep 7, 2024

Pushed to rebase.

@PIG208 PIG208 force-pushed the set-typing branch 2 times, most recently from 2a349d8 to 9a77275 Compare September 12, 2024 21:31
@PIG208
Copy link
Member Author

PIG208 commented Sep 12, 2024

Dropped the checkDmExpectedOp helper because the TypingOp.toJson is already tested with the typing status for topic tests. Also revised the wording of some tests.

final supportsTypeChannel = connection.zulipFeatureLevel! >= 248; // TODO(server-9)
final supportsStreamId = connection.zulipFeatureLevel! >= 215; // TODO(server-8)
return connection.post('setTypingStatus', (_) {}, 'typing', {
'type': RawParameter((supportsTypeChannel) ? 'channel' : 'stream'),
Copy link
Member

Choose a reason for hiding this comment

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

nit: extra parens

Comment on lines 18 to 20
'topic': RawParameter(destination.topic),
...(supportsStreamId) ? {'stream_id': destination.streamId}
: {'to': [destination.streamId]}
Copy link
Member

Choose a reason for hiding this comment

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

nit: put in logical order: channel/stream ID before topic, because the topic lives within the channel

Similarly, put type just above the channel ID (or list of DM recipients), because it's the next layer of namespacing above those.

Comment on lines 19 to 20
...(supportsStreamId) ? {'stream_id': destination.streamId}
: {'to': [destination.streamId]}
Copy link
Member

Choose a reason for hiding this comment

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

A fun Dart 3 way to write this:

Suggested change
...(supportsStreamId) ? {'stream_id': destination.streamId}
: {'to': [destination.streamId]}
if (supportsStreamId) 'stream_id': destination.streamId
else 'to': [destination.streamId],

Comment on lines 18 to 20
Future<void> checkSetTypingStatus(FakeApiConnection connection, TypingOp op, {
required MessageDestination destination,
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
Future<void> checkSetTypingStatus(FakeApiConnection connection, TypingOp op, {
required MessageDestination destination,
Future<void> checkSetTypingStatus(FakeApiConnection connection,
TypingOp op, {
required MessageDestination destination,

else "op" gets a bit lost visually

Comment on lines 30 to 32
Future<void> checkSetTypingStatusForTopic(TypingOp op, String expectedOp) =>
FakeApiConnection.with_((connection) =>
checkSetTypingStatus(connection, op,
Copy link
Member

Choose a reason for hiding this comment

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

nit: block bodies

see that Flutter style guide section I've linked a few times before 🙂

Comment on lines 41 to 42
test('send typing status start for topic', () =>
checkSetTypingStatusForTopic(TypingOp.start, 'start'));
Copy link
Member

Choose a reason for hiding this comment

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

And definitely block bodies for test cases.

Comment on lines 21 to 28
return connection.post('setTypingStatus', (_) {}, 'typing', {
'op': RawParameter(op.toJson()),
'to': destination.userIds,
});
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, cleanest to just do the thing that's preferred in the current API.

(And then adapt for old servers as necessary — but "type" has been accepted since server-4, so effectively forever now.)

@gnprice
Copy link
Member

gnprice commented Sep 13, 2024

Thanks @PIG208, and thanks @chrisbobbe for the previous reviews!

Generally this all looks good. Several comments above, all small.

@PIG208
Copy link
Member Author

PIG208 commented Sep 13, 2024

Thanks! Pushed an update to the last commit.

UserSettingName has been moved to another file.

Signed-off-by: Zixuan James Li <[email protected]>
This is not prohibited by the server and we should not log expected
behaviors like this.

See:

  https://zulip.com/api/get-events#typing-start

Signed-off-by: Zixuan James Li <[email protected]>
An issue that exists prior to this change is that there can be unused
prepared responses when the test ends, but we don't have a way to
detect that. We can potentially do something like what testWidgets
does with pending timers.

Signed-off-by: Zixuan James Li <[email protected]>
The three legacy cases will need to be dropped separately at different
server versions. The tests will fail accordingly as we do that.

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

gnprice commented Sep 16, 2024

Thanks! Looks good; merging.

@gnprice gnprice merged commit e974ed3 into zulip:main Sep 16, 2024
@PIG208 PIG208 deleted the set-typing branch September 17, 2024 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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