diff --git a/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index 2356e89d0..fc2b7b497 100644 --- a/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -38,6 +38,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme private CheckBoxPreference ignoreBattery; private CheckBoxPreference notificationsEnabled; private CheckBoxPreference mentionNotifEnabled; + private CheckBoxPreference reliableService; @Override public void onCreate(Bundle paramBundle) { @@ -85,7 +86,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme } - CheckBoxPreference reliableService = this.findPreference("pref_reliable_service"); + reliableService = this.findPreference("pref_reliable_service"); if (reliableService != null) { reliableService.setOnPreferenceChangeListener((preference, newValue) -> { Context context = getContext(); @@ -132,6 +133,10 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme ignoreBattery.setChecked(isIgnoringBatteryOptimizations()); notificationsEnabled.setChecked(!dcContext.isMuted()); mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled()); + if (Prefs.reliableService(getActivity())) { + // only alter the "unset" state of the preference if true + reliableService.setChecked(true); + } } @Override diff --git a/src/main/java/org/thoughtcrime/securesms/util/Prefs.java b/src/main/java/org/thoughtcrime/securesms/util/Prefs.java index 4df6b2deb..8096857e5 100644 --- a/src/main/java/org/thoughtcrime/securesms/util/Prefs.java +++ b/src/main/java/org/thoughtcrime/securesms/util/Prefs.java @@ -12,10 +12,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import com.b44t.messenger.DcAccounts; import com.b44t.messenger.DcContext; import org.thoughtcrime.securesms.BuildConfig; import org.thoughtcrime.securesms.connect.DcHelper; +import org.thoughtcrime.securesms.notifications.FcmReceiveService; import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference; import java.util.ArrayList; @@ -212,13 +214,36 @@ public class Prefs { return result==null? null : Uri.parse(result); } + private static boolean isAllChatmail(Context context) { + DcAccounts dcAccounts = DcHelper.getAccounts(context); + for (int accountId : dcAccounts.getAll()) { + DcContext dcContext = dcAccounts.getAccount(accountId); + if (!dcContext.isChatmail()) { + return false; + } + } + return true; + } + public static boolean reliableService(Context context) { + final String key = "pref_reliable_service"; + boolean value = false; try { - return getBooleanPreference(context, "pref_reliable_service", false); + value = getBooleanPreference(context, key, false); + } catch(Exception e) {} + boolean value2; + try { + value2 = getBooleanPreference(context, key, !value); + } catch(Exception e) { + value2 = !value; } - catch(Exception e) { - return false; + + // if the key was unset, then calculate default value + if (value != value2) { + value = FcmReceiveService.getToken() == null || !isAllChatmail(context); } + + return value; } // vibrate