From da0d63b0dc5465755ff60f1c1089410eebe62ab7 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 26 Feb 2024 18:19:20 -0800 Subject: [PATCH] Prevent Android from Wiping Unsaved Conversations Every Time the Foreground Reloads --- LIBCWTCH-GO.version | 2 +- .../kotlin/im/cwtch/flwtch/FlwtchWorker.kt | 3 ++ lib/cwtch/cwtchNotifier.dart | 36 +++++++++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index 79b03a0d..ef6dfd02 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2024-02-26-09-28-v0.0.13 \ No newline at end of file +2024-02-26-18-01-v0.0.14 \ No newline at end of file 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 66f429ff..548716a6 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/FlwtchWorker.kt @@ -177,6 +177,9 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) : .build() notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), channelId), newNotification) + if (fh != null) { + fh.close() + } } } diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 0dd710f8..b0c03958 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -58,7 +58,14 @@ class CwtchNotifier { // EnvironmentConfig.debugLog("NewEvent $type $data"); switch (type) { case "CwtchStarted": - flwtchState.cwtch.LoadProfiles(DefaultPassword); + if (data["Reload"] == "true" && profileCN.num > 0 ) { + // don't reload... + // unless we have loaded no profiles...then there isnt a risk and this + // might be a first time (e.g. new apk, existing service) + } else { + EnvironmentConfig.debugLog("Reloading....${data}"); + flwtchState.cwtch.LoadProfiles(DefaultPassword); + } appState.SetCwtchInit(); break; case "CwtchStartError": @@ -188,21 +195,9 @@ class CwtchNotifier { var senderImage = data['picture']; var isAuto = data['Auto'] == "true"; String contenthash = data['ContentHash']; + var selectedProfile = appState.selectedProfile == data["ProfileOnion"]; var selectedConversation = selectedProfile && appState.selectedConversation == identifier; - var notification = data["notification"]; - - if (selectedConversation && seenMessageCallback != null) { - seenMessageCallback!(data["ProfileOnion"]!, identifier, DateTime.now().toUtc()); - } - - if (notification == "SimpleEvent") { - notificationManager.notify(notificationSimple ?? "New Message", "", 0); - } else if (notification == "ContactInfo") { - var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier); - notificationManager.notify((notificationConversationInfo ?? "New Message from %1").replaceFirst("%1", (contact?.nickname ?? senderHandle.toString())), data["ProfileOnion"], identifier); - } - profileCN.getProfile(data["ProfileOnion"])?.newMessage( identifier, messageID, @@ -215,6 +210,19 @@ class CwtchNotifier { selectedProfile, selectedConversation, ); + + // Now perform the notification logic... + var notification = data["notification"]; + if (selectedConversation && seenMessageCallback != null) { + seenMessageCallback!(data["ProfileOnion"]!, identifier, DateTime.now().toUtc()); + } + + if (notification == "SimpleEvent") { + notificationManager.notify(notificationSimple ?? "New Message", "", 0); + } else if (notification == "ContactInfo") { + var contact = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier); + notificationManager.notify((notificationConversationInfo ?? "New Message from %1").replaceFirst("%1", (contact?.nickname ?? senderHandle.toString())), data["ProfileOnion"], identifier); + } appState.notifyProfileUnread(); break; case "PeerAcknowledgement":