From 1527f555ac80b5457b7421cfbde9bc6cd62fdb12 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 3 Feb 2022 09:14:22 -0800 Subject: [PATCH] Fix contact.server NSE in contact list sync state --- lib/cwtch/cwtchNotifier.dart | 8 ++++---- lib/models/contact.dart | 2 +- lib/widgets/contactrow.dart | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index c697ea00..7b9668f6 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -71,9 +71,9 @@ class CwtchNotifier { savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"], numMessages: int.parse(data["numMessages"]), numUnread: int.parse(data["unread"]), - isGroup: data["isGroup"] == true, - server: data["groupServer"], - archived: data["isArchived"] == true, + isGroup: false, // by definition + server: null, + archived: false, lastMessageTime: DateTime.now(), //show at the top of the contact list even if no messages yet )); break; @@ -220,7 +220,7 @@ class CwtchNotifier { notificationManager.notify("New Message From Group!"); } - RemoteServerInfoState? server = profileCN.getProfile(data["ProfileOnion"])?.serverList.getServer(contact.server); + RemoteServerInfoState? server = profileCN.getProfile(data["ProfileOnion"])?.serverList.getServer(contact.server ?? ""); server?.updateSyncProgressFor(timestampSent); } else { // This is dealt with by IndexedAcknowledgment diff --git a/lib/models/contact.dart b/lib/models/contact.dart index 5ac0edd4..7f840747 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -174,7 +174,7 @@ class ContactInfoState extends ChangeNotifier { } // we only allow callers to fetch the server - get server => this._server; + String? get server => this._server; bool isOnline() { if (this.isGroup == true) { diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index b61b8ffa..cdad4f77 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -24,6 +24,18 @@ class _ContactRowState extends State { @override Widget build(BuildContext context) { var contact = Provider.of(context); + + // Only groups have a sync status + Widget? syncStatus; + if (contact.isGroup) { + syncStatus = Visibility( + visible: contact.isGroup && contact.status == "Authenticated", + child: LinearProgressIndicator( + color: Provider.of(context).theme.defaultButtonActiveColor, + value: Provider.of(context).serverList.getServer(contact.server ?? "")?.syncProgress, + )); + } + return Card( clipBehavior: Clip.antiAlias, color: Provider.of(context).selectedConversation == contact.identifier ? Provider.of(context).theme.backgroundHilightElementColor : null, @@ -63,12 +75,7 @@ class _ContactRowState extends State { softWrap: true, overflow: TextOverflow.visible, ), - Visibility( - visible: contact.isGroup && contact.status == "Authenticated", - child: LinearProgressIndicator( - color: Provider.of(context).theme.defaultButtonActiveColor, - value: Provider.of(context).serverList.getServer(contact.server)?.syncProgress, - )), + syncStatus ?? Container(), Visibility( visible: !Provider.of(context).streamerMode, child: Text(contact.onion, @@ -128,7 +135,7 @@ class _ContactRowState extends State { Provider.of(context, listen: false).blocked = true; ContactInfoState contact = Provider.of(context, listen: false); if (contact.isGroup == true) { - // FIXME This flow is incrorect. 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(context, listen: false).removeContact(contact.onion); } else { Provider.of(context, listen: false).cwtch.BlockContact(Provider.of(context, listen: false).profileOnion, contact.identifier);