Skip to content

Commit a3a68d9

Browse files
committed
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: zulip#1250 Signed-off-by: Zixuan James Li <[email protected]>
1 parent 0b65586 commit a3a68d9

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': resolveDmElements(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;
@@ -149,7 +150,10 @@ void main() {
149150
await checkGetMessage(connection,
150151
messageId: 1,
151152
applyMarkdown: true,
152-
expected: {'apply_markdown': 'true'});
153+
expected: {
154+
'apply_markdown': 'true',
155+
'allow_empty_topic_name': 'true',
156+
});
153157
});
154158
});
155159

@@ -159,7 +163,19 @@ void main() {
159163
await checkGetMessage(connection,
160164
messageId: 1,
161165
applyMarkdown: false,
162-
expected: {'apply_markdown': 'false'});
166+
expected: {
167+
'apply_markdown': 'false',
168+
'allow_empty_topic_name': 'true',
169+
});
170+
});
171+
});
172+
173+
test('legacy: empty topic name not supported', () {
174+
return FakeApiConnection.with_(zulipFeatureLevel: 333, (connection) async {
175+
connection.prepare(json: fakeResult.toJson());
176+
await checkGetMessage(connection,
177+
messageId: 1,
178+
expected: {});
163179
});
164180
});
165181

@@ -259,6 +275,7 @@ void main() {
259275
'anchor': 'newest',
260276
'num_before': '10',
261277
'num_after': '20',
278+
'allow_empty_topic_name': 'true',
262279
});
263280
});
264281
});
@@ -292,6 +309,22 @@ void main() {
292309
'anchor': '42',
293310
'num_before': '10',
294311
'num_after': '20',
312+
'allow_empty_topic_name': 'true',
313+
});
314+
});
315+
});
316+
317+
test('legacy: empty topic name not supported', () {
318+
return FakeApiConnection.with_(zulipFeatureLevel: 333, (connection) async {
319+
connection.prepare(json: fakeResult.toJson());
320+
await checkGetMessages(connection,
321+
narrow: const CombinedFeedNarrow().apiEncode(),
322+
anchor: AnchorCode.newest, numBefore: 10, numAfter: 20,
323+
expected: {
324+
'narrow': jsonEncode([]),
325+
'anchor': 'newest',
326+
'num_before': '10',
327+
'num_after': '20',
295328
});
296329
});
297330
});

0 commit comments

Comments
 (0)