From ee2fd2ae98b2535aaac4e88e2a358095b5512e37 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 22 Jun 2021 12:44:36 -0700 Subject: [PATCH 1/3] Fix DeleteProfile in Android --- android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt | 4 ++-- lib/cwtch/gomobile.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt index 48f908c..90d751c 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt @@ -181,8 +181,8 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) : } "DeleteProfile" -> { val profile = (a.get("ProfileOnion") as? String) ?: "" - val groupHandle = (a.get("pass") as? String) ?: "" - Cwtch.deleteProfile(profile, groupHandle) + val pass = (a.get("pass") as? String) ?: "" + Cwtch.deleteProfile(profile, pass) } "LeaveConversation" -> { val profile = (a.get("ProfileOnion") as? String) ?: "" diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index 06e3a05..d9be08c 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -83,7 +83,7 @@ class CwtchGomobile implements Cwtch { // ignore: non_constant_identifier_names void DeleteProfile(String onion, String pass) { - cwtchPlatform.invokeMethod("DeleteProfile", {"onion": onion, "pass": pass}); + cwtchPlatform.invokeMethod("DeleteProfile", {"ProfileOnion": onion, "pass": pass}); } // ignore: non_constant_identifier_names From 066c1965e6402f22c903305ceadbb2cc8c7b8cc3 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 22 Jun 2021 17:03:36 -0700 Subject: [PATCH 2/3] Fix Reconnect Woes --- LIBCWTCH-GO.version | 2 +- .../kotlin/im/cwtch/flwtch/MainActivity.kt | 8 +++ lib/cwtch/cwtchNotifier.dart | 3 +- lib/model.dart | 49 ++++++++++++++++--- lib/settings.dart | 2 +- lib/views/torstatusview.dart | 2 +- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index 1552c0d..0bc6904 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -v0.0.2-99-gc864bcc-2021-06-22-00-52 \ No newline at end of file +v0.0.2-104-gc1b7e4c-2021-06-22-23-59 \ No newline at end of file diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt index da889d7..93c740a 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt @@ -142,6 +142,14 @@ class MainActivity: FlutterActivity() { myReceiver = MyBroadcastReceiver(mc) LocalBroadcastManager.getInstance(applicationContext).registerReceiver(myReceiver!!, filter) } + + // ReconnectCwtchForeground which will resync counters and settings... + // We need to do this here because after a "pause" flutter is still running + // but we might have lost sync with the background process... + Log.i("MainActivity.kt", "Call ReconnectCwtchForeground") + val data: Data = Data.Builder().putString(FlwtchWorker.KEY_METHOD, "ReconnectCwtchForeground").putString(FlwtchWorker.KEY_ARGS, "{}").build() + val workRequest = OneTimeWorkRequestBuilder().setInputData(data).build() + WorkManager.getInstance(applicationContext).enqueue(workRequest) } override fun onStop() { diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 251dad6..bb564e6 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -37,8 +37,7 @@ class CwtchNotifier { appState.SetAppError(data["Error"]); break; case "NewPeer": - profileCN.add(ProfileInfoState( - onion: data["Identity"], nickname: data["name"], imagePath: data["picture"], contactsJson: data["ContactsJson"], serversJson: data["ServerList"], online: data["Online"] == "true")); + profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true"); break; case "PeerCreated": profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState( diff --git a/lib/model.dart b/lib/model.dart index 93d6f34..a6ffb47 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -38,13 +38,13 @@ class ProfileListState extends ChangeNotifier { List _profiles = []; int get num => _profiles.length; - void addAll(Iterable newProfiles) { - _profiles.addAll(newProfiles); - notifyListeners(); - } - - void add(ProfileInfoState newProfile) { - _profiles.add(newProfile); + void add(String onion, String name, String picture, String contactsJson, String serverJson, bool online) { + var idx = _profiles.indexWhere((element) => element.onion == onion); + if (idx == -1) { + _profiles.add(ProfileInfoState(onion: onion, nickname: name, imagePath: picture, contactsJson: contactsJson, serversJson: serverJson, online: online)); + } else { + _profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online); + } notifyListeners(); } @@ -261,6 +261,41 @@ class ProfileInfoState extends ChangeNotifier { super.dispose(); print("profileinfostate.dispose()"); } + + void updateFrom(String onion, String name, String picture, String contactsJson, String serverJson, bool online) { + this._nickname = name; + this._imagePath = picture; + this._online = online; + this.replaceServers(serverJson); + + if (contactsJson != null && contactsJson != "" && contactsJson != "null") { + List contacts = jsonDecode(contactsJson); + contacts.forEach((contact) { + var profileContact = this._contacts.getContact(contact["onion"]); + if (profileContact != null) { + profileContact.status = contact["status"]; + profileContact.totalMessages = contact["numMessages"]; + profileContact.lastMessageTime = DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])); + } else { + this._contacts.add(ContactInfoState( + this.onion, + contact["onion"], + nickname: contact["name"], + status: contact["status"], + imagePath: contact["picture"], + isBlocked: contact["authorization"] == "blocked", + isInvitation: contact["authorization"] == "unknown", + savePeerHistory: contact["saveConversationHistory"], + numMessages: contact["numMessages"], + numUnread: contact["numUnread"], + isGroup: contact["isGroup"], + server: contact["groupServer"], + lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])), + )); + } + }); + } + } } class ContactInfoState extends ChangeNotifier { diff --git a/lib/settings.dart b/lib/settings.dart index 0b52cbb..cea6eff 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -20,7 +20,7 @@ class Settings extends ChangeNotifier { bool experimentsEnabled = false; HashMap experiments = HashMap.identity(); - late bool blockUnknownConnections; + bool blockUnknownConnections = false; /// Set the dark theme. void setDark() { diff --git a/lib/views/torstatusview.dart b/lib/views/torstatusview.dart index 43bb5f0..e3f445d 100644 --- a/lib/views/torstatusview.dart +++ b/lib/views/torstatusview.dart @@ -55,7 +55,7 @@ class _TorStatusView extends State { ListTile( title: Text(AppLocalizations.of(context)!.torVersion), subtitle: Text(torStatus.version), - ), + ), ])))); }); }); From 94014ede016a8b8fa6e0fcddfd3c79ed8678671a Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 22 Jun 2021 17:49:05 -0700 Subject: [PATCH 3/3] bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6f843e1..31814d3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+13 +version: 1.0.0+14 environment: sdk: ">=2.12.0 <3.0.0"