Skip to content

Commit bc3377d

Browse files
committed
do not merge; api: Indicate support for handling empty topics
Look for `allow_empty_topic_name` and `empty_topic_name` under "Feature level 334" in the API Changelog to verify the affected routes: https://zulip.com/api/changelog Fixes: #1250 Signed-off-by: Zixuan James Li <[email protected]>
1 parent 447f9f4 commit bc3377d

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

lib/api/route/channels.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ part 'channels.g.dart';
88
Future<GetStreamTopicsResult> getStreamTopics(ApiConnection connection, {
99
required int streamId,
1010
}) {
11-
return connection.get('getStreamTopics', GetStreamTopicsResult.fromJson, 'users/me/$streamId/topics', {});
11+
final supportsEmptyTopics = connection.zulipFeatureLevel! >= 334; // TODO(server-10)
12+
return connection.get('getStreamTopics', GetStreamTopicsResult.fromJson, 'users/me/$streamId/topics', {
13+
if (supportsEmptyTopics) 'allow_empty_topic_name': true,
14+
});
1215
}
1316

1417
@JsonSerializable(fieldRename: FieldRename.snake)

lib/api/route/events.dart

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Future<InitialSnapshot> registerQueue(ApiConnection connection) {
1818
'user_avatar_url_field_optional': false, // TODO(#254): turn on
1919
'stream_typing_notifications': true,
2020
'user_settings_object': true,
21+
'empty_topic_name': true,
2122
},
2223
});
2324
}

lib/api/route/messages.dart

+4
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ Future<GetMessageResult> getMessage(ApiConnection connection, {
5959
bool? applyMarkdown,
6060
}) {
6161
assert(connection.zulipFeatureLevel! >= 120);
62+
final supportsEmptyTopics = connection.zulipFeatureLevel! >= 334; // TODO(server-10)
6263
return connection.get('getMessage', GetMessageResult.fromJson, 'messages/$messageId', {
6364
if (applyMarkdown != null) 'apply_markdown': applyMarkdown,
65+
if (supportsEmptyTopics) 'allow_empty_topic_name': true,
6466
});
6567
}
6668

@@ -90,6 +92,7 @@ Future<GetMessagesResult> getMessages(ApiConnection connection, {
9092
bool? applyMarkdown,
9193
// bool? useFirstUnreadAnchor // omitted because deprecated
9294
}) {
95+
final supportsEmptyTopics = connection.zulipFeatureLevel! >= 334; // TODO(server-10)
9396
return connection.get('getMessages', GetMessagesResult.fromJson, 'messages', {
9497
'narrow': resolveApiNarrowForServer(narrow, connection.zulipFeatureLevel!),
9598
'anchor': RawParameter(anchor.toJson()),
@@ -98,6 +101,7 @@ Future<GetMessagesResult> getMessages(ApiConnection connection, {
98101
'num_after': numAfter,
99102
if (clientGravatar != null) 'client_gravatar': clientGravatar,
100103
if (applyMarkdown != null) 'apply_markdown': applyMarkdown,
104+
if (supportsEmptyTopics) 'allow_empty_topic_name': true,
101105
});
102106
}
103107

test/api/route/channels_test.dart

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,30 @@ import '../../stdlib_checks.dart';
88
import '../fake_api.dart';
99

1010
void main() {
11+
test('smoke getStreamTopics', () {
12+
return FakeApiConnection.with_((connection) async {
13+
connection.prepare(json: GetStreamTopicsResult(topics: []).toJson());
14+
await getStreamTopics(connection, streamId: 1);
15+
check(connection.takeRequests()).single.isA<http.Request>()
16+
..method.equals('GET')
17+
..url.path.equals('/api/v1/users/me/1/topics')
18+
..url.queryParameters.deepEquals({
19+
'allow_empty_topic_name': 'true',
20+
});
21+
});
22+
});
23+
24+
test('legacy: getStreamTopics when FL < 334', () {
25+
return FakeApiConnection.with_(zulipFeatureLevel: 333, (connection) async {
26+
connection.prepare(json: GetStreamTopicsResult(topics: []).toJson());
27+
await getStreamTopics(connection, streamId: 1);
28+
check(connection.takeRequests()).single.isA<http.Request>()
29+
..method.equals('GET')
30+
..url.path.equals('/api/v1/users/me/1/topics')
31+
..url.queryParameters.deepEquals({});
32+
});
33+
});
34+
1135
test('smoke updateUserTopic', () {
1236
return FakeApiConnection.with_((connection) async {
1337
connection.prepare(json: {});

test/api/route/messages_test.dart

+35-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void main() {
4343
..url.path.equals('/api/v1/messages/$messageId')
4444
..url.queryParameters.deepEquals({
4545
if (applyMarkdown != null) 'apply_markdown': applyMarkdown.toString(),
46+
'allow_empty_topic_name': 'true',
4647
});
4748
}
4849
return result;
@@ -145,7 +146,10 @@ void main() {
145146
await checkGetMessage(connection,
146147
messageId: 1,
147148
applyMarkdown: true,
148-
expected: {'apply_markdown': 'true'});
149+
expected: {
150+
'apply_markdown': 'true',
151+
'allow_empty_topic_name': 'true',
152+
});
149153
});
150154
});
151155

@@ -155,7 +159,19 @@ void main() {
155159
await checkGetMessage(connection,
156160
messageId: 1,
157161
applyMarkdown: false,
158-
expected: {'apply_markdown': 'false'});
162+
expected: {
163+
'apply_markdown': 'false',
164+
'allow_empty_topic_name': 'true',
165+
});
166+
});
167+
});
168+
169+
test('legacy: empty topic name not supported', () {
170+
return FakeApiConnection.with_(zulipFeatureLevel: 333, (connection) async {
171+
connection.prepare(json: fakeResult.toJson());
172+
await checkGetMessage(connection,
173+
messageId: 1,
174+
expected: {});
159175
});
160176
});
161177

@@ -284,6 +300,7 @@ void main() {
284300
'anchor': 'newest',
285301
'num_before': '10',
286302
'num_after': '20',
303+
'allow_empty_topic_name': 'true',
287304
});
288305
});
289306
});
@@ -317,6 +334,22 @@ void main() {
317334
'anchor': '42',
318335
'num_before': '10',
319336
'num_after': '20',
337+
'allow_empty_topic_name': 'true',
338+
});
339+
});
340+
});
341+
342+
test('legacy: empty topic name not supported', () {
343+
return FakeApiConnection.with_(zulipFeatureLevel: 333, (connection) async {
344+
connection.prepare(json: fakeResult.toJson());
345+
await checkGetMessages(connection,
346+
narrow: const CombinedFeedNarrow().apiEncode(),
347+
anchor: AnchorCode.newest, numBefore: 10, numAfter: 20,
348+
expected: {
349+
'narrow': jsonEncode([]),
350+
'anchor': 'newest',
351+
'num_before': '10',
352+
'num_after': '20',
320353
});
321354
});
322355
});

0 commit comments

Comments
 (0)