@@ -7,6 +7,7 @@ import '../api/exception.dart';
7
7
import '../api/model/model.dart' ;
8
8
import '../api/model/narrow.dart' ;
9
9
import '../api/route/messages.dart' ;
10
+ import '../api/route/channels.dart' as channels_api;
10
11
import '../generated/l10n/zulip_localizations.dart' ;
11
12
import '../model/binding.dart' ;
12
13
import '../model/narrow.dart' ;
@@ -239,6 +240,32 @@ abstract final class ZulipAction {
239
240
240
241
return fetchedMessage? .content;
241
242
}
243
+
244
+ static Future <void > subscribeToChannel (BuildContext context, {
245
+ required int channelId,
246
+ }) async {
247
+ final store = PerAccountStoreWidget .of (context);
248
+ final channel = store.streams[channelId];
249
+ if (channel == null || channel is Subscription ) return ; // TODO could give feedback
250
+
251
+ try {
252
+ await channels_api.subscribeToChannel (store.connection, subscriptions: [channel.name]);
253
+ } catch (e) {
254
+ if (! context.mounted) return ;
255
+
256
+ String ? errorMessage;
257
+ switch (e) {
258
+ case ZulipApiException ():
259
+ errorMessage = e.message;
260
+ // TODO(#741) specific messages for common errors, like network errors
261
+ // (support with reusable code)
262
+ default :
263
+ }
264
+
265
+ final title = ZulipLocalizations .of (context).subscribeFailedTitle;
266
+ showErrorDialog (context: context, title: title, message: errorMessage);
267
+ }
268
+ }
242
269
}
243
270
244
271
/// Methods that act through platform APIs and show feedback in the UI.
0 commit comments