Fix indexing error in conversation list search.
continuous-integration/drone/pr Build is passing Details

Only allow pinning of accepted contacts
This commit is contained in:
Sarah Jamie Lewis 2022-07-25 09:31:29 -07:00
parent d4d7a54af1
commit 34e296959a
3 changed files with 25 additions and 19 deletions

View File

@ -73,7 +73,7 @@ class ContactInfoState extends ChangeNotifier {
server, server,
archived = false, archived = false,
notificationPolicy = "ConversationNotificationPolicy.Default", notificationPolicy = "ConversationNotificationPolicy.Default",
pinned = false}) { pinned = false}) {
this._nickname = nickname; this._nickname = nickname;
this._isGroup = isGroup; this._isGroup = isGroup;
this._accepted = accepted; this._accepted = accepted;
@ -301,7 +301,7 @@ class ContactInfoState extends ChangeNotifier {
void pin(context) { void pin(context) {
_pinned = true; _pinned = true;
var profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion; var profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(context,listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "true"); Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "true");
notifyListeners(); notifyListeners();
} }
@ -309,9 +309,13 @@ class ContactInfoState extends ChangeNotifier {
// Requires caller tree to contain a FlwtchState and ProfileInfoState provider. // Requires caller tree to contain a FlwtchState and ProfileInfoState provider.
void unpin(context) { void unpin(context) {
_pinned = false; _pinned = false;
var profileHandle = Provider.of<ProfileInfoState>(context,listen: false).onion; var profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(context,listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "false"); Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "false");
notifyListeners(); notifyListeners();
} }
// returns true only if the conversation has been accepted, and has not been blocked
bool isAccepted() {
return _accepted && !_blocked;
}
} }

View File

@ -227,11 +227,11 @@ class _ContactsViewState extends State<ContactsView> {
var contactList = ScrollablePositionedList.separated( var contactList = ScrollablePositionedList.separated(
itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController, itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController,
itemCount: Provider.of<ContactListState>(context).num, itemCount: Provider.of<ContactListState>(context).numFiltered,
initialScrollIndex: initialScroll, initialScrollIndex: initialScroll,
shrinkWrap: true, shrinkWrap: true,
physics: BouncingScrollPhysics(), physics: BouncingScrollPhysics(),
semanticChildCount: Provider.of<ContactListState>(context).num, semanticChildCount: Provider.of<ContactListState>(context).numFiltered,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return tiles.elementAt(index); return tiles.elementAt(index);
}, },

View File

@ -19,7 +19,6 @@ class ContactRow extends StatefulWidget {
} }
class _ContactRowState extends State<ContactRow> { class _ContactRowState extends State<ContactRow> {
bool isHover = false; bool isHover = false;
@override @override
@ -127,19 +126,22 @@ class _ContactRowState extends State<ContactRow> {
), ),
], ],
))), ))),
Visibility(
Visibility(visible: Platform.isAndroid || (!Platform.isAndroid && isHover) || contact.pinned, child: // only allow pinning for non-blocked and accepted conversations,
IconButton( visible: contact.isAccepted() && (Platform.isAndroid || (!Platform.isAndroid && isHover) || contact.pinned),
tooltip: contact.pinned ? AppLocalizations.of(context)!.tooltipUnpinConversation :AppLocalizations.of(context)!.tooltipPinConversation , child: IconButton(
icon: Icon(contact.pinned ? Icons.push_pin : Icons.push_pin_outlined, tooltip: contact.pinned ? AppLocalizations.of(context)!.tooltipUnpinConversation : AppLocalizations.of(context)!.tooltipPinConversation,
color: Provider.of<Settings>(context).theme.mainTextColor,), icon: Icon(
contact.pinned ? Icons.push_pin : Icons.push_pin_outlined,
color: Provider.of<Settings>(context).theme.mainTextColor,
),
onPressed: () { onPressed: () {
if (contact.pinned) { if (contact.pinned) {
contact.unpin(context); contact.unpin(context);
} else { } else {
contact.pin(context); contact.pin(context);
} }
Provider.of<ContactListState>(context, listen: false).resort(); Provider.of<ContactListState>(context, listen: false).resort();
}, },
)) ))
]), ]),