Skip to content

Commit f2fcb10

Browse files
committed
autocomplete: Setup stream topics API binding
1 parent b2f9e5c commit f2fcb10

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

lib/api/route/streams.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
import '../core.dart';
4+
part 'streams.g.dart';
5+
6+
/// https://zulip.com/api/get-stream-topics
7+
Future<GetTopicsResult> getStreamTopics(
8+
ApiConnection connection, {
9+
required int streamId,
10+
}) {
11+
return connection.get('getStreamTopics', GetTopicsResult.fromJson,
12+
'users/me/$streamId/topics', {});
13+
}
14+
15+
@JsonSerializable(fieldRename: FieldRename.snake)
16+
class GetTopicsResult {
17+
final List<Topic> topics;
18+
19+
GetTopicsResult({
20+
required this.topics,
21+
});
22+
23+
factory GetTopicsResult.fromJson(Map<String, dynamic> json) =>
24+
_$GetTopicsResultFromJson(json);
25+
26+
Map<String, dynamic> toJson() => _$GetTopicsResultToJson(this);
27+
}
28+
29+
@JsonSerializable(fieldRename: FieldRename.snake)
30+
class Topic {
31+
final int maxId;
32+
@JsonKey(name: 'name')
33+
final String value;
34+
35+
Topic({
36+
required this.maxId,
37+
required this.value,
38+
});
39+
40+
factory Topic.fromJson(Map<String, dynamic> json) => _$TopicFromJson(json);
41+
42+
Map<String, dynamic> toJson() => _$TopicToJson(this);
43+
}

lib/api/route/streams.g.dart

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)