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

Commit 62411ace authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

Fix assigning account number when Account is first saved (fixes #3787)

parent 05d9315d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class Account implements BaseAccount, StoreConfig {
    public static final SortType DEFAULT_SORT_TYPE = SortType.SORT_DATE;
    public static final boolean DEFAULT_SORT_ASCENDING = false;
    public static final long NO_OPENPGP_KEY = 0;
    public static final int UNASSIGNED_ACCOUNT_NUMBER = -1;

    private DeletePolicy deletePolicy = DeletePolicy.NEVER;

+2 −2
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class AccountPreferenceSerializer(

            autoExpandFolder = storage.getString("$accountUuid.autoExpandFolderName", INBOX)

            accountNumber = storage.getInt("$accountUuid.accountNumber", 0)
            accountNumber = storage.getInt("$accountUuid.accountNumber", UNASSIGNED_ACCOUNT_NUMBER)

            chipColor = storage.getInt("$accountUuid.chipColor", FALLBACK_ACCOUNT_COLOR)

@@ -503,7 +503,7 @@ class AccountPreferenceSerializer(
            idleRefreshMinutes = 24
            isPushPollOnConnect = true
            displayCount = K9.DEFAULT_VISIBLE_LIMIT
            accountNumber = -1
            accountNumber = UNASSIGNED_ACCOUNT_NUMBER
            isNotifyNewMail = true
            folderNotifyNewMailMode = FolderMode.ALL
            isNotifySync = true
+10 −6
Original line number Diff line number Diff line
@@ -203,14 +203,18 @@ public class Preferences {
    public void saveAccount(Account account) {
        StorageEditor editor = storage.edit();

        if (!accounts.containsKey(account.getUuid())) {
            int accountNumber = generateAccountNumber();
            account.setAccountNumber(accountNumber);
        ensureAssignedAccountNumber(account);
        processChangedValues(account);
        accountPreferenceSerializer.save(storage, editor, account);
    }

        processChangedValues(account);
    private void ensureAssignedAccountNumber(Account account) {
        if (account.getAccountNumber() != Account.UNASSIGNED_ACCOUNT_NUMBER) {
            return;
        }

        accountPreferenceSerializer.save(storage, editor, account);
        int accountNumber = generateAccountNumber();
        account.setAccountNumber(accountNumber);
    }

    private void processChangedValues(Account account) {