forked from cwtch.im/cwtch-ui
Fix Change Password for Unencrypted Profiles / Handle TokenUpdates with No Tokens / Format
This commit is contained in:
parent
7ee619f1a6
commit
27a729d09a
|
@ -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<dynamic> 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<dynamic> 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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -199,7 +199,9 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
|
|||
Provider.of<ProfileInfoState>(context).autostart = value;
|
||||
|
||||
if (!Provider.of<ProfileInfoState>(context).onion.isEmpty) {
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(Provider.of<ProfileInfoState>(context).onion, "profile.autostart", value ? "true" : "false");
|
||||
Provider.of<FlwtchState>(context, listen: false)
|
||||
.cwtch
|
||||
.SetProfileAttribute(Provider.of<ProfileInfoState>(context).onion, "profile.autostart", value ? "true" : "false");
|
||||
}
|
||||
},
|
||||
activeTrackColor: Provider.of<Settings>(context).theme.defaultButtonColor,
|
||||
|
@ -207,7 +209,6 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
|
|||
secondary: Icon(CwtchIcons.favorite_24dp, color: Provider.of<Settings>(context).current().mainTextColor),
|
||||
),
|
||||
|
||||
|
||||
Visibility(
|
||||
visible: Provider.of<ProfileInfoState>(context).onion.isEmpty,
|
||||
child: SizedBox(
|
||||
|
@ -418,7 +419,9 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
|
|||
var profile = Provider.of<ProfileInfoState>(context, listen: false).onion;
|
||||
Provider.of<ProfileInfoState>(context, listen: false).nickname = ctrlrNick.value.text;
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(profile, "profile.name", ctrlrNick.value.text);
|
||||
Provider.of<FlwtchState>(context, listen: false).cwtch.ChangePassword(profile, ctrlrOldPass.text, ctrlrPass.text, ctrlrPass2.text);
|
||||
// Use default password if the profile is unencrypted
|
||||
var password = Provider.of<ProfileInfoState>(context, listen: false).isEncrypted ? ctrlrOldPass.text : DefaultPassword;
|
||||
Provider.of<FlwtchState>(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<AddEditProfileView> {
|
|||
}
|
||||
}).whenComplete(() {
|
||||
if (globalErrorHandler.explicitChangePasswordSuccess) {
|
||||
// we need to set the local encrypted status to display correct password forms on this run...
|
||||
Provider.of<ProfileInfoState>(context, listen: false).isEncrypted = true;
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.newPassword));
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
Navigator.pop(context);
|
||||
|
|
|
@ -95,70 +95,73 @@ class _ContactsViewState extends State<ContactsView> {
|
|||
|
||||
@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<ProfileInfoState>(context, listen: false).recountUnread();
|
||||
Provider.of<AppState>(context, listen: false).selectedProfile = "";
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)),
|
||||
Positioned(
|
||||
bottom: 5.0,
|
||||
right: 5.0,
|
||||
child: StreamBuilder<bool>(
|
||||
stream: Provider.of<AppState>(context).getUnreadProfileNotifyStream(),
|
||||
builder: (BuildContext context, AsyncSnapshot<bool> unreadCountSnapshot) {
|
||||
int unreadCount = Provider.of<ProfileListState>(context).generateUnreadCount(Provider.of<AppState>(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<ProfileInfoState>(context, listen: false).recountUnread();
|
||||
Provider.of<AppState>(context, listen: false).selectedProfile = "";
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)),
|
||||
Positioned(
|
||||
bottom: 5.0,
|
||||
right: 5.0,
|
||||
child: StreamBuilder<bool>(
|
||||
stream: Provider.of<AppState>(context).getUnreadProfileNotifyStream(),
|
||||
builder: (BuildContext context, AsyncSnapshot<bool> unreadCountSnapshot) {
|
||||
int unreadCount = Provider.of<ProfileListState>(context).generateUnreadCount(Provider.of<AppState>(context).selectedProfile ?? "");
|
||||
|
||||
return Visibility(
|
||||
visible: unreadCount > 0,
|
||||
child: CircleAvatar(
|
||||
radius: 10.0,
|
||||
backgroundColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
|
||||
child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)),
|
||||
));
|
||||
}),
|
||||
)
|
||||
]),
|
||||
title: Row(children: [
|
||||
ProfileImage(
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
|
||||
? Provider.of<ProfileInfoState>(context).imagePath
|
||||
: Provider.of<ProfileInfoState>(context).defaultImagePath,
|
||||
diameter: 42,
|
||||
border: Provider.of<ProfileInfoState>(context).isOnline
|
||||
? Provider.of<Settings>(context).current().portraitOnlineBorderColor
|
||||
: Provider.of<Settings>(context).current().portraitOfflineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
badgeColor: Colors.red,
|
||||
return Visibility(
|
||||
visible: unreadCount > 0,
|
||||
child: CircleAvatar(
|
||||
radius: 10.0,
|
||||
backgroundColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
|
||||
child:
|
||||
Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)),
|
||||
));
|
||||
}),
|
||||
)
|
||||
]),
|
||||
title: Row(children: [
|
||||
ProfileImage(
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
|
||||
? Provider.of<ProfileInfoState>(context).imagePath
|
||||
: Provider.of<ProfileInfoState>(context).defaultImagePath,
|
||||
diameter: 42,
|
||||
border: Provider.of<ProfileInfoState>(context).isOnline
|
||||
? Provider.of<Settings>(context).current().portraitOnlineBorderColor
|
||||
: Provider.of<Settings>(context).current().portraitOfflineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
badgeColor: Colors.red,
|
||||
),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Expanded(
|
||||
child: Text("%1 » %2".replaceAll("%1", Provider.of<ProfileInfoState>(context).nickname).replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts),
|
||||
overflow: TextOverflow.ellipsis, style: TextStyle(color: Provider.of<Settings>(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<Settings>(context).theme.defaultButtonTextColor,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text("%1 » %2".replaceAll("%1", Provider.of<ProfileInfoState>(context).nickname).replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts),
|
||||
overflow: TextOverflow.ellipsis, style: TextStyle(color: Provider.of<Settings>(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<Settings>(context).theme.defaultButtonTextColor,
|
||||
),
|
||||
),
|
||||
body: showSearchBar || Provider.of<ContactListState>(context).isFiltered ? _buildFilterable() : _buildContactList()));
|
||||
body: showSearchBar || Provider.of<ContactListState>(context).isFiltered ? _buildFilterable() : _buildContactList()));
|
||||
}
|
||||
|
||||
List<Widget> getActions(context) {
|
||||
|
|
|
@ -82,15 +82,17 @@ class _ProfileImageState extends State<ProfileImage> {
|
|||
width: widget.diameter,
|
||||
height: widget.diameter,
|
||||
color: widget.border,
|
||||
foregroundDecoration: widget.disabled ? BoxDecoration(
|
||||
color: Provider.of<Settings>(context).theme.portraitBackgroundColor, //Colors.grey,
|
||||
backgroundBlendMode: BlendMode.color, //saturation,
|
||||
) : null,
|
||||
foregroundDecoration: widget.disabled
|
||||
? BoxDecoration(
|
||||
color: Provider.of<Settings>(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<ProfileImage> {
|
|||
),
|
||||
)),
|
||||
// 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<Settings>(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<Settings>(context).theme.portraitOfflineBorderColor,
|
||||
)))),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue