From dde6b791c5a761aa1733228df18b93a090f68d0c Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 3 Feb 2022 10:03:41 -0800 Subject: [PATCH] Fixup RemoveContact (still has the reconnection issue, but does implement purge) --- lib/models/profile.dart | 4 +-- lib/views/groupsettingsview.dart | 4 +-- lib/views/messageview.dart | 2 +- lib/views/peersettingsview.dart | 49 +++++++++++++++++++++----------- lib/widgets/contactrow.dart | 2 +- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 268eeb78..ba618f8b 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -122,8 +122,8 @@ class ProfileInfoState extends ChangeNotifier { // Remove a contact from a list. Currently only used when rejecting a group invitation. // Eventually will also be used for other removals. - void removeContact(String handle) { - this.contactList.removeContactByHandle(handle); + void removeContact(int handle) { + this.contactList.removeContact(handle); notifyListeners(); } diff --git a/lib/views/groupsettingsview.dart b/lib/views/groupsettingsview.dart index 18855e7e..d64c4907 100644 --- a/lib/views/groupsettingsview.dart +++ b/lib/views/groupsettingsview.dart @@ -151,7 +151,7 @@ class _GroupSettingsViewState extends State { Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog }); }, - icon: Icon(CwtchIcons.leave_chat), + icon: Icon(Icons.archive), label: Text(AppLocalizations.of(context)!.archiveConversation), )), SizedBox( @@ -198,8 +198,6 @@ class _GroupSettingsViewState extends State { onPressed: () { var profileOnion = Provider.of(context, listen: false).profileOnion; var identifier = Provider.of(context, listen: false).identifier; - // locally update cache... - Provider.of(context, listen: false).isArchived = true; Provider.of(context, listen: false).contactList.removeContact(identifier); Provider.of(context, listen: false).cwtch.DeleteContact(profileOnion, identifier); Future.delayed(Duration(milliseconds: 500), () { diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 8db678ff..8d060cd3 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -167,7 +167,7 @@ class _MessageViewState extends State { ); } else { return MultiProvider( - providers: [ChangeNotifierProvider.value(value: Provider.of(context))], + providers: [ChangeNotifierProvider.value(value: Provider.of(context)), ChangeNotifierProvider.value(value: Provider.of(context))], child: PeerSettingsView(), ); } diff --git a/lib/views/peersettingsview.dart b/lib/views/peersettingsview.dart index 0ab762ee..405a6e76 100644 --- a/lib/views/peersettingsview.dart +++ b/lib/views/peersettingsview.dart @@ -3,6 +3,7 @@ import 'dart:ui'; import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/contact.dart'; +import 'package:cwtch/models/profile.dart'; import 'package:flutter/services.dart'; import 'package:cwtch/widgets/buttontextfield.dart'; import 'package:cwtch/widgets/cwtchlabel.dart'; @@ -197,30 +198,46 @@ class _PeerSettingsViewState extends State { ); }).toList())), ]), - Column(mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ + Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [ + SizedBox( + height: 20, + ), + Tooltip( + message: AppLocalizations.of(context)!.archiveConversation, + child: ElevatedButton.icon( + onPressed: () { + var profileOnion = Provider.of(context, listen: false).profileOnion; + var handle = Provider.of(context, listen: false).identifier; + // locally update cache... + Provider.of(context, listen: false).isArchived = true; + Provider.of(context, listen: false).cwtch.ArchiveConversation(profileOnion, handle); + Future.delayed(Duration(milliseconds: 500), () { + Provider.of(context, listen: false).selectedConversation = null; + Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog + }); + }, + icon: Icon(Icons.archive), + label: Text(AppLocalizations.of(context)!.archiveConversation), + )), SizedBox( height: 20, ), Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [ Tooltip( - message: AppLocalizations.of(context)!.archiveConversation, - child: ElevatedButton.icon( + message: AppLocalizations.of(context)!.leaveGroup, + child: TextButton.icon( onPressed: () { - var profileOnion = Provider.of(context, listen: false).profileOnion; - var handle = Provider.of(context, listen: false).identifier; - // locally update cache... - Provider.of(context, listen: false).isArchived = true; - Provider.of(context, listen: false).cwtch.ArchiveConversation(profileOnion, handle); - Future.delayed(Duration(milliseconds: 500), () { - Provider.of(context, listen: false).selectedConversation = null; - Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog - }); + showAlertDialog(context); }, - icon: Icon(CwtchIcons.leave_chat), - label: Text(AppLocalizations.of(context)!.archiveConversation), + style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.transparent)), + icon: Icon(CwtchIcons.leave_group), + label: Text( + AppLocalizations.of(context)!.leaveGroup, + style: TextStyle(decoration: TextDecoration.underline), + ), )) ]) - ]), + ]) ]))))); }); }); @@ -247,8 +264,8 @@ class _PeerSettingsViewState extends State { onPressed: () { var profileOnion = Provider.of(context, listen: false).profileOnion; var handle = Provider.of(context, listen: false).identifier; + Provider.of(context).removeContact(handle); // locally update cache... - Provider.of(context, listen: false).isArchived = true; Provider.of(context, listen: false).cwtch.DeleteContact(profileOnion, handle); Future.delayed(Duration(milliseconds: 500), () { Provider.of(context, listen: false).selectedConversation = null; diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index cdad4f77..246917db 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -136,7 +136,7 @@ class _ContactRowState extends State { ContactInfoState contact = Provider.of(context, listen: false); if (contact.isGroup == true) { // FIXME This flow is incorrect. Groups never just show up on the contact list anymore - Provider.of(context, listen: false).removeContact(contact.onion); + Provider.of(context, listen: false).removeContact(contact.identifier); } else { Provider.of(context, listen: false).cwtch.BlockContact(Provider.of(context, listen: false).profileOnion, contact.identifier); }