Skip to content

Commit 96836fc

Browse files
committed
api: Add route subscribeToChannels
1 parent f51e828 commit 96836fc

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/api/route/channels.dart

+25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:json_annotation/json_annotation.dart';
22

33
import '../core.dart';
4+
import '../model/model.dart';
45
part 'channels.g.dart';
56

67
/// https://zulip.com/api/get-stream-topics
@@ -38,3 +39,27 @@ class GetStreamTopicsEntry {
3839

3940
Map<String, dynamic> toJson() => _$GetStreamTopicsEntryToJson(this);
4041
}
42+
43+
/// https://zulip.com/api/subscribe
44+
Future<SubscribeToChannelsResult> subscribeToChannels(ApiConnection connection, List<ZulipStream> streams) {
45+
return connection.post('subscribe', SubscribeToChannelsResult.fromJson,
46+
'users/me/subscriptions', {'subscriptions': streams.map((e) => {'name': e.name}).toList()});
47+
}
48+
49+
@JsonSerializable(fieldRename: FieldRename.snake)
50+
class SubscribeToChannelsResult {
51+
final Map<String, List<String>> subscribed;
52+
final Map<String, List<String>> alreadySubscribed;
53+
final List<String>? unauthorized;
54+
55+
SubscribeToChannelsResult({
56+
required this.subscribed,
57+
required this.alreadySubscribed,
58+
this.unauthorized,
59+
});
60+
61+
factory SubscribeToChannelsResult.fromJson(Map<String, dynamic> json) =>
62+
_$SubscribeToChannelsResultFromJson(json);
63+
64+
Map<String, dynamic> toJson() => _$SubscribeToChannelsResultToJson(this);
65+
}

lib/api/route/channels.g.dart

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

0 commit comments

Comments
 (0)