diff --git a/lib/Core/l10n/app_ar.arb b/lib/Core/l10n/app_ar.arb index 6ac4341..dbe5306 100644 --- a/lib/Core/l10n/app_ar.arb +++ b/lib/Core/l10n/app_ar.arb @@ -248,6 +248,8 @@ "tripwirePints" : "نقاط Tripwire", "timer" : "المؤقت", "timerInfo" : "يقوم هذا المؤقت بتعيين الحد الأدنى من الوقت بين إشعارات Tripwire", - "tripwireUpdated" : "تم تحديث إعدادات Tripwire بنجاح" - + "tripwireUpdated" : "تم تحديث إعدادات Tripwire بنجاح", + "youHaveBlockedThisContact" : "لقد قمت بحظر جهة الاتصال هذه", + "unBlock" : "الغاء الحظر", + "youNoLongerCanSendMessages": "لم يعد بإمكانك إرسال رسائل إلى هذا الشخص" } \ No newline at end of file diff --git a/lib/Core/l10n/app_en.arb b/lib/Core/l10n/app_en.arb index 6940edc..65e7484 100644 --- a/lib/Core/l10n/app_en.arb +++ b/lib/Core/l10n/app_en.arb @@ -248,5 +248,8 @@ "tripwirePints" : "Tripwire Points", "timer" : "Timer", "timerInfo" : "This Timer Set The Minimum Time Between Notifications of Tripwire", - "tripwireUpdated" : "Tripwire Settings Updated Successfully" + "tripwireUpdated" : "Tripwire Settings Updated Successfully", + "youHaveBlockedThisContact" : "You Have Blocked This Contact", + "unBlock" : "UnBlock", + "youNoLongerCanSendMessages": "You No Longer Can Send Messages to This Person" } \ No newline at end of file diff --git a/lib/Presentation/UI/ContactChat/ContactChatView.dart b/lib/Presentation/UI/ContactChat/ContactChatView.dart index b422ca4..4824d35 100644 --- a/lib/Presentation/UI/ContactChat/ContactChatView.dart +++ b/lib/Presentation/UI/ContactChat/ContactChatView.dart @@ -152,40 +152,160 @@ class _ContactChatViewState } }, )), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 10.0, vertical: 15), - child: Row( - children: [ - Expanded( - child: TextFormField( - controller: viewModel.controller, - autovalidateMode: AutovalidateMode.onUserInteraction, - cursorColor: Theme.of(context).primaryColor, - decoration: InputDecoration( - suffixIcon: InkWell( - onTap: () => viewModel.sendMessage(), - child: Icon( - EvaIcons.paperPlane, - size: 25, - color: Theme.of(context).primaryColor, - ), - ), - prefixIcon: InkWell( - onTap: () => value.showModalBottomSheet(), - child: const Icon( - Icons.image, - size: 25, - ), - ), - hintText: value.local!.sendMessage, + if (viewModel.contact.isBlockedByFirstUser && + (viewModel.appConfigProvider!.user!.uid == + viewModel.contact.firstUserUID)) ...[ + Container( + padding: const EdgeInsets.all(20), + margin: const EdgeInsets.all(10), + width: double.infinity, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + borderRadius: BorderRadius.circular(15)), + child: Column( + children: [ + Text( + viewModel.local!.youHaveBlockedThisContact, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor), + ), + TextButton( + onPressed: () { + viewModel.unBlock(); + }, + child: Text( + viewModel.local!.unBlock, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor, + decoration: TextDecoration.underline), + )) + ], + ), + ) + ] + else if (viewModel.contact.isBlockedBySecondUser && + (viewModel.appConfigProvider!.user!.uid == + viewModel.contact.secondUserUID)) ...[ + Container( + padding: const EdgeInsets.all(20), + margin: const EdgeInsets.all(10), + width: double.infinity, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + borderRadius: BorderRadius.circular(15)), + child: Column( + children: [ + Text( + viewModel.local!.youHaveBlockedThisContact, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor), + ), + TextButton( + onPressed: () { + viewModel.unBlock(); + }, + child: Text( + viewModel.local!.unBlock, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor, + decoration: TextDecoration.underline), + )) + ], + ), + ) + ]else if (viewModel.contact.isBlockedByFirstUser && + (viewModel.appConfigProvider!.user!.uid == + viewModel.contact.secondUserUID)) ...[ + Container( + padding: const EdgeInsets.all(20), + margin: const EdgeInsets.all(10), + width: double.infinity, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + borderRadius: BorderRadius.circular(15)), + child: Column( + children: [ + Text( + viewModel.local!.youNoLongerCanSendMessages, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor), + ), + ], + ), + ) + ]else if (viewModel.contact.isBlockedBySecondUser && + (viewModel.appConfigProvider!.user!.uid == + viewModel.contact.firstUserUID)) ...[ + Container( + padding: const EdgeInsets.all(20), + margin: const EdgeInsets.all(10), + width: double.infinity, + decoration: BoxDecoration( + color: Theme.of(context).primaryColor, + borderRadius: BorderRadius.circular(15)), + child: Column( + children: [ + Text( + viewModel.local!.youNoLongerCanSendMessages, + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith( + color: Theme.of(context) + .scaffoldBackgroundColor), + ), + ], + ), + ) + ]else ...[ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10.0, vertical: 15), + child: TextFormField( + controller: viewModel.controller, + autovalidateMode: AutovalidateMode.onUserInteraction, + cursorColor: Theme.of(context).primaryColor, + decoration: InputDecoration( + suffixIcon: InkWell( + onTap: () => viewModel.sendMessage(), + child: Icon( + EvaIcons.paperPlane, + size: 25, + color: Theme.of(context).primaryColor, + ), + ), + prefixIcon: InkWell( + onTap: () => value.showModalBottomSheet(), + child: const Icon( + Icons.image, + size: 25, ), ), + hintText: value.local!.sendMessage, ), - - ], + ), ), - ), + ] ], ), ), @@ -199,7 +319,6 @@ class _ContactChatViewState return ContactChatViewModel( sendMessageUseCase: injectSendMessageUseCase(), getMessagesUseCase: injectGetMessagesUseCase(), - updateContactUseCase: injectUpdateContactUseCase() - ); + updateContactUseCase: injectUpdateContactUseCase()); } } diff --git a/lib/Presentation/UI/ContactChat/ContactChatViewModel.dart b/lib/Presentation/UI/ContactChat/ContactChatViewModel.dart index c82620c..d39c8ce 100644 --- a/lib/Presentation/UI/ContactChat/ContactChatViewModel.dart +++ b/lib/Presentation/UI/ContactChat/ContactChatViewModel.dart @@ -74,8 +74,19 @@ class ContactChatViewModel extends BaseViewModel { } // function to block contact - blockContact() { - //todo to be implemented + blockContact()async { + if(contact.firstUserUID == appConfigProvider!.user!.uid){ + contact.isBlockedByFirstUser = true; + }else{ + contact.isBlockedBySecondUser = true; + } + try { + await updateContactUseCase.invoke(contact: contact); + notifyListeners(); + } catch (e) { + navigator!.showErrorNotification(message: local!.errorSendingMessage); + notifyListeners(); + } } // function to block Contact @@ -93,4 +104,19 @@ class ContactChatViewModel extends BaseViewModel { openCamera: pickImageFromCamera, openGallery: pickImageFromGallery)); } + + unBlock()async { + if(contact.firstUserUID == appConfigProvider!.user!.uid){ + contact.isBlockedByFirstUser = false; + }else{ + contact.isBlockedBySecondUser = false; + } + try { + await updateContactUseCase.invoke(contact: contact); + notifyListeners(); + } catch (e) { + navigator!.showErrorNotification(message: local!.errorSendingMessage); + notifyListeners(); + } + } }