From 34e296959a1f30b881c55e6eb6a3f3fef0399ede Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 25 Jul 2022 09:31:29 -0700 Subject: [PATCH] Fix indexing error in conversation list search. Only allow pinning of accepted contacts --- lib/models/contact.dart | 12 ++++++++---- lib/views/contactsview.dart | 4 ++-- lib/widgets/contactrow.dart | 28 +++++++++++++++------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/models/contact.dart b/lib/models/contact.dart index eaa55a05..6580c6bb 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -73,7 +73,7 @@ class ContactInfoState extends ChangeNotifier { server, archived = false, notificationPolicy = "ConversationNotificationPolicy.Default", - pinned = false}) { + pinned = false}) { this._nickname = nickname; this._isGroup = isGroup; this._accepted = accepted; @@ -301,7 +301,7 @@ class ContactInfoState extends ChangeNotifier { void pin(context) { _pinned = true; var profileHandle = Provider.of(context, listen: false).onion; - Provider.of(context,listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "true"); + Provider.of(context, listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "true"); notifyListeners(); } @@ -309,9 +309,13 @@ class ContactInfoState extends ChangeNotifier { // Requires caller tree to contain a FlwtchState and ProfileInfoState provider. void unpin(context) { _pinned = false; - var profileHandle = Provider.of(context,listen: false).onion; - Provider.of(context,listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "false"); + var profileHandle = Provider.of(context, listen: false).onion; + Provider.of(context, listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "false"); notifyListeners(); } + // returns true only if the conversation has been accepted, and has not been blocked + bool isAccepted() { + return _accepted && !_blocked; + } } diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index f16b7a9e..f1c27139 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -227,11 +227,11 @@ class _ContactsViewState extends State { var contactList = ScrollablePositionedList.separated( itemScrollController: Provider.of(context).contactListScrollController, - itemCount: Provider.of(context).num, + itemCount: Provider.of(context).numFiltered, initialScrollIndex: initialScroll, shrinkWrap: true, physics: BouncingScrollPhysics(), - semanticChildCount: Provider.of(context).num, + semanticChildCount: Provider.of(context).numFiltered, itemBuilder: (context, index) { return tiles.elementAt(index); }, diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index 8c35cdaf..1fe8f3c0 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -19,7 +19,6 @@ class ContactRow extends StatefulWidget { } class _ContactRowState extends State { - bool isHover = false; @override @@ -127,19 +126,22 @@ class _ContactRowState extends State { ), ], ))), - - Visibility(visible: Platform.isAndroid || (!Platform.isAndroid && isHover) || contact.pinned, child: - IconButton( - tooltip: contact.pinned ? AppLocalizations.of(context)!.tooltipUnpinConversation :AppLocalizations.of(context)!.tooltipPinConversation , - icon: Icon(contact.pinned ? Icons.push_pin : Icons.push_pin_outlined, - color: Provider.of(context).theme.mainTextColor,), + Visibility( + // only allow pinning for non-blocked and accepted conversations, + visible: contact.isAccepted() && (Platform.isAndroid || (!Platform.isAndroid && isHover) || contact.pinned), + child: IconButton( + tooltip: contact.pinned ? AppLocalizations.of(context)!.tooltipUnpinConversation : AppLocalizations.of(context)!.tooltipPinConversation, + icon: Icon( + contact.pinned ? Icons.push_pin : Icons.push_pin_outlined, + color: Provider.of(context).theme.mainTextColor, + ), onPressed: () { - if (contact.pinned) { - contact.unpin(context); - } else { - contact.pin(context); - } - Provider.of(context, listen: false).resort(); + if (contact.pinned) { + contact.unpin(context); + } else { + contact.pin(context); + } + Provider.of(context, listen: false).resort(); }, )) ]),