Fixup RemoveContact (still has the reconnection issue, but does implement purge)

This commit is contained in:
Sarah Jamie Lewis 2022-02-03 10:03:41 -08:00
parent 1527f555ac
commit dde6b791c5
5 changed files with 38 additions and 23 deletions

View File

@ -122,8 +122,8 @@ class ProfileInfoState extends ChangeNotifier {
// Remove a contact from a list. Currently only used when rejecting a group invitation. // Remove a contact from a list. Currently only used when rejecting a group invitation.
// Eventually will also be used for other removals. // Eventually will also be used for other removals.
void removeContact(String handle) { void removeContact(int handle) {
this.contactList.removeContactByHandle(handle); this.contactList.removeContact(handle);
notifyListeners(); notifyListeners();
} }

View File

@ -151,7 +151,7 @@ class _GroupSettingsViewState extends State<GroupSettingsView> {
Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog 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), label: Text(AppLocalizations.of(context)!.archiveConversation),
)), )),
SizedBox( SizedBox(
@ -198,8 +198,6 @@ class _GroupSettingsViewState extends State<GroupSettingsView> {
onPressed: () { onPressed: () {
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion; var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier; var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
// locally update cache...
Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
Provider.of<ProfileInfoState>(context, listen: false).contactList.removeContact(identifier); Provider.of<ProfileInfoState>(context, listen: false).contactList.removeContact(identifier);
Provider.of<FlwtchState>(context, listen: false).cwtch.DeleteContact(profileOnion, identifier); Provider.of<FlwtchState>(context, listen: false).cwtch.DeleteContact(profileOnion, identifier);
Future.delayed(Duration(milliseconds: 500), () { Future.delayed(Duration(milliseconds: 500), () {

View File

@ -167,7 +167,7 @@ class _MessageViewState extends State<MessageView> {
); );
} else { } else {
return MultiProvider( return MultiProvider(
providers: [ChangeNotifierProvider.value(value: Provider.of<ContactInfoState>(context))], providers: [ChangeNotifierProvider.value(value: Provider.of<ContactInfoState>(context)), ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context))],
child: PeerSettingsView(), child: PeerSettingsView(),
); );
} }

View File

@ -3,6 +3,7 @@ import 'dart:ui';
import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:cwtch/cwtch_icons_icons.dart';
import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/appstate.dart';
import 'package:cwtch/models/contact.dart'; import 'package:cwtch/models/contact.dart';
import 'package:cwtch/models/profile.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:cwtch/widgets/buttontextfield.dart'; import 'package:cwtch/widgets/buttontextfield.dart';
import 'package:cwtch/widgets/cwtchlabel.dart'; import 'package:cwtch/widgets/cwtchlabel.dart';
@ -197,30 +198,46 @@ class _PeerSettingsViewState extends State<PeerSettingsView> {
); );
}).toList())), }).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<ContactInfoState>(context, listen: false).profileOnion;
var handle = Provider.of<ContactInfoState>(context, listen: false).identifier;
// locally update cache...
Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
Provider.of<FlwtchState>(context, listen: false).cwtch.ArchiveConversation(profileOnion, handle);
Future.delayed(Duration(milliseconds: 500), () {
Provider.of<AppState>(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( SizedBox(
height: 20, height: 20,
), ),
Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [ Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [
Tooltip( Tooltip(
message: AppLocalizations.of(context)!.archiveConversation, message: AppLocalizations.of(context)!.leaveGroup,
child: ElevatedButton.icon( child: TextButton.icon(
onPressed: () { onPressed: () {
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion; showAlertDialog(context);
var handle = Provider.of<ContactInfoState>(context, listen: false).identifier;
// locally update cache...
Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
Provider.of<FlwtchState>(context, listen: false).cwtch.ArchiveConversation(profileOnion, handle);
Future.delayed(Duration(milliseconds: 500), () {
Provider.of<AppState>(context, listen: false).selectedConversation = null;
Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog
});
}, },
icon: Icon(CwtchIcons.leave_chat), style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.transparent)),
label: Text(AppLocalizations.of(context)!.archiveConversation), icon: Icon(CwtchIcons.leave_group),
label: Text(
AppLocalizations.of(context)!.leaveGroup,
style: TextStyle(decoration: TextDecoration.underline),
),
)) ))
]) ])
]), ])
]))))); ])))));
}); });
}); });
@ -247,8 +264,8 @@ class _PeerSettingsViewState extends State<PeerSettingsView> {
onPressed: () { onPressed: () {
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion; var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var handle = Provider.of<ContactInfoState>(context, listen: false).identifier; var handle = Provider.of<ContactInfoState>(context, listen: false).identifier;
Provider.of<ProfileInfoState>(context).removeContact(handle);
// locally update cache... // locally update cache...
Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
Provider.of<FlwtchState>(context, listen: false).cwtch.DeleteContact(profileOnion, handle); Provider.of<FlwtchState>(context, listen: false).cwtch.DeleteContact(profileOnion, handle);
Future.delayed(Duration(milliseconds: 500), () { Future.delayed(Duration(milliseconds: 500), () {
Provider.of<AppState>(context, listen: false).selectedConversation = null; Provider.of<AppState>(context, listen: false).selectedConversation = null;

View File

@ -136,7 +136,7 @@ class _ContactRowState extends State<ContactRow> {
ContactInfoState contact = Provider.of<ContactInfoState>(context, listen: false); ContactInfoState contact = Provider.of<ContactInfoState>(context, listen: false);
if (contact.isGroup == true) { if (contact.isGroup == true) {
// FIXME This flow is incorrect. Groups never just show up on the contact list anymore // FIXME This flow is incorrect. Groups never just show up on the contact list anymore
Provider.of<ProfileInfoState>(context, listen: false).removeContact(contact.onion); Provider.of<ProfileInfoState>(context, listen: false).removeContact(contact.identifier);
} else { } else {
Provider.of<FlwtchState>(context, listen: false).cwtch.BlockContact(Provider.of<ContactInfoState>(context, listen: false).profileOnion, contact.identifier); Provider.of<FlwtchState>(context, listen: false).cwtch.BlockContact(Provider.of<ContactInfoState>(context, listen: false).profileOnion, contact.identifier);
} }