Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class ContactListBuilder @Inject constructor(
.firstOrNull { !isSelf(it) } ?: return@mapNotNull null
val phone = otherMember.userProfile.verifiedPhoneNumber
val formattedPhone = phone?.let { phoneUtils.formatNumber(it) }
val displayName = otherMember.userProfile.displayName?.takeIf { it.isNotBlank() }
val displayName = otherMember.userProfile.displayName.takeIf { it.isNotBlank() }
?: formattedPhone
?: return@mapNotNull null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ internal sealed interface ChatParticipant {
}

data class TipUser(val userId: ID, val profile: UserProfile) : ChatParticipant {
override val displayName: String get() = profile.displayName.orEmpty()
override val displayName: String get() = profile.displayName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ internal class ChatViewModel @Inject constructor(
val other = members.firstOrNull { it.userId != selfId }
if (other != null) {
val profile = other.userProfile
val hasIdentity = !profile.displayName.isNullOrBlank() ||
val hasIdentity = profile.displayName.isNotBlank() ||
!profile.verifiedPhoneNumber.isNullOrBlank()
!hasIdentity
} else false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ internal fun UserProfileScreenContent(

@Composable
private fun ProfileHeader(
displayName: String?,
displayName: String,
profilePicture: MediaItem?,
onEditName: () -> Unit,
onEditPhoto: () -> Unit,
Expand All @@ -290,7 +290,7 @@ private fun ProfileHeader(
horizontalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x1),
) {
Text(
text = displayName?.takeIf { it.isNotEmpty() }
text = displayName.takeIf { it.isNotEmpty() }
?: stringResource(R.string.subtitle_noDisplayName),
style = CodeTheme.typography.textLarge,
color = CodeTheme.colors.textMain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class UserProfileViewModel @Inject constructor(
defaultDispatcher = dispatchers.Default,
) {
internal data class State(
val displayName: String? = null,
val displayName: String = "",
val profilePicture: MediaItem? = null,
val phone: VerifiableContactMethod? = null,
val email: VerifiableContactMethod? = null,
Expand All @@ -58,7 +58,7 @@ internal class UserProfileViewModel @Inject constructor(

internal sealed interface Event {
data class OnProfileUpdated(
val displayName: String?,
val displayName: String,
val profilePicture: MediaItem?,
val phone: VerifiableContactMethod?,
val email: VerifiableContactMethod?,
Expand Down Expand Up @@ -102,7 +102,7 @@ internal class UserProfileViewModel @Inject constructor(

dispatchEvent(
Event.OnProfileUpdated(
displayName = profile?.displayName,
displayName = profile?.displayName.orEmpty(),
profilePicture = profile?.profilePicture,
// Carry the contact (value + verified) so unverified entries still show.
phone = profile?.phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ContactMethodsViewModelStateTest {
@Test
fun `default state has null profile fields`() {
val state = UserProfileViewModel.State()
assertNull(state.displayName)
assertTrue(state.displayName.isEmpty())
assertNull(state.phone)
assertNull(state.email)
assertFalse(state.phoneLinkedForPayment)
Expand Down Expand Up @@ -58,15 +58,15 @@ class ContactMethodsViewModelStateTest {
fun `OnProfileUpdated with null values`() {
val updated = reduce(
UserProfileViewModel.Event.OnProfileUpdated(
displayName = null,
displayName = "",
profilePicture = null,
phone = null,
email = null,
linkedForPayment = false,
socialAccounts = emptyList(),
)
)(UserProfileViewModel.State())
assertNull(updated.displayName)
assertTrue(updated.displayName.isEmpty())
assertNull(updated.phone)
assertNull(updated.email)
assertFalse(updated.phoneLinkedForPayment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class UserProfileScreenContentTest {
composeTestRule.onNodeWithText("Alice").assertIsDisplayed()
}

@Test
fun `no display name placeholder when null`() {
setScreen(UserProfileViewModel.State(displayName = null))
composeTestRule.onNodeWithText("No display name set").assertIsDisplayed()
}

@Test
fun `no display name placeholder when empty`() {
setScreen(UserProfileViewModel.State(displayName = ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal class TipFlowViewModel @Inject constructor(
stateFlow.map { it.resumed }.distinctUntilChanged(),
) { profile, resumed ->
buildList {
val hasProfile = profile?.displayName != null // TODO: explicitly not required right now && profile.profilePicture != null
val hasProfile = !profile?.displayName.isNullOrEmpty() // TODO: explicitly not required right now && profile.profilePicture != null
when {
// Post-setup handoff: land on TipCard alone, with a close affordance. No Tips
// underneath — closing exits, and reopening from home lands on the Tips list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FeedSyncDelegate @Inject constructor(
// identified by user id and have no phone by design, so they are never dropped.
if (chatType == ChatType.CONTACT_DM) {
val profile = otherMember.userProfile
val hasIdentity = !profile.displayName.isNullOrBlank() ||
val hasIdentity = profile.displayName.isNotBlank() ||
!profile.verifiedPhoneNumber.isNullOrBlank()
if (!hasIdentity) return@mapNotNull null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ class ChatEntityMapper @Inject constructor() {
fun toMember(entity: ChatMemberEntity): ChatMember {
return ChatMember(
userId = entity.userIdHex.hexToId(),
userProfile = entity.userProfileJson?.toDomain() ?: UserProfile(
displayName = null,
socialAccounts = emptyList(),
phoneNumber = null,
email = null,
),
userProfile = entity.userProfileJson?.toDomain() ?: UserProfile.Empty,
pointers = entity.pointersJson?.map { it.toDomain() } ?: emptyList(),
)
}
Expand Down Expand Up @@ -284,7 +279,7 @@ private fun UserProfile.toSerialized(): UserProfileSerialized = UserProfileSeria
)

private fun UserProfileSerialized.toDomain(): UserProfile = UserProfile(
displayName = displayName,
displayName = displayName.orEmpty(),
socialAccounts = socialAccounts.map { it.toDomain() },
phoneNumber = phoneNumber,
email = email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private data class CachedProfile(
val email: VerifiableContactMethod? = null,
) {
fun toDomain(): UserProfile = UserProfile(
displayName = displayName,
displayName = displayName.orEmpty(),
socialAccounts = socialAccounts.mapNotNull { it.toDomain() },
phoneNumber = phoneNumber,
email = email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class ProfileController @Inject constructor(
throw error
}

UserProfile(
displayName = null,
socialAccounts = emptyList(),
UserProfile.Empty.copy(
phoneNumber = unverifiedPhone,
email = unverifiedEmail,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.flipcash.services.models
import com.flipcash.services.models.chat.MediaItem

data class UserProfile(
val displayName: String?,
val displayName: String,
val socialAccounts: List<SocialAccount>,
val phoneNumber: VerifiableContactMethod?,
val email: VerifiableContactMethod?,
Expand All @@ -19,7 +19,7 @@ data class UserProfile(

companion object {
val Empty = UserProfile(
displayName = null,
displayName = "",
socialAccounts = emptyList(),
phoneNumber = null,
email = null,
Expand Down
Loading