|
1 | 1 | import 'package:json_annotation/json_annotation.dart';
|
2 | 2 |
|
3 | 3 | import '../core.dart';
|
| 4 | +import '../model/model.dart'; |
4 | 5 | part 'channels.g.dart';
|
5 | 6 |
|
6 | 7 | /// https://zulip.com/api/get-stream-topics
|
@@ -38,3 +39,27 @@ class GetStreamTopicsEntry {
|
38 | 39 |
|
39 | 40 | Map<String, dynamic> toJson() => _$GetStreamTopicsEntryToJson(this);
|
40 | 41 | }
|
| 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 | +} |
0 commit comments