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

Unverified Commit e229254e authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #5574 from k9mail/no_notification_on_first_sync

Don't create notifications when first syncing a folder
parents beaefd84 eb1b3109
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ import com.fsck.k9.mail.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mailstore.FolderDetailsAccessor;
import com.fsck.k9.mailstore.ListenableMessageStore;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
@@ -679,9 +681,13 @@ public class MessagingController {
            return;
        }

        MessageStore messageStore = messageStoreManager.getMessageStore(account);
        Long lastChecked = messageStore.getFolder(folderId, FolderDetailsAccessor::getLastChecked);
        boolean suppressNotifications = lastChecked == null;

        String folderServerId = localFolder.getServerId();
        SyncConfig syncConfig = createSyncConfig(account);
        ControllerSyncListener syncListener = new ControllerSyncListener(account, listener);
        ControllerSyncListener syncListener = new ControllerSyncListener(account, listener, suppressNotifications);

        backend.sync(folderServerId, syncConfig, syncListener);

@@ -2477,9 +2483,6 @@ public class MessagingController {
            showFetchingMailNotificationIfNecessary(account, folder);
            try {
                synchronizeMailboxSynchronous(account, folder.getDatabaseId(), listener);

                long now = System.currentTimeMillis();
                folder.setLastChecked(now);
            } finally {
                clearFetchingMailNotificationIfNecessary(account);
            }
@@ -2716,12 +2719,14 @@ public class MessagingController {
        private final MessagingListener listener;
        private final LocalStore localStore;
        private final int previousUnreadMessageCount;
        private final boolean suppressNotifications;
        boolean syncFailed = false;


        ControllerSyncListener(Account account, MessagingListener listener) {
        ControllerSyncListener(Account account, MessagingListener listener, boolean suppressNotifications) {
            this.account = account;
            this.listener = listener;
            this.suppressNotifications = suppressNotifications;
            this.localStore = getLocalStoreOrThrow(account);

            previousUnreadMessageCount = getUnreadMessageCount(account);
@@ -2778,7 +2783,8 @@ public class MessagingController {
            // Send a notification of this message
            LocalMessage message = loadMessage(folderServerId, messageServerId);
            LocalFolder localFolder = message.getFolder();
            if (notificationStrategy.shouldNotifyForMessage(account, localFolder, message, isOldMessage)) {
            if (!suppressNotifications &&
                    notificationStrategy.shouldNotifyForMessage(account, localFolder, message, isOldMessage)) {
                Timber.v("Creating notification for message %s:%s", localFolder.getName(), message.getUid());
                // Notify with the localMessage so that we don't have to recalculate the content preview.
                notificationController.addNewMailNotification(account, message, previousUnreadMessageCount);
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ interface FolderDetailsAccessor {
    val pushClass: FolderClass
    val visibleLimit: Int
    val moreMessages: MoreMessages
    val lastChecked: Long?
    val unreadMessageCount: Int
    val starredMessageCount: Int

+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class K9BackendFolder(
    }

    override fun setLastChecked(timestamp: Long) {
        messageStore.setLastUpdated(folderId, timestamp)
        messageStore.setLastChecked(folderId, timestamp)
    }

    override fun setStatus(status: String?) {
+9 −11
Original line number Diff line number Diff line
@@ -351,16 +351,6 @@ public class LocalFolder {
        }
    }

    public void setLastChecked(final long lastChecked) throws MessagingException {
        try {
            open();
            this.lastChecked = lastChecked;
        } catch (MessagingException e) {
            throw new WrappedException(e);
        }
        updateFolderColumn("last_updated", lastChecked);
    }

    public int getVisibleLimit() throws MessagingException {
        open();
        return visibleLimit;
@@ -1124,6 +1114,7 @@ public class LocalFolder {
                        db.execSQL("DELETE FROM messages WHERE folder_id = ?", folderIdArg);

                        setMoreMessages(MoreMessages.UNKNOWN);
                        resetLastChecked(db);

                        return null;
                    } catch (MessagingException e) {
@@ -1137,10 +1128,17 @@ public class LocalFolder {

        this.localStore.notifyChange();

        setLastChecked(0);
        setVisibleLimit(getAccount().getDisplayCount());
    }

    private void resetLastChecked(SQLiteDatabase db) {
        lastChecked = 0;

        ContentValues values = new ContentValues();
        values.putNull("last_updated");
        db.update("folders", values, "id = ?", new String[] { Long.toString(databaseId) });
    }

    public void destroyLocalOnlyMessages() throws MessagingException {
        destroyMessages("uid LIKE '" + K9.LOCAL_UID_PREFIX + "%'");
    }
+2 −2
Original line number Diff line number Diff line
@@ -212,9 +212,9 @@ interface MessageStore {
    fun setMoreMessages(folderId: Long, moreMessages: MoreMessages)

    /**
     * Update the 'last updated' state of a folder.
     * Update the time when the folder was last checked for new messages.
     */
    fun setLastUpdated(folderId: Long, timestamp: Long)
    fun setLastChecked(folderId: Long, timestamp: Long)

    /**
     * Update folder status message.
Loading