Prevent Android from Wiping Unsaved Conversations Every Time the Foreground Reloads
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2024-02-26 18:19:20 -08:00
parent 7cea83d141
commit da0d63b0dc
Signed by: sarah
GPG Key ID: F27FD21A270837EF
3 changed files with 26 additions and 15 deletions

View File

@ -1 +1 @@
2024-02-26-09-28-v0.0.13
2024-02-26-18-01-v0.0.14

View File

@ -177,6 +177,9 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
.build()
notificationManager.notify(getNotificationID(data.getString("ProfileOnion"), channelId), newNotification)
if (fh != null) {
fh.close()
}
}
}

View File

@ -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":