Skip to content

Commit 14af294

Browse files
committed
channel_list: Setup subscribeToChannels api binding
1 parent e780865 commit 14af294

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

lib/api/route/channel.dart

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
import '../core.dart';
4+
import '../model/model.dart';
5+
6+
part 'channel.g.dart';
7+
8+
// https://zulip.com/api/subscribe
9+
Future<SubscribeToChannelsResult> subscribeToChannels(ApiConnection connection, List<ZulipStream> streams) {
10+
return connection.post('subscribe', SubscribeToChannelsResult.fromJson,
11+
'users/me/subscriptions', {'subscriptions': streams.map((e) => {'name': e.name}).toList()});
12+
}
13+
14+
@JsonSerializable(fieldRename: FieldRename.snake)
15+
class SubscribeToChannelsResult {
16+
final Map<String, List<String>> subscribed;
17+
final Map<String, List<String>> alreadySubscribed;
18+
final List<String>? unauthorized;
19+
20+
SubscribeToChannelsResult({
21+
required this.subscribed,
22+
required this.alreadySubscribed,
23+
this.unauthorized,
24+
});
25+
26+
factory SubscribeToChannelsResult.fromJson(Map<String, dynamic> json) =>
27+
_$SubscribeToChannelsResultFromJson(json);
28+
29+
Map<String, dynamic> toJson() => _$SubscribeToChannelsResultToJson(this);
30+
}
31+

lib/api/route/channel.g.dart

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)