Skip to content

Commit be932b4

Browse files
committed
feat(account creation): Added use cases for finding a folder by the folder type and enabling push with the folder ID and account information.
1 parent 888c317 commit be932b4

5 files changed

Lines changed: 60 additions & 13 deletions

File tree

‎app-common/src/main/kotlin/net/thunderbird/app/common/account/AccountCreator.kt‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings
77
import app.k9mail.feature.account.setup.AccountSetupExternalContract
88
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
99
import app.k9mail.feature.account.setup.domain.usecase.GetSpecialFolderOptions
10+
import app.k9mail.legacy.mailstore.MessageStoreManager
11+
import app.k9mail.legacy.mailstore.domain.GetFolderIdsForTypeUseCase
12+
import app.k9mail.legacy.mailstore.domain.SetPushForFolderUseCase
1013
import com.fsck.k9.Core
1114
import com.fsck.k9.Preferences
1215
import com.fsck.k9.account.DeletePolicyProvider
@@ -48,6 +51,8 @@ internal class AccountCreator(
4851
private val avatarMonogramCreator: AvatarMonogramCreator,
4952
private val unifiedInboxConfigurator: UnifiedInboxConfigurator,
5053
private val featureFlagProvider: FeatureFlagProvider,
54+
private val getFolderIdsForTypeUseCase: GetFolderIdsForTypeUseCase,
55+
private val setPushForFolderUseCase: SetPushForFolderUseCase,
5156
private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
5257
) : AccountSetupExternalContract.AccountCreator {
5358

@@ -114,19 +119,12 @@ internal class AccountCreator(
114119
featureFlagProvider.provide(GeneratedFeatureFlagKey.PUSH_ENABLED_ON_INBOX_BY_DEFAULT)
115120
.onEnabled {
116121
// The AccountCreator is only called when not importing settings.
117-
// We can update inbox push here by default.
118-
// TODO Get Inbox folderDetails, then updateFolderSettings
119-
// TODO make a use case for getting a folder's settings by type
120-
val inboxFolderID: Long? =
121-
messagingController.getMessageStore(newAccount).getFolders(true) { folderDetails ->
122-
if (folderDetails.type == FolderType.INBOX) {
123-
folderDetails.id
124-
} else {
125-
null
126-
}
127-
}.firstOrNull()
128-
if (inboxFolderID != null) {
129-
messagingController.getMessageStore(newAccount).setPushEnabled(inboxFolderID, true)
122+
// We can update inbox push here by default, as it's always a new account.
123+
getFolderIdsForTypeUseCase(
124+
newAccount.uuid,
125+
FolderType.INBOX
126+
).firstOrNull()?.let { inboxFolderId ->
127+
setPushForFolderUseCase(accountUuid = newAccount.uuid, folderId = inboxFolderId, enabled = true)
130128
}
131129
}
132130

‎app-common/src/main/kotlin/net/thunderbird/app/common/account/AppCommonAccountModule.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ internal val appCommonAccountModule = module {
9292
avatarMonogramCreator = get(),
9393
unifiedInboxConfigurator = get(),
9494
featureFlagProvider = get(),
95+
getFolderIdsForTypeUseCase = get(),
96+
setPushForFolderUseCase = get(),
9597
)
9698
}
9799
}

‎legacy/core/src/main/java/com/fsck/k9/controller/KoinModule.kt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.fsck.k9.controller
22

33
import android.content.Context
44
import app.k9mail.legacy.mailstore.MessageStoreManager
5+
import app.k9mail.legacy.mailstore.domain.GetFolderIdsForTypeUseCase
6+
import app.k9mail.legacy.mailstore.domain.SetPushForFolderUseCase
57
import app.k9mail.legacy.message.controller.MessageCountsProvider
68
import app.k9mail.legacy.message.controller.MessagingControllerRegistry
79
import com.fsck.k9.Preferences
@@ -60,4 +62,16 @@ val controllerModule = module {
6062
outboxFolderManager = get(),
6163
)
6264
}
65+
66+
single<GetFolderIdsForTypeUseCase> {
67+
GetFolderIdsForTypeUseCase(
68+
messageStoreManager = get(),
69+
)
70+
}
71+
72+
single<SetPushForFolderUseCase> {
73+
SetPushForFolderUseCase(
74+
messageStoreManager = get(),
75+
)
76+
}
6377
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package app.k9mail.legacy.mailstore.domain
2+
3+
import app.k9mail.legacy.mailstore.MessageStoreManager
4+
import com.fsck.k9.mail.FolderType
5+
6+
class GetFolderIdsForTypeUseCase(
7+
private val messageStoreManager: MessageStoreManager,
8+
) {
9+
operator fun invoke(
10+
accountUuid: String,
11+
folderType: FolderType,
12+
): List<Long?> {
13+
return messageStoreManager.getMessageStore(accountUuid)
14+
.getFolders(true) { folderDetails ->
15+
if (folderDetails.type == folderType) {
16+
folderDetails.id
17+
} else {
18+
null
19+
}
20+
}
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.k9mail.legacy.mailstore.domain
2+
3+
import app.k9mail.legacy.mailstore.MessageStoreManager
4+
5+
class SetPushForFolderUseCase(
6+
private val messageStoreManager: MessageStoreManager,
7+
) {
8+
operator fun invoke(accountUuid: String, folderId: Long, enabled: Boolean) {
9+
messageStoreManager.getMessageStore(accountUuid).setPushEnabled(folderId, enabled)
10+
}
11+
}

0 commit comments

Comments
 (0)