mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
App | Feature | Delete account (#2157)
This commit is contained in:
parent
b1630655d7
commit
38185eaba5
62 changed files with 1192 additions and 241 deletions
|
@ -0,0 +1,11 @@
|
|||
package com.anytypeio.anytype.data.auth.account
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.domain.account.AccountStatusChannel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class AccountStatusDataChannel(
|
||||
private val remote: AccountStatusRemoteChannel
|
||||
) : AccountStatusChannel {
|
||||
override fun observe(): Flow<AccountStatus> = remote.observe()
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.anytypeio.anytype.data.auth.account
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AccountStatusRemoteChannel {
|
||||
fun observe(): Flow<AccountStatus>
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.data.auth.model.AccountEntity
|
||||
import com.anytypeio.anytype.data.auth.model.FlavourConfigEntity
|
||||
import com.anytypeio.anytype.data.auth.model.WalletEntity
|
||||
|
@ -12,7 +12,7 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore {
|
|||
override suspend fun startAccount(
|
||||
id: String,
|
||||
path: String
|
||||
): Pair<AccountEntity, FlavourConfigEntity> {
|
||||
): Triple<AccountEntity, FlavourConfigEntity, AccountStatus> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,14 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore {
|
|||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun deleteAccount(): AccountStatus {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun restoreAccount(): AccountStatus {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun recoverAccount() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
@ -54,7 +62,7 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore {
|
|||
|
||||
override suspend fun getMnemonic() = cache.getMnemonic()
|
||||
|
||||
override suspend fun logout() {
|
||||
override suspend fun logout(clearLocalRepositoryData: Boolean) {
|
||||
cache.logout()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.core_models.FlavourConfig
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.data.auth.mapper.toDomain
|
||||
import com.anytypeio.anytype.data.auth.mapper.toEntity
|
||||
import com.anytypeio.anytype.data.auth.repo.config.Configurator
|
||||
import com.anytypeio.anytype.domain.auth.model.Account
|
||||
import com.anytypeio.anytype.domain.auth.model.Wallet
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.core_models.FlavourConfig
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class AuthDataRepository(
|
||||
|
@ -18,10 +18,11 @@ class AuthDataRepository(
|
|||
|
||||
override suspend fun startAccount(
|
||||
id: String, path: String
|
||||
): Pair<Account, FlavourConfig> = factory.remote.startAccount(id, path).let { pair ->
|
||||
Pair(
|
||||
first = pair.first.toDomain(),
|
||||
second = pair.second.toDomain()
|
||||
): Triple<Account, FlavourConfig, AccountStatus> = factory.remote.startAccount(id, path).let { triple ->
|
||||
Triple(
|
||||
first = triple.first.toDomain(),
|
||||
second = triple.second.toDomain(),
|
||||
third = triple.third
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -31,6 +32,9 @@ class AuthDataRepository(
|
|||
invitationCode: String
|
||||
): Account = factory.remote.createAccount(name, avatarPath, invitationCode).toDomain()
|
||||
|
||||
override suspend fun deleteAccount(): AccountStatus = factory.remote.deleteAccount()
|
||||
override suspend fun restoreAccount(): AccountStatus = factory.remote.restoreAccount()
|
||||
|
||||
override suspend fun startLoadingAccounts() {
|
||||
factory.remote.recoverAccount()
|
||||
}
|
||||
|
@ -66,10 +70,10 @@ class AuthDataRepository(
|
|||
|
||||
override suspend fun getMnemonic() = factory.cache.getMnemonic()
|
||||
|
||||
override suspend fun logout() {
|
||||
override suspend fun logout(clearLocalRepositoryData: Boolean) {
|
||||
configurator.release()
|
||||
factory.remote.logout()
|
||||
factory.cache.logout()
|
||||
factory.remote.logout(clearLocalRepositoryData)
|
||||
factory.cache.logout(clearLocalRepositoryData)
|
||||
}
|
||||
|
||||
override suspend fun getAccounts() = factory.cache.getAccounts().map { it.toDomain() }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.data.auth.model.AccountEntity
|
||||
import com.anytypeio.anytype.data.auth.model.FlavourConfigEntity
|
||||
import com.anytypeio.anytype.data.auth.model.WalletEntity
|
||||
|
@ -9,10 +9,13 @@ import kotlinx.coroutines.flow.Flow
|
|||
|
||||
interface AuthDataStore {
|
||||
|
||||
suspend fun startAccount(id: String, path: String): Pair<AccountEntity, FlavourConfigEntity>
|
||||
suspend fun startAccount(id: String, path: String): Triple<AccountEntity, FlavourConfigEntity, AccountStatus>
|
||||
|
||||
suspend fun createAccount(name: String, avatarPath: String?, invitationCode: String): AccountEntity
|
||||
|
||||
suspend fun deleteAccount() : AccountStatus
|
||||
suspend fun restoreAccount() : AccountStatus
|
||||
|
||||
suspend fun recoverAccount()
|
||||
|
||||
suspend fun saveAccount(account: AccountEntity)
|
||||
|
@ -30,7 +33,7 @@ interface AuthDataStore {
|
|||
suspend fun saveMnemonic(mnemonic: String)
|
||||
suspend fun getMnemonic(): String
|
||||
|
||||
suspend fun logout()
|
||||
suspend fun logout(clearLocalRepositoryData: Boolean)
|
||||
suspend fun getAccounts(): List<AccountEntity>
|
||||
suspend fun setCurrentAccount(id: String)
|
||||
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.data.auth.model.AccountEntity
|
||||
import com.anytypeio.anytype.data.auth.model.FlavourConfigEntity
|
||||
import com.anytypeio.anytype.data.auth.model.WalletEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AuthRemote {
|
||||
suspend fun startAccount(id: String, path: String): Pair<AccountEntity, FlavourConfigEntity>
|
||||
suspend fun startAccount(id: String, path: String): Triple<AccountEntity, FlavourConfigEntity, AccountStatus>
|
||||
suspend fun createAccount(name: String, avatarPath: String?, invitationCode: String): AccountEntity
|
||||
suspend fun deleteAccount() : AccountStatus
|
||||
suspend fun restoreAccount() : AccountStatus
|
||||
suspend fun recoverAccount()
|
||||
suspend fun logout()
|
||||
suspend fun logout(clearLocalRepositoryData: Boolean)
|
||||
fun observeAccounts(): Flow<AccountEntity>
|
||||
|
||||
suspend fun createWallet(path: String): WalletEntity
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.data.auth.model.AccountEntity
|
||||
import com.anytypeio.anytype.data.auth.model.WalletEntity
|
||||
|
||||
|
@ -19,6 +19,10 @@ class AuthRemoteDataStore(
|
|||
invitationCode: String
|
||||
) = authRemote.createAccount(name, avatarPath, invitationCode)
|
||||
|
||||
override suspend fun deleteAccount(): AccountStatus = authRemote.deleteAccount()
|
||||
|
||||
override suspend fun restoreAccount(): AccountStatus = authRemote.restoreAccount()
|
||||
|
||||
override suspend fun recoverAccount() {
|
||||
authRemote.recoverAccount()
|
||||
}
|
||||
|
@ -48,8 +52,8 @@ class AuthRemoteDataStore(
|
|||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun logout() {
|
||||
authRemote.logout()
|
||||
override suspend fun logout(clearLocalRepositoryData: Boolean) {
|
||||
authRemote.logout(clearLocalRepositoryData)
|
||||
}
|
||||
|
||||
override suspend fun getAccounts(): List<AccountEntity> {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.anytypeio.anytype.data
|
||||
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.data.auth.model.AccountEntity
|
||||
import com.anytypeio.anytype.data.auth.model.FlavourConfigEntity
|
||||
import com.anytypeio.anytype.data.auth.model.WalletEntity
|
||||
|
@ -58,7 +59,9 @@ class AuthDataRepositoryTest {
|
|||
val config = FlavourConfigEntity()
|
||||
|
||||
authRemote.stub {
|
||||
onBlocking { startAccount(id = id, path = path) } doReturn Pair(account, config)
|
||||
onBlocking { startAccount(id = id, path = path) } doReturn Triple(
|
||||
account, config, AccountStatus.Active
|
||||
)
|
||||
}
|
||||
|
||||
repo.startAccount(
|
||||
|
@ -224,11 +227,11 @@ class AuthDataRepositoryTest {
|
|||
onBlocking { logout() } doReturn Unit
|
||||
}
|
||||
|
||||
repo.logout()
|
||||
repo.logout(false)
|
||||
|
||||
verify(authCache, times(1)).logout()
|
||||
verifyNoMoreInteractions(authCache)
|
||||
verify(authRemote, times(1)).logout()
|
||||
verify(authRemote, times(1)).logout(false)
|
||||
verifyNoMoreInteractions(authRemote)
|
||||
verify(configurator, times(1)).release()
|
||||
verifyZeroInteractions(configurator)
|
||||
|
@ -238,14 +241,14 @@ class AuthDataRepositoryTest {
|
|||
fun `should not call logout on cache if remote logout is not succeeded`() {
|
||||
|
||||
authRemote.stub {
|
||||
onBlocking { logout() } doThrow IllegalStateException()
|
||||
onBlocking { logout(false) } doThrow IllegalStateException()
|
||||
}
|
||||
|
||||
runBlocking {
|
||||
try {
|
||||
repo.logout()
|
||||
repo.logout(false)
|
||||
} catch (e: Exception) {
|
||||
verify(authRemote, times(1)).logout()
|
||||
verify(authRemote, times(1)).logout(false)
|
||||
verifyZeroInteractions(authCache)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue