Avatars and profile-picture editing¶
Sparrow keeps avatar loading and editing in the dedicated :feature:avatar module. Chat, contacts and group UI consume avatar presentation state instead of passing image ByteArray values through large composable trees.
Module boundary¶
The active production module is :feature:avatar.
Important types:
AvatarTargetidentifies what is being rendered: the local user, another user, or a group.AvatarRepository/AvatarRepositoryImplexpose observable avatar state.AvatarEditorRepository/AvatarEditorRepositoryImplown editor input/output state.AvatarDataSource,LocalAvatarImageDataSourceandLocalAvatarEditorDataSourceimplement local data access.ObserveAvatarUseCaseis the read-side domain entry point.PrepareAvatarEditorSourceUseCase,CropAvatarEditorSourceUseCase,ConsumeAvatarEditResultUseCaseandClearAvatarEditorUseCaseimplement the editor flow.AvatarViewModelmaps repository state toAvatarUiState.AvatarEditorViewModelmaps the edit workflow toAvatarEditorUiState.SparrowAvataris the reusable presentation component.ImagePickeris the multiplatform picker abstraction;cropAndEncodeProfilePicture()(declared inProfilePictureCropper.kt) is the expect/actual crop/encode boundary with Android/iOS implementations.
Read flow¶
sequenceDiagram
participant UI as SparrowAvatar / screen
participant VM as AvatarViewModel
participant UC as ObserveAvatarUseCase
participant Repo as AvatarRepositoryImpl
participant DS as AvatarDataSource
UI->>VM: observe AvatarTarget
VM->>UC: observe(target)
UC->>Repo: observeAvatar(target)
Repo->>DS: observe persisted avatar metadata/image
DS-->>Repo: avatar changes
Repo-->>VM: Avatar
VM-->>UI: AvatarUiState
AvatarRepositoryImpl keeps target-scoped observable state and image caching so a timestamp or image change can update the relevant avatar without forcing callers to carry raw image bytes throughout higher-level UI state.
Edit flow¶
sequenceDiagram
participant Screen as AvatarEditor
participant VM as AvatarEditorViewModel
participant Pick as ImagePicker
participant Prep as PrepareAvatarEditorSourceUseCase
participant Crop as CropAvatarEditorSourceUseCase
participant Device as cropAndEncodeProfilePicture()
participant Repo as AvatarEditorRepositoryImpl
Screen->>Pick: choose image
Pick-->>VM: selected platform image
VM->>Prep: prepare editor source
Prep->>Repo: persist editor source/state
Screen->>VM: confirm crop region
VM->>Crop: crop(source, region)
Crop->>Device: crop platform image
Device-->>Crop: cropped ProfilePictureData
Crop->>Repo: publish AvatarEditResult
Repo-->>Screen: completed edit result
The editor itself does not decide whether the resulting avatar belongs to identity, contact or group persistence. Its output is consumed by the owning feature, preserving the avatar module as a reusable image/editing boundary.
Platform code¶
The common module declares ImagePicker and the expect function cropAndEncodeProfilePicture(). Platform implementations live in androidMain and iosMain, keeping picker/bitmap APIs out of common presentation/domain code.
Why this module exists¶
The dedicated module prevents chat screens from owning avatar decoding/caching and keeps image selection/cropping separate from identity, contact and group business rules. This is especially important for recomposition: conversation list rows and message screens should observe only the avatar target they render rather than rebuilding broad screen state whenever one image changes.