importBundle returns result

noAddContactDup
Dan Ballard 2 months ago
parent 5d09341277
commit d550c23fbd
  1. 2
      LIBCWTCH-GO-MACOS.version
  2. 2
      LIBCWTCH-GO.version
  3. 2
      android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt
  4. 2
      lib/cwtch/cwtch.dart
  5. 11
      lib/cwtch/ffi.dart
  6. 4
      lib/cwtch/gomobile.dart
  7. 26
      lib/errorHandler.dart
  8. 31
      lib/views/addcontactview.dart

@ -1 +1 @@
2022-08-13-14-33-v1.8.0-10-gb99e35e
2022-08-16-10-59-v1.8.0-12-gf1de9b1

@ -1 +1 @@
2022-08-13-18-34-v1.8.0-10-gb99e35e
2022-08-16-14-59-v1.8.0-12-gf1de9b1

@ -442,7 +442,7 @@ class MainActivity: FlutterActivity() {
"ImportBundle" -> {
val profile: String = call.argument("ProfileOnion") ?: ""
val bundle: String = call.argument("bundle") ?: ""
Cwtch.importBundle(profile, bundle)
result.success(Cwtch.importBundle(profile, bundle))
}
"CreateGroup" -> {
val profile: String = call.argument("ProfileOnion") ?: ""

@ -91,7 +91,7 @@ abstract class Cwtch {
void CreateGroup(String profile, String server, String groupName);
// ignore: non_constant_identifier_names
void ImportBundle(String profile, String bundle);
Future<dynamic> ImportBundle(String profile, String bundle);
// ignore: non_constant_identifier_names
void SetProfileAttribute(String profile, String key, String val);
// ignore: non_constant_identifier_names

@ -505,15 +505,18 @@ class CwtchFfi implements Cwtch {
@override
// ignore: non_constant_identifier_names
void ImportBundle(String profileOnion, String bundle) {
var importBundle = library.lookup<NativeFunction<string_string_to_void_function>>("c_ImportBundle");
Future<dynamic> ImportBundle(String profileOnion, String bundle) async {
var importBundle = library.lookup<NativeFunction<string_string_to_string_function>>("c_ImportBundle");
// ignore: non_constant_identifier_names
final ImportBundle = importBundle.asFunction<VoidFromStringStringFn>();
final ImportBundle = importBundle.asFunction<StringFromStringStringFn>();
final u1 = profileOnion.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(u2);
return response;
}
@override

@ -190,8 +190,8 @@ class CwtchGomobile implements Cwtch {
@override
// ignore: non_constant_identifier_names
void ImportBundle(String profileOnion, String bundle) {
cwtchPlatform.invokeMethod("ImportBundle", {"ProfileOnion": profileOnion, "bundle": bundle});
Future<dynamic> ImportBundle(String profileOnion, String bundle) {
return cwtchPlatform.invokeMethod("ImportBundle", {"ProfileOnion": profileOnion, "bundle": bundle});
}
@override

@ -13,11 +13,6 @@ class ErrorHandler extends ChangeNotifier {
bool changePasswordError = false;
bool explicitChangePasswordSuccess = false;
// Import Bundle Specific Errors
static const String importBundleErrorPrefix = "importBundle";
bool importBundleError = false;
bool importBundleSuccess = false;
static const String deleteProfileErrorPrefix = "deleteprofile";
bool deleteProfileError = false;
bool deleteProfileSuccess = false;
@ -27,9 +22,6 @@ class ErrorHandler extends ChangeNotifier {
bool deletedServerSuccess = false;
reset() {
importBundleError = false;
importBundleSuccess = false;
deleteProfileError = false;
deleteProfileSuccess = false;
@ -49,9 +41,6 @@ class ErrorHandler extends ChangeNotifier {
String errorType = parts[1];
switch (prefix) {
case importBundleErrorPrefix:
handleImportBundleError(errorType);
break;
case deleteProfileErrorPrefix:
handleDeleteProfileError(errorType);
break;
@ -65,21 +54,6 @@ class ErrorHandler extends ChangeNotifier {
notifyListeners();
}
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) {
// Reset add contact errors
deleteProfileError = false;

@ -38,6 +38,7 @@ class _AddContactViewState extends State<AddContactView> {
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
@ -153,9 +154,9 @@ class _AddContactViewState extends State<AddContactView> {
if (value == "") {
return null;
}
if (globalErrorHandler.importBundleError) {
if (failedImport) {
return AppLocalizations.of(context)!.invalidImportString;
} else if (globalErrorHandler.importBundleSuccess) { return null; }
}
return null;
},
onChanged: (String importBundle) async {
@ -167,20 +168,18 @@ class _AddContactViewState extends State<AddContactView> {
Provider
.of<FlwtchState>(bcontext, listen: false)
.cwtch
.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
Future.delayed(const Duration(milliseconds: 500), () {
if (globalErrorHandler.importBundleSuccess) {
// TODO: This isn't ideal, but because onChange can be fired during this future check
// and because the context can change after being popped we have this kind of double assertion...
// There is probably a better pattern to handle this...
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");
}
}
});
.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", "")).then((result) {
if (result == "importBundle.success") {
failedImport = false;
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: '',

Loading…
Cancel
Save