Skip to content

New read_for_sender flag when sending a new message #456

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 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Future<SendMessageResult> sendMessage(
required String content,
String? queueId,
String? localId,
bool? readBySender,
}) {
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
Expand All @@ -191,8 +192,9 @@ Future<SendMessageResult> sendMessage(
throw Exception('impossible destination') // TODO(dart-3) show this statically
),
'content': RawParameter(content),
if (queueId != null) 'queue_id': queueId,
if (localId != null) 'local_id': localId,
if (queueId != null) 'queue_id': queueId, // TODO should this use RawParameter?
if (localId != null) 'local_id': localId, // TODO should this use RawParameter?
if (readBySender != null) 'read_by_sender': readBySender,
});
}

Expand Down
6 changes: 5 additions & 1 deletion lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
Future<void> sendMessage({required MessageDestination destination, required String content}) {
// TODO implement outbox; see design at
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
return _apiSendMessage(connection, destination: destination, content: content);
return _apiSendMessage(connection,
destination: destination,
content: content,
readBySender: true,
);
}

static List<CustomProfileField> _sortCustomProfileFields(List<CustomProfileField> initialCustomProfileFields) {
Expand Down
25 changes: 24 additions & 1 deletion test/api/route/messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,41 @@ void main() {
FakeApiConnection connection, {
required MessageDestination destination,
required String content,
String? queueId,
String? localId,
bool? readBySender,
required Map<String, String> expectedBodyFields,
}) async {
connection.prepare(json: SendMessageResult(id: 42).toJson());
final result = await sendMessage(connection,
destination: destination, content: content);
destination: destination, content: content,
queueId: queueId, localId: localId, readBySender: readBySender);
check(result).id.equals(42);
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages')
..bodyFields.deepEquals(expectedBodyFields);
}

test('smoke', () {
return FakeApiConnection.with_((connection) async {
await checkSendMessage(connection,
destination: StreamDestination(streamId, topic), content: content,
queueId: 'abc:123',
localId: '456',
readBySender: true,
expectedBodyFields: {
'type': 'stream',
'to': streamId.toString(),
'topic': topic,
'content': content,
'queue_id': '"abc:123"',
'local_id': '"456"',
'read_by_sender': 'true',
});
});
});

test('to stream', () {
return FakeApiConnection.with_((connection) async {
await checkSendMessage(connection,
Expand Down
23 changes: 23 additions & 0 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:checks/checks.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:test/scaffolding.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/model/store.dart';
import 'package:zulip/notifications.dart';

Expand Down Expand Up @@ -108,6 +109,28 @@ void main() {
check(completers(1)).length.equals(1);
});

group('PerAccountStore.sendMessage', () {
test('smoke', () async {
final store = eg.store();
final connection = store.connection as FakeApiConnection;
final stream = eg.stream();
connection.prepare(json: SendMessageResult(id: 12345).toJson());
await store.sendMessage(
destination: StreamDestination(stream.streamId, 'world'),
content: 'hello');
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
..url.path.equals('/api/v1/messages')
..bodyFields.deepEquals({
'type': 'stream',
'to': stream.streamId.toString(),
'topic': 'world',
'content': 'hello',
'read_by_sender': 'true',
});
});
});

group('UpdateMachine.registerNotificationToken', () {
late UpdateMachine updateMachine;
late FakeApiConnection connection;
Expand Down