Skip to content

Commit

Permalink
fix: call raid endpoint (#1070)
Browse files Browse the repository at this point in the history
* fix: call raid endpoint

* actions adapter
  • Loading branch information
kevmo314 authored Sep 16, 2023
1 parent 2407d53 commit 0471ce4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/components/drawer/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -127,18 +128,19 @@ class _DrawerHeader extends StatelessWidget {
onChannelSelect: (channel) {
model.activeChannel = channel;
},
onRaid:
userChannel == model.activeChannel &&
userChannel != null
? (channel) {
final userModel =
Provider.of<UserModel>(
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,
);
},
Expand Down
22 changes: 22 additions & 0 deletions lib/models/adapters/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class ActionsAdapter {
functions: FirebaseFunctions.instance);
static ActionsAdapter? _instance;

Future<void> send(Channel channel, String message) async {
final call = functions.httpsCallable('send');
await call({
"provider": channel.provider,
"channelId": channel.channelId,
"message": message,
});
}

Future<void> ban(Channel channel, String username) async {
final call = functions.httpsCallable('ban');
await call({
Expand Down Expand Up @@ -51,4 +60,17 @@ class ActionsAdapter {
"messageId": messageId,
});
}

Future<void> 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,
});
}
}

0 comments on commit 0471ce4

Please sign in to comment.