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,
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<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();
}
@ -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<ProfileInfoState>(context,listen: false).onion;
Provider.of<FlwtchState>(context,listen: false).cwtch.SetConversationAttribute(profileHandle, identifier, "profile.pinned", "false");
var profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
Provider.of<FlwtchState>(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;
}
}

View File

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

View File

@ -19,7 +19,6 @@ class ContactRow extends StatefulWidget {
}
class _ContactRowState extends State<ContactRow> {
bool isHover = false;
@override
@ -127,19 +126,22 @@ class _ContactRowState extends State<ContactRow> {
),
],
))),
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<Settings>(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<Settings>(context).theme.mainTextColor,
),
onPressed: () {
if (contact.pinned) {
contact.unpin(context);
} else {
contact.pin(context);
}
Provider.of<ContactListState>(context, listen: false).resort();
if (contact.pinned) {
contact.unpin(context);
} else {
contact.pin(context);
}
Provider.of<ContactListState>(context, listen: false).resort();
},
))
]),