From cac9f46d98d5fc77cf40e7da6e1ba5c5b99d1db2 Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Wed, 9 Feb 2022 18:50:17 -0500 Subject: [PATCH] Fix blocking, user modal tweaks --- ios/Podfile.lock | 2 +- lib/core/user/user_store.dart | 16 ++--- lib/core/user/user_store.g.dart | 8 ++- .../channel/chat/widgets/chat_user_modal.dart | 59 +++++++++---------- lib/widgets/block_button.dart | 6 +- lib/widgets/block_report_modal.dart | 42 ++++++------- 6 files changed, 70 insertions(+), 63 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index f1197200..cdb42d18 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -78,7 +78,7 @@ SPEC CHECKSUMS: sentry_flutter: 7c3cb050dc23563a4ea5db438c83afdb460a2ae6 shared_preferences_ios: aef470a42dc4675a1cdd50e3158b42e3d1232b32 sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904 - url_launcher_ios: 02f1989d4e14e998335b02b67a7590fa34f971af + url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de webview_flutter_wkwebview: 005fbd90c888a42c5690919a1527ecc6649e1162 PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c diff --git a/lib/core/user/user_store.dart b/lib/core/user/user_store.dart index 1cc39d97..b2841807 100644 --- a/lib/core/user/user_store.dart +++ b/lib/core/user/user_store.dart @@ -17,7 +17,7 @@ abstract class _UserStoreBase with Store { @readonly var _blockedUsers = ObservableList(); - ReactionDisposer? disposeReaction; + late final ReactionDisposer disposeReaction; _UserStoreBase({required this.twitchApi}); @@ -33,12 +33,14 @@ abstract class _UserStoreBase with Store { } @action - Future block({required String targetId, required Map headers}) async { + Future block({ + required String targetId, + required String displayName, + required Map headers, + }) async { final success = await twitchApi.blockUser(userId: targetId, headers: headers); - // Add a slight delay between requests, otherwise the blocked list won't properly update. - // Weird behavior, might be something to do with PUT request and time to create and update resource? - await Future.delayed(const Duration(milliseconds: 300)); - if (success) await refreshBlockedUsers(headers: headers); + + if (success) _blockedUsers.add(UserBlockedTwitch(targetId, displayName, displayName)); } @action @@ -55,6 +57,6 @@ abstract class _UserStoreBase with Store { void dispose() { _details = null; _blockedUsers.clear(); - if (disposeReaction != null) disposeReaction!(); + disposeReaction(); } } diff --git a/lib/core/user/user_store.g.dart b/lib/core/user/user_store.g.dart index 3c340166..f5f94f98 100644 --- a/lib/core/user/user_store.g.dart +++ b/lib/core/user/user_store.g.dart @@ -54,9 +54,11 @@ mixin _$UserStore on _UserStoreBase, Store { @override Future block( - {required String targetId, required Map headers}) { - return _$blockAsyncAction - .run(() => super.block(targetId: targetId, headers: headers)); + {required String targetId, + required String displayName, + required Map headers}) { + return _$blockAsyncAction.run(() => super + .block(targetId: targetId, displayName: displayName, headers: headers)); } final _$unblockAsyncAction = AsyncAction('_UserStoreBase.unblock'); diff --git a/lib/screens/channel/chat/widgets/chat_user_modal.dart b/lib/screens/channel/chat/widgets/chat_user_modal.dart index f3f3393a..c219cb81 100644 --- a/lib/screens/channel/chat/widgets/chat_user_modal.dart +++ b/lib/screens/channel/chat/widgets/chat_user_modal.dart @@ -2,9 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:frosty/screens/channel/chat/widgets/chat_message.dart'; import 'package:frosty/screens/channel/stores/chat_store.dart'; -import 'package:frosty/widgets/block_button.dart'; +import 'package:frosty/widgets/block_report_modal.dart'; import 'package:frosty/widgets/profile_picture.dart'; -import 'package:frosty/widgets/report_button.dart'; import 'package:frosty/widgets/section_header.dart'; class ChatUserModal extends StatelessWidget { @@ -37,22 +36,35 @@ class ChatUserModal extends StatelessWidget { leading: ProfilePicture( userLogin: username, ), - title: Text( - displayName, - style: const TextStyle(fontWeight: FontWeight.bold), + title: Row( + children: [ + Text( + displayName, + style: const TextStyle(fontWeight: FontWeight.bold), + ), + IconButton( + tooltip: 'Block or Report User', + onPressed: () => showModalBottomSheet( + context: context, + builder: (context) => BlockReportModal( + authStore: chatStore.auth, + name: displayName, + userLogin: username, + userId: userId, + ), + ), + icon: const Icon(Icons.report), + ), + ], ), trailing: chatStore.auth.isLoggedIn - ? Row( - mainAxisSize: MainAxisSize.min, - children: [ - ReportButton(userLogin: username), - const SizedBox(width: 10.0), - BlockButton( - authStore: chatStore.auth, - targetUser: username, - targetUserId: userId, - ), - ], + ? OutlinedButton( + onPressed: () { + chatStore.textController.text = '@$username '; + Navigator.pop(context); + chatStore.textFieldFocusNode.requestFocus(); + }, + child: const Text('Reply'), ) : null, ), @@ -89,21 +101,6 @@ class ChatUserModal extends StatelessWidget { ), ), ), - Container( - width: double.infinity, - padding: const EdgeInsets.symmetric( - horizontal: 10.0, - vertical: 5.0, - ), - child: OutlinedButton( - onPressed: () { - chatStore.textController.text = '@$username '; - Navigator.pop(context); - chatStore.textFieldFocusNode.requestFocus(); - }, - child: const Text('Reply'), - ), - ), ], ), ), diff --git a/lib/widgets/block_button.dart b/lib/widgets/block_button.dart index f4b988f0..8f12c688 100644 --- a/lib/widgets/block_button.dart +++ b/lib/widgets/block_button.dart @@ -38,7 +38,11 @@ class BlockButton extends StatelessWidget { if (isBlocked) { authStore.user.unblock(targetId: targetUserId, headers: authStore.headersTwitch); } else { - authStore.user.block(targetId: targetUserId, headers: authStore.headersTwitch); + authStore.user.block( + targetId: targetUserId, + displayName: targetUser, + headers: authStore.headersTwitch, + ); } Navigator.pop(context); }, diff --git a/lib/widgets/block_report_modal.dart b/lib/widgets/block_report_modal.dart index 8d88cf7c..91dfd7c9 100644 --- a/lib/widgets/block_report_modal.dart +++ b/lib/widgets/block_report_modal.dart @@ -19,28 +19,30 @@ class BlockReportModal extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.symmetric(horizontal: 10.0), - width: double.infinity, - child: BlockButton( - authStore: authStore, - targetUser: name, - targetUserId: userId, - simple: false, + return SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + width: double.infinity, + child: BlockButton( + authStore: authStore, + targetUser: name, + targetUserId: userId, + simple: false, + ), ), - ), - Container( - padding: const EdgeInsets.symmetric(horizontal: 10.0), - width: double.infinity, - child: ReportButton( - userLogin: userLogin, - name: name, + Container( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + width: double.infinity, + child: ReportButton( + userLogin: userLogin, + name: name, + ), ), - ), - ], + ], + ), ); } }