Skip to content

Commit a8caa14

Browse files
committed
refactor(message-list): further small improvements
1 parent 25d76f1 commit a8caa14

8 files changed

Lines changed: 45 additions & 30 deletions

File tree

app-common/src/test/kotlin/net/thunderbird/app/common/feature/mail/BaseAccountBackendStorageFactoryTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package net.thunderbird.app.common.feature.mail
33
import assertk.assertFailure
44
import assertk.assertThat
55
import assertk.assertions.isInstanceOf
6-
import assertk.assertions.isSameAs
6+
import assertk.assertions.isSameInstanceAs
77
import net.thunderbird.feature.mail.account.api.BaseAccount
88
import org.junit.Test
99

@@ -21,7 +21,7 @@ class BaseAccountBackendStorageFactoryTest {
2121
factory.createBackendStorage(dto)
2222

2323
// Assert
24-
assertThat(legacyFactory.lastAccount).isSameAs(dto)
24+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(dto)
2525
}
2626

2727
@Test
@@ -37,8 +37,8 @@ class BaseAccountBackendStorageFactoryTest {
3737
factory.createBackendStorage(domain)
3838

3939
// Assert
40-
assertThat(mapper.lastMapped).isSameAs(domain)
41-
assertThat(legacyFactory.lastAccount).isSameAs(dto)
40+
assertThat(mapper.lastMapped).isSameInstanceAs(domain)
41+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(dto)
4242
}
4343

4444
@Test

app-common/src/test/kotlin/net/thunderbird/app/common/feature/mail/BaseAccountImapBackendFactoryTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package net.thunderbird.app.common.feature.mail
33
import assertk.assertFailure
44
import assertk.assertThat
55
import assertk.assertions.isInstanceOf
6-
import assertk.assertions.isSameAs
6+
import assertk.assertions.isSameInstanceAs
77
import com.fsck.k9.mail.AuthType
88
import com.fsck.k9.mail.ConnectionSecurity
99
import com.fsck.k9.mail.ServerSettings
@@ -26,7 +26,7 @@ class BaseAccountImapBackendFactoryTest {
2626
factory.createBackend(account)
2727

2828
// Assert
29-
assertThat(legacyFactory.lastAccount).isSameAs(account)
29+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(account)
3030
}
3131

3232
@Test
@@ -42,8 +42,8 @@ class BaseAccountImapBackendFactoryTest {
4242
factory.createBackend(domain)
4343

4444
// Assert
45-
assertThat(mapper.lastMapped).isSameAs(domain)
46-
assertThat(legacyFactory.lastAccount).isSameAs(dto)
45+
assertThat(mapper.lastMapped).isSameInstanceAs(domain)
46+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(dto)
4747
}
4848

4949
@Test

app-common/src/test/kotlin/net/thunderbird/app/common/feature/mail/BaseAccountSpecialFolderUpdaterFactoryTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package net.thunderbird.app.common.feature.mail
33
import assertk.assertFailure
44
import assertk.assertThat
55
import assertk.assertions.isInstanceOf
6-
import assertk.assertions.isSameAs
6+
import assertk.assertions.isSameInstanceAs
77
import com.fsck.k9.mail.AuthType
88
import com.fsck.k9.mail.ConnectionSecurity
99
import com.fsck.k9.mail.ServerSettings
@@ -27,7 +27,7 @@ class BaseAccountSpecialFolderUpdaterFactoryTest {
2727
val updater = factory.create(dto)
2828

2929
// Assert
30-
assertThat(legacyFactory.lastAccount).isSameAs(dto)
30+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(dto)
3131
assertThat(updater).isInstanceOf(SpecialFolderUpdater::class)
3232
}
3333

@@ -44,8 +44,8 @@ class BaseAccountSpecialFolderUpdaterFactoryTest {
4444
factory.create(domain)
4545

4646
// Assert
47-
assertThat(mapper.lastMapped).isSameAs(domain)
48-
assertThat(legacyFactory.lastAccount).isSameAs(dto)
47+
assertThat(mapper.lastMapped).isSameInstanceAs(domain)
48+
assertThat(legacyFactory.lastAccount).isSameInstanceAs(dto)
4949
}
5050

5151
@Test

app-common/src/test/kotlin/net/thunderbird/app/common/feature/mail/RemoteFolderCreatorResolverTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.thunderbird.app.common.feature.mail
22

33
import assertk.assertThat
4-
import assertk.assertions.isNotSameAs
5-
import assertk.assertions.isSameAs
4+
import assertk.assertions.isNotSameInstanceAs
5+
import assertk.assertions.isSameInstanceAs
66
import kotlin.test.Test
77
import net.thunderbird.core.common.mail.Protocols
88

@@ -24,7 +24,7 @@ class RemoteFolderCreatorResolverTest {
2424
val result = router.create(account)
2525

2626
// Assert
27-
assertThat(result).isNotSameAs(NoOpRemoteFolderCreator)
27+
assertThat(result).isNotSameInstanceAs(NoOpRemoteFolderCreator)
2828
}
2929

3030
@Test
@@ -39,6 +39,6 @@ class RemoteFolderCreatorResolverTest {
3939
val result = router.create(account)
4040

4141
// Assert
42-
assertThat(result).isSameAs(NoOpRemoteFolderCreator)
42+
assertThat(result).isSameInstanceAs(NoOpRemoteFolderCreator)
4343
}
4444
}

core/android/account/src/main/kotlin/net/thunderbird/core/android/account/LegacyAccountDtoManager.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import kotlinx.coroutines.flow.Flow
44
import net.thunderbird.feature.mail.account.api.AccountManager
55

66
@Deprecated(
7-
message = "Use net.thunderbird.feature.mail.account.api.AccountManager<TAccount : BaseAccount> instead",
7+
message = "Use net.thunderbird.core.android.account.LegacyAccountManager instead",
88
replaceWith = ReplaceWith(
9-
expression = "AccountManager<LegacyAccount>",
10-
"net.thunderbird.feature.mail.account.api.AccountManager",
11-
"app.k9mail.legacy.account.LegacyAccount",
9+
expression = "LegacyAccountManager",
10+
"net.thunderbird.core.android.account.LegacyAccountManager",
1211
),
1312
)
1413
interface LegacyAccountDtoManager : AccountManager<LegacyAccountDto> {

legacy/core/src/main/java/com/fsck/k9/mailstore/LocalStoreProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LocalStoreProvider {
2424
}
2525
}
2626

27-
@Throws
27+
@Throws(MessagingException::class)
2828
fun getInstanceByLegacyAccount(account: LegacyAccount): LocalStore {
2929
val context = DI.get(Context::class.java)
3030
val legacyAccountMapper = DI.get(LegacyAccountDataMapper::class.java)

legacy/ui/legacy/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616
implementation(projects.core.android.contact)
1717

1818
implementation(projects.core.featureflag)
19+
implementation(projects.core.logging.api)
1920
implementation(projects.core.ui.theme.api)
2021
implementation(projects.feature.launcher)
2122
implementation(projects.core.common)

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ import java.util.concurrent.Future
6969
import kotlin.time.Clock
7070
import kotlin.time.ExperimentalTime
7171
import kotlinx.collections.immutable.persistentSetOf
72+
import kotlinx.coroutines.Dispatchers
7273
import kotlinx.coroutines.flow.distinctUntilChanged
7374
import kotlinx.coroutines.flow.drop
7475
import kotlinx.coroutines.flow.launchIn
7576
import kotlinx.coroutines.flow.map
7677
import kotlinx.coroutines.flow.onEach
78+
import kotlinx.coroutines.launch
7779
import net.jcip.annotations.GuardedBy
7880
import net.thunderbird.core.android.account.Expunge
7981
import net.thunderbird.core.android.account.LegacyAccount
@@ -86,6 +88,7 @@ import net.thunderbird.core.common.exception.MessagingException
8688
import net.thunderbird.core.featureflag.FeatureFlagKey
8789
import net.thunderbird.core.featureflag.FeatureFlagProvider
8890
import net.thunderbird.core.featureflag.FeatureFlagResult
91+
import net.thunderbird.core.logging.Logger
8992
import net.thunderbird.core.logging.legacy.Log
9093
import net.thunderbird.core.preference.GeneralSettingsManager
9194
import net.thunderbird.core.ui.theme.api.FeatureThemeProvider
@@ -106,6 +109,8 @@ private const val MAXIMUM_MESSAGE_SORT_OVERRIDES = 3
106109
private const val MINIMUM_CLICK_INTERVAL = 200L
107110
private const val RECENT_CHANGES_SNACKBAR_DURATION = 10 * 1000
108111

112+
private const val TAG = "MessageListFragment"
113+
109114
class MessageListFragment :
110115
Fragment(),
111116
ConfirmationDialogFragmentListener,
@@ -132,6 +137,7 @@ class MessageListFragment :
132137
}
133138
private val featureFlagProvider: FeatureFlagProvider by inject()
134139
private val featureThemeProvider: FeatureThemeProvider by inject()
140+
private val logger: Logger by inject()
135141

136142
private val handler = MessageListHandler(this)
137143
private val activityListener = MessageListActivityListener()
@@ -870,8 +876,10 @@ class MessageListFragment :
870876
sortType = sortType,
871877
sortAscending = newSortAscendingMap,
872878
)
873-
accountManager.saveAccount(updatedAccount)
874-
this.account = updatedAccount
879+
lifecycleScope.launch(Dispatchers.IO) {
880+
accountManager.saveAccount(updatedAccount)
881+
this@MessageListFragment.account = updatedAccount
882+
}
875883
} else {
876884
K9.sortType = this.sortType
877885
if (sortAscending == null) {
@@ -1426,33 +1434,40 @@ class MessageListFragment :
14261434
.groupBy { it.folderId }
14271435

14281436
for ((folderId, messagesInFolder) in folderMap) {
1429-
val account = accountManager.getAccount(messagesInFolder.first().accountUuid) ?: continue
1437+
val account = accountManager.getAccount(messagesInFolder.first().accountUuid)
1438+
if (account == null) {
1439+
logger.debug(TAG) {
1440+
"Account for message ${messagesInFolder.first()} not found, skipping copy/move operation"
1441+
}
1442+
continue
1443+
}
14301444

1431-
if (operation == FolderOperation.MOVE) {
1432-
if (showingThreadedList) {
1445+
when (operation) {
1446+
FolderOperation.MOVE if showingThreadedList -> {
14331447
messagingController.moveMessagesInThread(
14341448
account.id,
14351449
folderId,
14361450
messagesInFolder,
14371451
destinationFolderId,
14381452
)
1439-
} else {
1453+
}
1454+
FolderOperation.MOVE -> {
14401455
messagingController.moveMessages(
14411456
account.id,
14421457
folderId,
14431458
messagesInFolder,
14441459
destinationFolderId,
14451460
)
14461461
}
1447-
} else {
1448-
if (showingThreadedList) {
1462+
FolderOperation.COPY if showingThreadedList -> {
14491463
messagingController.copyMessagesInThread(
14501464
account.id,
14511465
folderId,
14521466
messagesInFolder,
14531467
destinationFolderId,
14541468
)
1455-
} else {
1469+
}
1470+
FolderOperation.COPY -> {
14561471
messagingController.copyMessages(
14571472
account.id,
14581473
folderId,

0 commit comments

Comments
 (0)