From 2e5ee796fa7a914c532ab304e8ce922d56cc8836 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 8 Feb 2022 13:59:24 -0800 Subject: [PATCH 1/2] Add Profile Image Preview to Peer Settings + other UI Profile Image Fixups --- LIBCWTCH-GO-MACOS.version | 2 +- LIBCWTCH-GO.version | 2 +- lib/cwtch/cwtchNotifier.dart | 14 ++++---------- lib/models/contact.dart | 8 +++++++- lib/models/message.dart | 7 ++++--- lib/views/messageview.dart | 33 ++++++++++++++++++--------------- lib/views/peersettingsview.dart | 14 ++++++++++++++ lib/widgets/messagerow.dart | 2 +- lib/widgets/profileimage.dart | 7 ++++--- 9 files changed, 54 insertions(+), 35 deletions(-) diff --git a/LIBCWTCH-GO-MACOS.version b/LIBCWTCH-GO-MACOS.version index 131da5bc..00bd89ea 100644 --- a/LIBCWTCH-GO-MACOS.version +++ b/LIBCWTCH-GO-MACOS.version @@ -1 +1 @@ -2022-02-07-17-39-v1.5.4-31-g17acc3b \ No newline at end of file +2022-02-08-16-19-v1.5.4-36-g4467c40 \ No newline at end of file diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index ae1b1c97..5ec5256c 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2022-02-07-22-31-v1.5.4-31-g17acc3b \ No newline at end of file +2022-02-08-21-19-v1.5.4-36-g4467c40 \ No newline at end of file diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index d3b74765..93749b3c 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -333,16 +333,10 @@ class CwtchNotifier { profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"])!.nickname = data["Data"]; } } - } else if (data['Path'] == "profile.custom-profile-image" && data["Exists"] == "true") { - EnvironmentConfig.debugLog("received ret val of custom profile image: $data"); - String fileKey = data['Data']; - String filePath = data['FilePath']; - bool downloaded = data['FileDownloadFinished'] == "true"; - if (downloaded) { - if (profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]) != null) { - profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"])!.imagePath = filePath; - } - } else { + } else if (data['Path'] == "profile.custom-profile-image") { + if (data["Exists"] == "true") { + EnvironmentConfig.debugLog("received ret val of custom profile image: $data"); + String fileKey = data['Data']; var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.findContact(data["RemotePeer"]); if (contact != null) { profileCN.getProfile(data["ProfileOnion"])?.waitForDownloadComplete(contact.identifier, fileKey); diff --git a/lib/models/contact.dart b/lib/models/contact.dart index 38cd31cd..fe522d51 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -162,7 +162,13 @@ class ContactInfoState extends ChangeNotifier { notifyListeners(); } - String get imagePath => this._imagePath; + String get imagePath { + // don't show custom images for blocked contacts.. + if (!this.isBlocked) { + return this._imagePath; + } + return this.defaultImagePath; + } set imagePath(String newVal) { this._imagePath = newVal; diff --git a/lib/models/message.dart b/lib/models/message.dart index 6ada0469..4c6956d3 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -160,6 +160,7 @@ MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion, Future fetchAndCacheMessageInfo(BuildContext context, String profileOnion, int conversationIdentifier, CacheHandler cacheHandler) { // Load and cache + var profileInfostate = Provider.of(context, listen: false); try { Future rawMessageEnvelopeFuture; @@ -198,14 +199,14 @@ Future fetchAndCacheMessageInfo(BuildContext context, String profi var metadata = MessageMetadata(profileOnion, conversationIdentifier, messageID, timestamp, senderHandle, senderImage, signature, attributes, ackd, error, false); var messageInfo = new MessageInfo(metadata, messageWrapper['Message']); - var cache = Provider.of(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache; + var cache = profileInfostate.contactList.getContact(conversationIdentifier)?.messageCache; if (cache != null) { cacheHandler.add(cache, messageInfo, contenthash); } return messageInfo; - } catch (e) { - EnvironmentConfig.debugLog("message handler exception on parse message and cache: " + e.toString()); + } catch (e, stacktrace) { + EnvironmentConfig.debugLog("message handler exception on parse message and cache: " + e.toString() + " " + stacktrace.toString()); return null; } }); diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 3630034d..d82f2e35 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -170,21 +170,24 @@ class _MessageViewState extends State { } void _pushContactSettings() { - Navigator.of(context).push(MaterialPageRoute( - builder: (BuildContext bcontext) { - if (Provider.of(context, listen: false).isGroup == true) { - return MultiProvider( - providers: [ChangeNotifierProvider.value(value: Provider.of(context)), ChangeNotifierProvider.value(value: Provider.of(context))], - child: GroupSettingsView(), - ); - } else { - return MultiProvider( - providers: [ChangeNotifierProvider.value(value: Provider.of(context))], - child: PeerSettingsView(), - ); - } - }, - )); + var profileInfoState = Provider.of(context, listen: false); + var contactInfoState = Provider.of(context, listen: false); + + if (Provider.of(context, listen: false).isGroup == true) { + Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext bcontext) { + return MultiProvider( + providers: [ChangeNotifierProvider.value(value: profileInfoState), ChangeNotifierProvider.value(value: contactInfoState)], + child: GroupSettingsView(), + ); + })); + } else { + Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext bcontext) { + return MultiProvider( + providers: [ChangeNotifierProvider.value(value: profileInfoState), ChangeNotifierProvider.value(value: contactInfoState)], + child: PeerSettingsView(), + ); + })); + } } // todo: legacy groups currently have restricted message diff --git a/lib/views/peersettingsview.dart b/lib/views/peersettingsview.dart index 0206c175..080778ec 100644 --- a/lib/views/peersettingsview.dart +++ b/lib/views/peersettingsview.dart @@ -4,6 +4,7 @@ import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/contact.dart'; import 'package:cwtch/models/profile.dart'; +import 'package:cwtch/widgets/profileimage.dart'; import 'package:flutter/services.dart'; import 'package:cwtch/widgets/buttontextfield.dart'; import 'package:cwtch/widgets/cwtchlabel.dart'; @@ -89,6 +90,19 @@ class _PeerSettingsViewState extends State { margin: EdgeInsets.all(10), padding: EdgeInsets.all(2), child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + ProfileImage( + imagePath: Provider.of(context).isExperimentEnabled(ImagePreviewsExperiment) + ? Provider.of(context).imagePath + : Provider.of(context).defaultImagePath, + diameter: 120, + maskOut: false, + border: settings.theme.portraitOnlineBorderColor, + badgeTextColor: settings.theme.portraitContactBadgeTextColor, + badgeColor: settings.theme.portraitContactBadgeColor, + badgeEdit: false) + ]), + Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ CwtchLabel(label: AppLocalizations.of(context)!.displayNameLabel), SizedBox( diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index ad92f840..c7217448 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -167,7 +167,7 @@ class MessageRowState extends State with SingleTickerProviderStateMi child: Padding( padding: EdgeInsets.all(4.0), child: ProfileImage( - diameter: 48.0, + diameter: 64.0, // default to the contact image...otherwise use a derived sender image... imagePath: imagePath, border: contact.status == "Authenticated" ? Provider.of(context).theme.portraitOnlineBorderColor : Provider.of(context).theme.portraitOfflineBorderColor, diff --git a/lib/widgets/profileimage.dart b/lib/widgets/profileimage.dart index db2c7774..ad7e3ad7 100644 --- a/lib/widgets/profileimage.dart +++ b/lib/widgets/profileimage.dart @@ -38,9 +38,10 @@ class _ProfileImageState extends State { var file = new File(widget.imagePath); var image = Image.file( file, - cacheWidth: 512, - cacheHeight: 512, + cacheWidth: 1920, filterQuality: FilterQuality.medium, + fit: BoxFit.cover, + alignment: Alignment.center, // We need some theme specific blending here...we might want to consider making this a theme level attribute colorBlendMode: !widget.maskOut ? Provider.of(context).theme.mode == mode_dark @@ -48,7 +49,7 @@ class _ProfileImageState extends State { : BlendMode.darken : BlendMode.srcOut, color: Provider.of(context).theme.portraitBackgroundColor, - isAntiAlias: true, + isAntiAlias: false, width: widget.diameter, height: widget.diameter, errorBuilder: (context, error, stackTrace) { From 2a07ba8ed7514cce2123e9539d7bfeaad5b63558 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 8 Feb 2022 14:05:23 -0800 Subject: [PATCH 2/2] revert message row image size change --- lib/widgets/messagerow.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index c7217448..ad92f840 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -167,7 +167,7 @@ class MessageRowState extends State with SingleTickerProviderStateMi child: Padding( padding: EdgeInsets.all(4.0), child: ProfileImage( - diameter: 64.0, + diameter: 48.0, // default to the contact image...otherwise use a derived sender image... imagePath: imagePath, border: contact.status == "Authenticated" ? Provider.of(context).theme.portraitOnlineBorderColor : Provider.of(context).theme.portraitOfflineBorderColor,