-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7174 from thundernest/add_account_updater
Add account updater
- Loading branch information
Showing
18 changed files
with
165 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
app-feature-preview/src/main/java/app/k9mail/feature/preview/account/AccountCreator.kt
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app-feature-preview/src/main/java/app/k9mail/feature/preview/account/InMemoryAccountStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package app.k9mail.feature.preview.account | ||
|
||
import app.k9mail.feature.account.common.domain.entity.Account | ||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdater | ||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdater.AccountUpdaterResult | ||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator | ||
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult | ||
|
||
class InMemoryAccountStore( | ||
private val accountMap: MutableMap<String, Account> = mutableMapOf(), | ||
) : AccountCreator, AccountUpdater { | ||
|
||
override suspend fun createAccount(account: Account): AccountCreatorResult { | ||
accountMap[account.uuid] = account | ||
|
||
return AccountCreatorResult.Success(account.uuid) | ||
} | ||
|
||
override suspend fun updateAccount(account: Account): AccountUpdaterResult { | ||
return if (!accountMap.containsKey(account.uuid)) { | ||
AccountUpdaterResult.Error("Account not found") | ||
} else { | ||
accountMap[account.uuid] = account | ||
|
||
AccountUpdaterResult.Success(account.uuid) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/k9mail/src/main/java/com/fsck/k9/account/AccountUpdater.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.fsck.k9.account | ||
|
||
import app.k9mail.feature.account.common.domain.entity.Account | ||
import app.k9mail.feature.account.edit.AccountEditExternalContract | ||
import app.k9mail.feature.account.edit.AccountEditExternalContract.AccountUpdater.AccountUpdaterResult | ||
import com.fsck.k9.Preferences | ||
import com.fsck.k9.logging.Timber | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
class AccountUpdater( | ||
private val preferences: Preferences, | ||
private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO, | ||
) : AccountEditExternalContract.AccountUpdater { | ||
|
||
@Suppress("TooGenericExceptionCaught") | ||
override suspend fun updateAccount(account: Account): AccountUpdaterResult { | ||
return try { | ||
withContext(coroutineDispatcher) { | ||
AccountUpdaterResult.Success(update(account)) | ||
} | ||
} catch (e: Exception) { | ||
Timber.e(e, "Error while updating account") | ||
|
||
AccountUpdaterResult.Error(e.message ?: "Unknown update account error") | ||
} | ||
} | ||
|
||
private fun update(account: Account): String { | ||
val uuid = account.uuid | ||
require(uuid.isNotEmpty()) { "Can't update account without uuid" } | ||
|
||
val existingAccount = preferences.getAccount(uuid) | ||
require(existingAccount != null) { "Can't update non-existing account" } | ||
|
||
existingAccount.incomingServerSettings = account.incomingServerSettings | ||
existingAccount.outgoingServerSettings = account.outgoingServerSettings | ||
|
||
preferences.saveAccount(existingAccount) | ||
|
||
return uuid | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id(ThunderbirdPlugins.Library.androidCompose) | ||
} | ||
|
||
android { | ||
namespace = "app.k9mail.feature.account.edit" | ||
resourcePrefix = "account_edit_" | ||
|
||
buildTypes { | ||
debug { | ||
manifestPlaceholders["appAuthRedirectScheme"] = "FIXME: override this in your app project" | ||
} | ||
release { | ||
manifestPlaceholders["appAuthRedirectScheme"] = "FIXME: override this in your app project" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.ui.compose.designsystem) | ||
implementation(projects.core.common) | ||
|
||
implementation(projects.feature.account.common) | ||
implementation(projects.feature.account.oauth) | ||
implementation(projects.feature.account.server.validation) | ||
|
||
testImplementation(projects.core.ui.compose.testing) | ||
} |
15 changes: 15 additions & 0 deletions
15
...count/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditExternalContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package app.k9mail.feature.account.edit | ||
|
||
import app.k9mail.feature.account.common.domain.entity.Account | ||
|
||
interface AccountEditExternalContract { | ||
|
||
fun interface AccountUpdater { | ||
suspend fun updateAccount(account: Account): AccountUpdaterResult | ||
|
||
sealed interface AccountUpdaterResult { | ||
data class Success(val accountId: String) : AccountUpdaterResult | ||
data class Error(val message: String) : AccountUpdaterResult | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
feature/account/edit/src/main/kotlin/app/k9mail/feature/account/edit/AccountEditModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.k9mail.feature.account.edit | ||
|
||
import app.k9mail.core.common.coreCommonModule | ||
import app.k9mail.feature.account.oauth.featureAccountOAuthModule | ||
import org.koin.dsl.module | ||
|
||
val accountEditModule = module { | ||
includes(coreCommonModule, featureAccountOAuthModule) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class CreateAccountTest { | |
recordedAccount = account | ||
AccountCreatorResult.Success(accountUuid = "uuid") | ||
}, | ||
uuidGenerator = { "uuid" }, | ||
) | ||
|
||
val emailAddress = "[email protected]" | ||
|
@@ -65,6 +66,7 @@ class CreateAccountTest { | |
assertThat(result).isEqualTo("uuid") | ||
assertThat(recordedAccount).isEqualTo( | ||
Account( | ||
uuid = "uuid", | ||
emailAddress = emailAddress, | ||
incomingServerSettings = incomingServerSettings, | ||
outgoingServerSettings = outgoingServerSettings, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters