diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 874b1226..8fd6ba34 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -72,7 +72,8 @@ class CwtchNotifier { } EnvironmentConfig.debugLog("NewPeer $data"); // if tag != v1-defaultPassword then it is either encrypted OR it is an unencrypted account created during pre-beta... - profileCN.add(data["Identity"], data["name"], data["picture"], data["defaultPicture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["autostart"] == "true", data["tag"] != "v1-defaultPassword"); + profileCN.add(data["Identity"], data["name"], data["picture"], data["defaultPicture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["autostart"] == "true", + data["tag"] != "v1-defaultPassword"); break; case "ContactCreated": EnvironmentConfig.debugLog("ContactCreated $data"); @@ -310,12 +311,16 @@ class CwtchNotifier { profileCN.getProfile(data["ProfileOnion"])?.replaceServers(data["ServerList"]); break; case "TokenManagerInfo": - List associatedGroups = jsonDecode(data["Data"]); - int count = int.parse(data["ServerTokenCount"]); - associatedGroups.forEach((identifier) { - profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(identifier.toString()))!.antispamTickets = count; - }); - EnvironmentConfig.debugLog("update server token count for ${associatedGroups}, $count"); + try { + List associatedGroups = jsonDecode(data["Data"]); + int count = int.parse(data["ServerTokenCount"]); + associatedGroups.forEach((identifier) { + profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(int.parse(identifier.toString()))!.antispamTickets = count; + }); + EnvironmentConfig.debugLog("update server token count for ${associatedGroups}, $count"); + } catch (e) { + // No tokens in data... + } break; case "NewGroup": String invite = data["GroupInvite"].toString(); diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 7d24b308..0abe9b5b 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -124,6 +124,10 @@ class ProfileInfoState extends ChangeNotifier { // Check encrypted status for profile info screen bool get isEncrypted => this._encrypted; + set isEncrypted(bool newValue) { + this._encrypted = newValue; + notifyListeners(); + } String get nickname => this._nickname; diff --git a/lib/models/profilelist.dart b/lib/models/profilelist.dart index 14ed466b..3c85a5de 100644 --- a/lib/models/profilelist.dart +++ b/lib/models/profilelist.dart @@ -13,7 +13,15 @@ class ProfileListState extends ChangeNotifier { var idx = _profiles.indexWhere((element) => element.onion == onion); if (idx == -1) { _profiles.add(ProfileInfoState( - onion: onion, nickname: name, imagePath: picture, defaultImagePath: defaultPicture, contactsJson: contactsJson, serversJson: serverJson, online: online, autostart: autostart, encrypted: encrypted)); + onion: onion, + nickname: name, + imagePath: picture, + defaultImagePath: defaultPicture, + contactsJson: contactsJson, + serversJson: serverJson, + online: online, + autostart: autostart, + encrypted: encrypted)); } else { _profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online); } diff --git a/lib/themes/ghost.dart b/lib/themes/ghost.dart index 86674440..8eceed3d 100644 --- a/lib/themes/ghost.dart +++ b/lib/themes/ghost.dart @@ -26,7 +26,7 @@ class GhostDark extends CwtchDark { static final Color peerBubble = darkBlue; static final Color font = Colors.white; static final Color settings = Color(0xFFFDFFFD); - static final Color accent = lightBlue;//Color(0xFFD20070); + static final Color accent = lightBlue; //Color(0xFFD20070); get theme => ghost_theme; get mode => mode_dark; diff --git a/lib/themes/midnight.dart b/lib/themes/midnight.dart index 4333a965..9e102f52 100644 --- a/lib/themes/midnight.dart +++ b/lib/themes/midnight.dart @@ -49,7 +49,7 @@ class MidnightDark extends CwtchDark { } class MidnightLight extends CwtchLight { - static final Color background = Color(0xFFFBFBFB);//Color(0xFFFFFDFF); + static final Color background = Color(0xFFFBFBFB); //Color(0xFFFFFDFF); static final Color header = Color(0xFFE0E0E0); static final Color userBubble = Color(0xFFE0E0E0); static final Color peerBubble = Color(0xFFBABDBE); diff --git a/lib/views/addeditprofileview.dart b/lib/views/addeditprofileview.dart index b172a1af..7498d712 100644 --- a/lib/views/addeditprofileview.dart +++ b/lib/views/addeditprofileview.dart @@ -199,7 +199,9 @@ class _AddEditProfileViewState extends State { Provider.of(context).autostart = value; if (!Provider.of(context).onion.isEmpty) { - Provider.of(context, listen: false).cwtch.SetProfileAttribute(Provider.of(context).onion, "profile.autostart", value ? "true" : "false"); + Provider.of(context, listen: false) + .cwtch + .SetProfileAttribute(Provider.of(context).onion, "profile.autostart", value ? "true" : "false"); } }, activeTrackColor: Provider.of(context).theme.defaultButtonColor, @@ -207,7 +209,6 @@ class _AddEditProfileViewState extends State { secondary: Icon(CwtchIcons.favorite_24dp, color: Provider.of(context).current().mainTextColor), ), - Visibility( visible: Provider.of(context).onion.isEmpty, child: SizedBox( @@ -418,7 +419,9 @@ class _AddEditProfileViewState extends State { var profile = Provider.of(context, listen: false).onion; Provider.of(context, listen: false).nickname = ctrlrNick.value.text; Provider.of(context, listen: false).cwtch.SetProfileAttribute(profile, "profile.name", ctrlrNick.value.text); - Provider.of(context, listen: false).cwtch.ChangePassword(profile, ctrlrOldPass.text, ctrlrPass.text, ctrlrPass2.text); + // Use default password if the profile is unencrypted + var password = Provider.of(context, listen: false).isEncrypted ? ctrlrOldPass.text : DefaultPassword; + Provider.of(context, listen: false).cwtch.ChangePassword(profile, password, ctrlrPass.text, ctrlrPass2.text); EnvironmentConfig.debugLog("waiting for change password response"); Future.delayed(const Duration(milliseconds: 500), () { @@ -434,6 +437,8 @@ class _AddEditProfileViewState extends State { } }).whenComplete(() { if (globalErrorHandler.explicitChangePasswordSuccess) { + // we need to set the local encrypted status to display correct password forms on this run... + Provider.of(context, listen: false).isEncrypted = true; final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.newPassword)); ScaffoldMessenger.of(context).showSnackBar(snackBar); Navigator.pop(context); diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 3806c1a2..fdf51c6d 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -95,70 +95,73 @@ class _ContactsViewState extends State { @override Widget build(BuildContext context) { - return ScaffoldMessenger(key: scaffoldKey, child: Scaffold( - endDrawerEnableOpenDragGesture: false, - drawerEnableOpenDragGesture: false, - appBar: AppBar( - leading: Stack(children: [ - Align( - alignment: Alignment.center, - child: IconButton( - icon: Icon(Icons.arrow_back), - tooltip: MaterialLocalizations.of(context).backButtonTooltip, - onPressed: () { - Provider.of(context, listen: false).recountUnread(); - Provider.of(context, listen: false).selectedProfile = ""; - Navigator.of(context).pop(); - }, - )), - Positioned( - bottom: 5.0, - right: 5.0, - child: StreamBuilder( - stream: Provider.of(context).getUnreadProfileNotifyStream(), - builder: (BuildContext context, AsyncSnapshot unreadCountSnapshot) { - int unreadCount = Provider.of(context).generateUnreadCount(Provider.of(context).selectedProfile ?? ""); + return ScaffoldMessenger( + key: scaffoldKey, + child: Scaffold( + endDrawerEnableOpenDragGesture: false, + drawerEnableOpenDragGesture: false, + appBar: AppBar( + leading: Stack(children: [ + Align( + alignment: Alignment.center, + child: IconButton( + icon: Icon(Icons.arrow_back), + tooltip: MaterialLocalizations.of(context).backButtonTooltip, + onPressed: () { + Provider.of(context, listen: false).recountUnread(); + Provider.of(context, listen: false).selectedProfile = ""; + Navigator.of(context).pop(); + }, + )), + Positioned( + bottom: 5.0, + right: 5.0, + child: StreamBuilder( + stream: Provider.of(context).getUnreadProfileNotifyStream(), + builder: (BuildContext context, AsyncSnapshot unreadCountSnapshot) { + int unreadCount = Provider.of(context).generateUnreadCount(Provider.of(context).selectedProfile ?? ""); - return Visibility( - visible: unreadCount > 0, - child: CircleAvatar( - radius: 10.0, - backgroundColor: Provider.of(context).theme.portraitProfileBadgeColor, - child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)), - )); - }), - ) - ]), - title: Row(children: [ - ProfileImage( - imagePath: Provider.of(context).isExperimentEnabled(ImagePreviewsExperiment) - ? Provider.of(context).imagePath - : Provider.of(context).defaultImagePath, - diameter: 42, - border: Provider.of(context).isOnline - ? Provider.of(context).current().portraitOnlineBorderColor - : Provider.of(context).current().portraitOfflineBorderColor, - badgeTextColor: Colors.red, - badgeColor: Colors.red, + return Visibility( + visible: unreadCount > 0, + child: CircleAvatar( + radius: 10.0, + backgroundColor: Provider.of(context).theme.portraitProfileBadgeColor, + child: + Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)), + )); + }), + ) + ]), + title: Row(children: [ + ProfileImage( + imagePath: Provider.of(context).isExperimentEnabled(ImagePreviewsExperiment) + ? Provider.of(context).imagePath + : Provider.of(context).defaultImagePath, + diameter: 42, + border: Provider.of(context).isOnline + ? Provider.of(context).current().portraitOnlineBorderColor + : Provider.of(context).current().portraitOfflineBorderColor, + badgeTextColor: Colors.red, + badgeColor: Colors.red, + ), + SizedBox( + width: 10, + ), + Expanded( + child: Text("%1 » %2".replaceAll("%1", Provider.of(context).nickname).replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts), + overflow: TextOverflow.ellipsis, style: TextStyle(color: Provider.of(context).current().mainTextColor))), + ]), + actions: getActions(context), ), - SizedBox( - width: 10, + floatingActionButton: FloatingActionButton( + onPressed: _modalAddImportChoice, + tooltip: AppLocalizations.of(context)!.tooltipAddContact, + child: Icon( + CwtchIcons.person_add_alt_1_24px, + color: Provider.of(context).theme.defaultButtonTextColor, + ), ), - Expanded( - child: Text("%1 » %2".replaceAll("%1", Provider.of(context).nickname).replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts), - overflow: TextOverflow.ellipsis, style: TextStyle(color: Provider.of(context).current().mainTextColor))), - ]), - actions: getActions(context), - ), - floatingActionButton: FloatingActionButton( - onPressed: _modalAddImportChoice, - tooltip: AppLocalizations.of(context)!.tooltipAddContact, - child: Icon( - CwtchIcons.person_add_alt_1_24px, - color: Provider.of(context).theme.defaultButtonTextColor, - ), - ), - body: showSearchBar || Provider.of(context).isFiltered ? _buildFilterable() : _buildContactList())); + body: showSearchBar || Provider.of(context).isFiltered ? _buildFilterable() : _buildContactList())); } List getActions(context) { diff --git a/lib/widgets/profileimage.dart b/lib/widgets/profileimage.dart index cc6a2c54..bd729a31 100644 --- a/lib/widgets/profileimage.dart +++ b/lib/widgets/profileimage.dart @@ -82,15 +82,17 @@ class _ProfileImageState extends State { width: widget.diameter, height: widget.diameter, color: widget.border, - foregroundDecoration: widget.disabled ? BoxDecoration( - color: Provider.of(context).theme.portraitBackgroundColor, //Colors.grey, - backgroundBlendMode: BlendMode.color, //saturation, - ) : null, + foregroundDecoration: widget.disabled + ? BoxDecoration( + color: Provider.of(context).theme.portraitBackgroundColor, //Colors.grey, + backgroundBlendMode: BlendMode.color, //saturation, + ) + : null, child: Padding( padding: const EdgeInsets.all(2.0), //border size child: ClipOval(clipBehavior: Clip.antiAlias, child: widget.tooltip == "" ? image : Tooltip(message: widget.tooltip, child: image))))), - // badge - Visibility( + // badge + Visibility( visible: widget.badgeIcon != null || widget.badgeEdit || widget.badgeCount > 0, child: Positioned( bottom: 0.0, @@ -107,22 +109,17 @@ class _ProfileImageState extends State { ), )), // disabled center icon - Visibility( - visible: widget.disabled, - child: Container( - width: widget.diameter, - height: widget.diameter, - child: - Center( - - - child: Icon( - CwtchIcons.negative_heart_24px, - size: widget.diameter / 1.5, - color: Provider.of(context).theme.portraitOfflineBorderColor, - ) - - ))), + Visibility( + visible: widget.disabled, + child: Container( + width: widget.diameter, + height: widget.diameter, + child: Center( + child: Icon( + CwtchIcons.negative_heart_24px, + size: widget.diameter / 1.5, + color: Provider.of(context).theme.portraitOfflineBorderColor, + )))), ])); } }