allow to toggle direct mentions notifications in muted chats

This commit is contained in:
adbenitez
2024-11-30 13:16:05 +01:00
parent 79e5eedab0
commit 30a63dd13b
5 changed files with 28 additions and 0 deletions
@@ -86,6 +86,7 @@ public class DcContext {
public final static int DC_CONNECTIVITY_CONNECTED = 4000;
private static final String CONFIG_ACCOUNT_ENABLED = "ui.enabled";
private static final String CONFIG_MENTION_NOTIF_ENABLED = "ui.notify_mentions";
// when using DcAccounts, use DcAccounts.addAccount() instead
public DcContext(String osName, String dbfile) {
@@ -226,6 +227,14 @@ public class DcContext {
}
}
public boolean isMentionsEnabled() {
return !"0".equals(getConfig(CONFIG_MENTION_NOTIF_ENABLED));
}
public void setMentionsEnabled(boolean enabled) {
setConfigInt(CONFIG_MENTION_NOTIF_ENABLED, enabled? 1 : 0);
}
public String getName() {
String displayname = getConfig("displayname");
if (displayname.isEmpty()) {
@@ -416,6 +416,7 @@ public class NotificationCenter {
DcContext dcContext = context.dcAccounts.getAccount(accountId);
int chatId = dcChat.getId();
ChatData chatData = new ChatData(accountId, chatId);
isMention = isMention && dcContext.isMentionsEnabled();
if (dcContext.isMuted() || (!isMention && dcChat.isMuted())) {
return;
@@ -36,6 +36,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
private CheckBoxPreference ignoreBattery;
private CheckBoxPreference notificationsEnabled;
private CheckBoxPreference mentionNotifEnabled;
@Override
public void onCreate(Bundle paramBundle) {
@@ -99,6 +100,13 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
dcContext.setMuted(!enabled);
return true;
});
mentionNotifEnabled = this.findPreference("pref_enable_mention_notifications");
mentionNotifEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
boolean enabled = (Boolean) newValue;
dcContext.setMentionsEnabled(enabled);
return true;
});
}
@Override
@@ -114,6 +122,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
// update ignoreBattery in onResume() to reflects changes done in the system settings
ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
notificationsEnabled.setChecked(!dcContext.isMuted());
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
}
@Override