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

Unverified Commit e5381ca1 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé Committed by GitHub
Browse files

Merge pull request #9332 from wmontwe/fix-avatar-storage-migration-missing

fix(avatar): add missing storage migration to prepopulate the avatar monogram
parents dd7033cb dacb5e2d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ dependencies {
    implementation(projects.core.featureflag)
    implementation(projects.core.ui.legacy.theme2.common)

    implementation(projects.feature.account.avatar.api)
    implementation(projects.feature.account.avatar.impl)
    implementation(projects.feature.account.setup)
    implementation(projects.feature.mail.account.api)
    implementation(projects.feature.migration.provider)
+13 −1
Original line number Diff line number Diff line
@@ -24,9 +24,13 @@ import kotlinx.coroutines.withContext
import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.common.mail.Protocols
import net.thunderbird.core.logging.legacy.Log
import net.thunderbird.feature.account.avatar.AvatarMonogramCreator
import net.thunderbird.feature.account.storage.profile.AvatarDto
import net.thunderbird.feature.account.storage.profile.AvatarTypeDto
import net.thunderbird.feature.mail.folder.api.SpecialFolderSelection

// TODO Move to feature/account/setup
@Suppress("LongParameterList")
internal class AccountCreator(
    private val accountColorPicker: AccountColorPicker,
    private val localFoldersCreator: SpecialLocalFoldersCreator,
@@ -34,8 +38,9 @@ internal class AccountCreator(
    private val context: Context,
    private val messagingController: MessagingController,
    private val deletePolicyProvider: DeletePolicyProvider,
    private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
    private val avatarMonogramCreator: AvatarMonogramCreator,
    private val unifiedInboxConfigurator: UnifiedInboxConfigurator,
    private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
) : AccountSetupExternalContract.AccountCreator {

    @Suppress("TooGenericExceptionCaught")
@@ -54,6 +59,13 @@ internal class AccountCreator(

        newAccount.email = account.emailAddress

        newAccount.avatar = AvatarDto(
            avatarType = AvatarTypeDto.MONOGRAM,
            avatarMonogram = avatarMonogramCreator.create(account.options.accountName, account.emailAddress),
            avatarImageUri = null,
            avatarIconName = null,
        )

        newAccount.setIncomingServerSettings(account.incomingServerSettings)
        newAccount.outgoingServerSettings = account.outgoingServerSettings

+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ import net.thunderbird.app.common.account.data.DefaultAccountProfileLocalDataSou
import net.thunderbird.app.common.account.data.DefaultLegacyAccountWrapperManager
import net.thunderbird.core.android.account.AccountDefaultsProvider
import net.thunderbird.core.android.account.LegacyAccountWrapperManager
import net.thunderbird.feature.account.avatar.AvatarMonogramCreator
import net.thunderbird.feature.account.avatar.DefaultAvatarMonogramCreator
import net.thunderbird.feature.account.core.AccountCoreExternalContract.AccountProfileLocalDataSource
import net.thunderbird.feature.account.core.featureAccountCoreModule
import net.thunderbird.feature.account.storage.legacy.featureAccountStorageLegacyModule
@@ -45,6 +47,10 @@ internal val appCommonAccountModule = module {
        )
    }

    factory<AvatarMonogramCreator> {
        DefaultAvatarMonogramCreator()
    }

    factory<AccountSetupExternalContract.AccountCreator> {
        AccountCreator(
            accountColorPicker = get(),
@@ -53,6 +59,7 @@ internal val appCommonAccountModule = module {
            context = androidApplication(),
            deletePolicyProvider = get(),
            messagingController = get(),
            avatarMonogramCreator = get(),
            unifiedInboxConfigurator = get(),
        )
    }
+7 −0
Original line number Diff line number Diff line
plugins {
    id(ThunderbirdPlugins.Library.kmp)
}

android {
    namespace = "net.thunderbird.feature.account.avatar"
}
+18 −0
Original line number Diff line number Diff line
package net.thunderbird.feature.account.avatar

/**
 * Interface for creating a monogram based on a name or email address.
 *
 * This interface is used to generate a monogram, which is typically the initials of a person's name,
 * or a representation based on an email address. Implementations should handle null or empty inputs gracefully.
 */
fun interface AvatarMonogramCreator {
    /**
     * Creates a monogram for the given name or email.
     *
     * @param name The name to generate a monogram for.
     * @param email The email address to generate a monogram for.
     * @return A string representing the monogram, or an empty string if the name or email is null or empty.
     */
    fun create(name: String?, email: String?): String
}
Loading