Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 652d52b6 authored by cketti's avatar cketti
Browse files

Add setting to suppress notifications for chat messages

Messages containing a 'Chat-Version' header field will not generate notifications when this setting is enabled.
parent f6cb1f90
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public class Account implements BaseAccount {
    private FolderMode folderNotifyNewMailMode;
    private boolean notifySelfNewMail;
    private boolean notifyContactsMailOnly;
    private boolean ignoreChatMessages;
    private String legacyInboxFolder;
    private String importedDraftsFolder;
    private String importedSentFolder;
@@ -680,6 +681,14 @@ public class Account implements BaseAccount {
        this.notifyContactsMailOnly = notifyContactsMailOnly;
    }

    public synchronized boolean isIgnoreChatMessages() {
        return ignoreChatMessages;
    }

    public synchronized void setIgnoreChatMessages(boolean ignoreChatMessages) {
        this.ignoreChatMessages = ignoreChatMessages;
    }

    public synchronized Expunge getExpungePolicy() {
        return expungePolicy;
    }
+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class AccountPreferenceSerializer(
            folderNotifyNewMailMode = getEnumStringPref<FolderMode>(storage, "$accountUuid.folderNotifyNewMailMode", FolderMode.ALL)
            isNotifySelfNewMail = storage.getBoolean("$accountUuid.notifySelfNewMail", true)
            isNotifyContactsMailOnly = storage.getBoolean("$accountUuid.notifyContactsMailOnly", false)
            isIgnoreChatMessages = storage.getBoolean("$accountUuid.ignoreChatMessages", false)
            isNotifySync = storage.getBoolean("$accountUuid.notifyMailCheck", false)
            deletePolicy = DeletePolicy.fromInt(storage.getInt("$accountUuid.deletePolicy", DeletePolicy.NEVER.setting))
            legacyInboxFolder = storage.getString("$accountUuid.inboxFolderName", null)
@@ -256,6 +257,7 @@ class AccountPreferenceSerializer(
            editor.putString("$accountUuid.folderNotifyNewMailMode", folderNotifyNewMailMode.name)
            editor.putBoolean("$accountUuid.notifySelfNewMail", isNotifySelfNewMail)
            editor.putBoolean("$accountUuid.notifyContactsMailOnly", isNotifyContactsMailOnly)
            editor.putBoolean("$accountUuid.ignoreChatMessages", isIgnoreChatMessages)
            editor.putBoolean("$accountUuid.notifyMailCheck", isNotifySync)
            editor.putInt("$accountUuid.deletePolicy", deletePolicy.setting)
            editor.putString("$accountUuid.inboxFolderName", legacyInboxFolder)
@@ -379,6 +381,7 @@ class AccountPreferenceSerializer(
        editor.remove("$accountUuid.lastAutomaticCheckTime")
        editor.remove("$accountUuid.notifyNewMail")
        editor.remove("$accountUuid.notifySelfNewMail")
        editor.remove("$accountUuid.ignoreChatMessages")
        editor.remove("$accountUuid.deletePolicy")
        editor.remove("$accountUuid.draftsFolderName")
        editor.remove("$accountUuid.sentFolderName")
@@ -551,6 +554,7 @@ class AccountPreferenceSerializer(
            isNotifySync = false
            isNotifySelfNewMail = true
            isNotifyContactsMailOnly = false
            isIgnoreChatMessages = false
            folderDisplayMode = FolderMode.NOT_SECOND_CLASS
            folderSyncMode = FolderMode.FIRST_CLASS
            folderPushMode = FolderMode.NONE
+3 −0
Original line number Diff line number Diff line
@@ -261,6 +261,9 @@ public class AccountSettingsDescriptions {
        s.put("trashFolderSelection", Settings.versions(
                new V(54, new EnumSetting<>(SpecialFolderSelection.class, SpecialFolderSelection.AUTOMATIC))
        ));
        s.put("ignoreChatMessages", Settings.versions(
                new V(76, new BooleanSetting(false))
        ));
        // note that there is no setting for openPgpProvider, because this will have to be set up together
        // with the actual provider after import anyways.

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public class Settings {
     *
     * @see SettingsExporter
     */
    public static final int VERSION = 75;
    public static final int VERSION = 76;

    static Map<String, Object> validate(int version, Map<String, TreeMap<Integer, SettingsDescription>> settings,
            Map<String, String> importedSettings, boolean useDefaultValues) {
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ import com.fsck.k9.Account
import com.fsck.k9.K9
import com.fsck.k9.helper.Contacts
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.K9MailLib
import com.fsck.k9.mail.Message
import com.fsck.k9.mailstore.LocalFolder
import com.fsck.k9.mailstore.LocalFolder.isModeMismatch
import com.fsck.k9.mailstore.LocalMessage
@@ -80,6 +82,11 @@ class K9NotificationStrategy(private val contacts: Contacts) : NotificationStrat
            return false
        }

        if (account.isIgnoreChatMessages && message.isChatMessage) {
            Timber.v("No notification: Notifications for chat messages are disabled")
            return false
        }

        if (!account.isNotifySelfNewMail && account.isAnIdentity(message.from)) {
            Timber.v("No notification: Notifications for messages from yourself are disabled")
            return false
@@ -92,4 +99,7 @@ class K9NotificationStrategy(private val contacts: Contacts) : NotificationStrat

        return true
    }

    private val Message.isChatMessage: Boolean
        get() = getHeader(K9MailLib.CHAT_HEADER).isNotEmpty()
}
Loading