diff --git a/lib/components/drawer/sidebar.dart b/lib/components/drawer/sidebar.dart index 549796b5b..c2a866c70 100644 --- a/lib/components/drawer/sidebar.dart +++ b/lib/components/drawer/sidebar.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:rtchat/components/channel_search_bottom_sheet.dart'; import 'package:rtchat/components/drawer/quicklinks_listview.dart'; import 'package:rtchat/components/image/cross_fade_image.dart'; +import 'package:rtchat/models/adapters/actions.dart'; import 'package:rtchat/models/audio.dart'; import 'package:rtchat/models/channels.dart'; import 'package:rtchat/models/layout.dart'; @@ -127,18 +128,19 @@ class _DrawerHeader extends StatelessWidget { onChannelSelect: (channel) { model.activeChannel = channel; }, - onRaid: - userChannel == model.activeChannel && - userChannel != null - ? (channel) { - final userModel = - Provider.of( - context, - listen: false); - userModel.send(userChannel, - "/raid ${channel.displayName}"); - } - : null, + onRaid: userChannel == + model.activeChannel && + userChannel != null + ? (channel) { + final activeChannel = + model.activeChannel; + if (activeChannel == null) { + return; + } + ActionsAdapter.instance + .raid(activeChannel, channel); + } + : null, controller: controller, ); }, diff --git a/lib/models/adapters/actions.dart b/lib/models/adapters/actions.dart index bee57d232..e81073e57 100644 --- a/lib/models/adapters/actions.dart +++ b/lib/models/adapters/actions.dart @@ -13,6 +13,15 @@ class ActionsAdapter { functions: FirebaseFunctions.instance); static ActionsAdapter? _instance; + Future send(Channel channel, String message) async { + final call = functions.httpsCallable('send'); + await call({ + "provider": channel.provider, + "channelId": channel.channelId, + "message": message, + }); + } + Future ban(Channel channel, String username) async { final call = functions.httpsCallable('ban'); await call({ @@ -51,4 +60,17 @@ class ActionsAdapter { "messageId": messageId, }); } + + Future raid(Channel fromChannel, Channel toChannel) async { + if (fromChannel.provider != toChannel.provider) { + throw ArgumentError( + "Cannot raid between channels of different providers"); + } + final call = functions.httpsCallable('raid'); + await call({ + "provider": fromChannel.provider, + "fromChannelId": fromChannel.channelId, + "toChannelId": toChannel.channelId, + }); + } }