fix importBundle error handling and dupping of events #523
|
@ -1 +1 @@
|
||||||
2022-07-22-12-41-v1.8.0-7-g7b3e842
|
2022-08-16-10-59-v1.8.0-12-gf1de9b1
|
|
@ -1 +1 @@
|
||||||
2022-07-22-16-41-v1.8.0-7-g7b3e842
|
2022-08-16-14-59-v1.8.0-12-gf1de9b1
|
|
@ -442,7 +442,7 @@ class MainActivity: FlutterActivity() {
|
||||||
"ImportBundle" -> {
|
"ImportBundle" -> {
|
||||||
val profile: String = call.argument("ProfileOnion") ?: ""
|
val profile: String = call.argument("ProfileOnion") ?: ""
|
||||||
val bundle: String = call.argument("bundle") ?: ""
|
val bundle: String = call.argument("bundle") ?: ""
|
||||||
Cwtch.importBundle(profile, bundle)
|
result.success(Cwtch.importBundle(profile, bundle))
|
||||||
}
|
}
|
||||||
"CreateGroup" -> {
|
"CreateGroup" -> {
|
||||||
val profile: String = call.argument("ProfileOnion") ?: ""
|
val profile: String = call.argument("ProfileOnion") ?: ""
|
||||||
|
|
|
@ -91,7 +91,7 @@ abstract class Cwtch {
|
||||||
void CreateGroup(String profile, String server, String groupName);
|
void CreateGroup(String profile, String server, String groupName);
|
||||||
|
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
void ImportBundle(String profile, String bundle);
|
Future<dynamic> ImportBundle(String profile, String bundle);
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
void SetProfileAttribute(String profile, String key, String val);
|
void SetProfileAttribute(String profile, String key, String val);
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
|
|
|
@ -505,15 +505,18 @@ class CwtchFfi implements Cwtch {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
void ImportBundle(String profileOnion, String bundle) {
|
Future<dynamic> ImportBundle(String profileOnion, String bundle) async {
|
||||||
var importBundle = library.lookup<NativeFunction<string_string_to_void_function>>("c_ImportBundle");
|
var importBundle = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportBundle");
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
final ImportBundle = importBundle.asFunction<VoidFromStringStringFn>();
|
final ImportBundle = importBundle.asFunction<StringFromStringStringFn>();
|
||||||
final u1 = profileOnion.toNativeUtf8();
|
final u1 = profileOnion.toNativeUtf8();
|
||||||
final u2 = bundle.toNativeUtf8();
|
final u2 = bundle.toNativeUtf8();
|
||||||
ImportBundle(u1, u1.length, u2, u2.length);
|
Pointer<Utf8> responsePtr = ImportBundle(u1, u1.length, u2, u2.length);
|
||||||
|
String response = responsePtr.toDartString();
|
||||||
|
_UnsafeFreePointerAnyUseOfThisFunctionMustBeDoubleApproved(responsePtr);
|
||||||
malloc.free(u1);
|
malloc.free(u1);
|
||||||
malloc.free(u2);
|
malloc.free(u2);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -190,8 +190,8 @@ class CwtchGomobile implements Cwtch {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: non_constant_identifier_names
|
// ignore: non_constant_identifier_names
|
||||||
void ImportBundle(String profileOnion, String bundle) {
|
Future<dynamic> ImportBundle(String profileOnion, String bundle) {
|
||||||
cwtchPlatform.invokeMethod("ImportBundle", {"ProfileOnion": profileOnion, "bundle": bundle});
|
return cwtchPlatform.invokeMethod("ImportBundle", {"ProfileOnion": profileOnion, "bundle": bundle});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -5,23 +5,14 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
static const String successErrorType = "success";
|
static const String successErrorType = "success";
|
||||||
|
|
||||||
// Add Contact Specific Errors...
|
// Add Contact Specific Errors...
|
||||||
static const String addContactErrorPrefix = "addcontact";
|
|
||||||
static const String changePasswordErrorPrefix = "changepassword";
|
static const String changePasswordErrorPrefix = "changepassword";
|
||||||
static const String invalidImportStringErrorType = "invalid_import_string";
|
static const String invalidImportStringErrorType = "invalid_import_string";
|
||||||
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
||||||
bool invalidImportStringError = false;
|
|
||||||
bool contactAlreadyExistsError = false;
|
|
||||||
bool explicitAddContactSuccess = false;
|
|
||||||
|
|
||||||
// ChangePassword
|
// ChangePassword
|
||||||
bool changePasswordError = false;
|
bool changePasswordError = false;
|
||||||
bool explicitChangePasswordSuccess = false;
|
bool explicitChangePasswordSuccess = false;
|
||||||
|
|
||||||
// Import Bundle Specific Errors
|
|
||||||
static const String importBundleErrorPrefix = "importBundle";
|
|
||||||
bool importBundleError = false;
|
|
||||||
bool importBundleSuccess = false;
|
|
||||||
|
|
||||||
static const String deleteProfileErrorPrefix = "deleteprofile";
|
static const String deleteProfileErrorPrefix = "deleteprofile";
|
||||||
bool deleteProfileError = false;
|
bool deleteProfileError = false;
|
||||||
bool deleteProfileSuccess = false;
|
bool deleteProfileSuccess = false;
|
||||||
|
@ -31,13 +22,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
bool deletedServerSuccess = false;
|
bool deletedServerSuccess = false;
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
invalidImportStringError = false;
|
|
||||||
contactAlreadyExistsError = false;
|
|
||||||
explicitAddContactSuccess = false;
|
|
||||||
|
|
||||||
importBundleError = false;
|
|
||||||
importBundleSuccess = false;
|
|
||||||
|
|
||||||
deleteProfileError = false;
|
deleteProfileError = false;
|
||||||
deleteProfileSuccess = false;
|
deleteProfileSuccess = false;
|
||||||
|
|
||||||
|
@ -57,12 +41,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
String errorType = parts[1];
|
String errorType = parts[1];
|
||||||
|
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
case addContactErrorPrefix:
|
|
||||||
handleAddContactError(errorType);
|
|
||||||
break;
|
|
||||||
case importBundleErrorPrefix:
|
|
||||||
handleImportBundleError(errorType);
|
|
||||||
break;
|
|
||||||
case deleteProfileErrorPrefix:
|
case deleteProfileErrorPrefix:
|
||||||
handleDeleteProfileError(errorType);
|
handleDeleteProfileError(errorType);
|
||||||
break;
|
break;
|
||||||
|
@ -76,41 +54,6 @@ class ErrorHandler extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAddContactError(String errorType) {
|
|
||||||
// Reset add contact errors
|
|
||||||
invalidImportStringError = false;
|
|
||||||
contactAlreadyExistsError = false;
|
|
||||||
explicitAddContactSuccess = false;
|
|
||||||
|
|
||||||
switch (errorType) {
|
|
||||||
case invalidImportStringErrorType:
|
|
||||||
invalidImportStringError = true;
|
|
||||||
break;
|
|
||||||
case contactAlreadyExistsErrorType:
|
|
||||||
contactAlreadyExistsError = true;
|
|
||||||
break;
|
|
||||||
case successErrorType:
|
|
||||||
explicitAddContactSuccess = true;
|
|
||||||
importBundleSuccess = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleImportBundleError(String errorType) {
|
|
||||||
// Reset add contact errors
|
|
||||||
importBundleError = false;
|
|
||||||
importBundleSuccess = false;
|
|
||||||
|
|
||||||
switch (errorType) {
|
|
||||||
case successErrorType:
|
|
||||||
importBundleSuccess = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
importBundleError = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleDeleteProfileError(String errorType) {
|
handleDeleteProfileError(String errorType) {
|
||||||
// Reset add contact errors
|
// Reset add contact errors
|
||||||
deleteProfileError = false;
|
deleteProfileError = false;
|
||||||
|
|
|
@ -36,6 +36,10 @@ class _AddContactViewState extends State<AddContactView> {
|
||||||
final ctrlrContact = TextEditingController(text: "");
|
final ctrlrContact = TextEditingController(text: "");
|
||||||
final ctrlrGroupName = TextEditingController(text: "");
|
final ctrlrGroupName = TextEditingController(text: "");
|
||||||
String server = "";
|
String server = "";
|
||||||
|
// flutter textfield onChange often fires twice and since we need contexts, we can't easily use a controler/listener
|
||||||
|
String lastContactValue = "";
|
||||||
|
bool failedImport = false;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -144,34 +148,39 @@ class _AddContactViewState extends State<AddContactView> {
|
||||||
),
|
),
|
||||||
CwtchTextField(
|
CwtchTextField(
|
||||||
testKey: Key("txtAddP2P"),
|
testKey: Key("txtAddP2P"),
|
||||||
|
key: Key("txtAddP2P"),
|
||||||
controller: ctrlrContact,
|
controller: ctrlrContact,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == "") {
|
if (value == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (globalErrorHandler.invalidImportStringError) {
|
if (failedImport) {
|
||||||
return AppLocalizations.of(context)!.invalidImportString;
|
return AppLocalizations.of(context)!.invalidImportString;
|
||||||
} else if (globalErrorHandler.contactAlreadyExistsError) {
|
}
|
||||||
return AppLocalizations.of(context)!.contactAlreadyExists;
|
|
||||||
} else if (globalErrorHandler.explicitAddContactSuccess) {}
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
onChanged: (String importBundle) async {
|
onChanged: (String importBundle) async {
|
||||||
var profileOnion = Provider.of<ProfileInfoState>(bcontext, listen: false).onion;
|
if (lastContactValue != importBundle) {
|
||||||
Provider.of<FlwtchState>(bcontext, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
|
lastContactValue = importBundle;
|
||||||
|
var profileOnion = Provider
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
.of<ProfileInfoState>(bcontext, listen: false)
|
||||||
if (globalErrorHandler.importBundleSuccess) {
|
.onion;
|
||||||
// TODO: This isn't ideal, but because onChange can be fired during this future check
|
Provider
|
||||||
// and because the context can change after being popped we have this kind of double assertion...
|
.of<FlwtchState>(bcontext, listen: false)
|
||||||
// There is probably a better pattern to handle this...
|
.cwtch
|
||||||
if (AppLocalizations.of(bcontext) != null) {
|
.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", "")).then((result) {
|
||||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
if (result == "importBundle.success") {
|
||||||
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
failedImport = false;
|
||||||
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
if (AppLocalizations.of(bcontext) != null) {
|
||||||
}
|
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
||||||
}
|
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
||||||
});
|
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
failedImport = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
hintText: '',
|
hintText: '',
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue