Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call raid endpoint #1070

Merged
merged 4 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
}
}
Loading