Skip to content

Commit a8d68fa

Browse files
committed
chore(chat): merge recents and on flipcash into single grouping; filter out self
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent ea5b48b commit a8d68fa

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

  • apps/flipcash

apps/flipcash/features/direct-send/src/main/kotlin/com/flipcash/app/directsend/internal/SendFlowViewModel.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.flipcash.app.permissions.PickedContact
1515
import com.flipcash.app.phone.PhoneUtils
1616
import com.flipcash.app.tokens.TokenCoordinator
1717
import com.flipcash.features.directsend.R
18+
import com.flipcash.services.models.chat.ChatMember
1819
import com.flipcash.services.models.chat.ChatType
1920
import com.flipcash.services.models.chat.MessageContent
2021
import com.flipcash.services.user.UserManager
@@ -228,7 +229,11 @@ internal class SendFlowViewModel @Inject constructor(
228229
chatFeed: List<ChatSummary>,
229230
tokensByMint: Map<Mint, Token>,
230231
): List<ContactListItem> = buildList {
231-
val allContacts = contactState.contacts.values.toList()
232+
val selfId = userManager.accountId
233+
val selfPhone = userManager.profile?.verifiedPhoneNumber
234+
235+
val allContacts = contactState.contacts.values
236+
.filter { selfPhone == null || it.e164 != selfPhone }
232237
val filtered = if (searchString.isBlank()) {
233238
allContacts
234239
} else {
@@ -238,8 +243,6 @@ internal class SendFlowViewModel @Inject constructor(
238243
}
239244
}
240245

241-
val selfId = userManager.accountId
242-
243246
val dmChats = chatFeed.filter { it.metadata.type == ChatType.DM }
244247
// Build a reverse lookup: e164 -> chatId string for contacts with DMs
245248
val e164ToChatId = contactState.dmChatIds
@@ -253,7 +256,9 @@ internal class SendFlowViewModel @Inject constructor(
253256
// Try to match this chat to a device contact
254257
val e164 = e164ToChatId.entries
255258
.firstOrNull { it.value == chatIdStr }?.key
256-
val deviceContact = e164?.let { contactState.contacts[it] }
259+
val deviceContact = e164
260+
?.takeIf { selfPhone == null || it != selfPhone }
261+
?.let { contactState.contacts[it] }
257262

258263
val contact = if (deviceContact != null) {
259264
if (searchString.isNotBlank() &&
@@ -265,8 +270,11 @@ internal class SendFlowViewModel @Inject constructor(
265270
deviceContact
266271
} else {
267272
// Non-contact DM — build contact from chat member profile
273+
val isSelf = { member: ChatMember ->
274+
member.userId == selfId || (selfPhone != null && member.userProfile.verifiedPhoneNumber == selfPhone)
275+
}
268276
val otherMember = summary.metadata.members
269-
.firstOrNull { it.userId != selfId } ?: return@mapNotNull null
277+
.firstOrNull { !isSelf(it) } ?: return@mapNotNull null
270278
val phone = otherMember.userProfile.verifiedPhoneNumber
271279
val formattedPhone = phone?.let { phoneUtils.formatNumber(it) }
272280
val displayName = otherMember.userProfile.displayName?.takeIf { it.isNotBlank() }
@@ -304,19 +312,14 @@ internal class SendFlowViewModel @Inject constructor(
304312
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.displayName })
305313
.map { ContactListItem.ContactRow(contact = it, isOnFlipcash = true) }
306314

315+
val flipcashCombined = (recentRows + flipcashRows)
316+
307317
val excludedE164s = recentsE164s + contactState.flipcashE164s
308318
val other = filtered
309319
.filter { it.e164 !in excludedE164s }
310320
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.displayName })
311321

312-
if (recentRows.isNotEmpty()) {
313-
add(ContactListItem.Header(resources.getString(R.string.title_recents)))
314-
addAll(recentRows)
315-
}
316-
if (flipcashRows.isNotEmpty()) {
317-
add(ContactListItem.Header(resources.getString(R.string.title_flipcashContacts)))
318-
addAll(flipcashRows)
319-
}
322+
addAll(flipcashCombined)
320323
if (other.isNotEmpty()) {
321324
add(ContactListItem.Header(resources.getString(R.string.title_nonFlipcashContacts)))
322325
other.forEach { add(ContactListItem.ContactRow(it, isOnFlipcash = false)) }

apps/flipcash/shared/chat/src/main/kotlin/com/flipcash/shared/chat/internal/delegates/FeedSyncDelegate.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ class FeedSyncDelegate @Inject constructor(
7474
override val feed: Flow<List<ChatSummary>>
7575
get() = stateHolder.state.map { state ->
7676
val selfId = userManager.accountId
77+
val selfPhone = userManager.profile?.verifiedPhoneNumber
78+
val isSelf = { member: ChatMember ->
79+
member.userId == selfId || (selfPhone != null && member.userProfile.verifiedPhoneNumber == selfPhone)
80+
}
7781
state.feed.mapNotNull { metadata ->
78-
val otherMember = metadata.members.firstOrNull { it.userId != selfId }
79-
if (otherMember != null) {
80-
val profile = otherMember.userProfile
81-
val hasIdentity = !profile.displayName.isNullOrBlank() ||
82-
!profile.verifiedPhoneNumber.isNullOrBlank()
83-
if (!hasIdentity) return@mapNotNull null
84-
}
82+
val otherMember = metadata.members.firstOrNull { !isSelf(it) }
83+
?: return@mapNotNull null
84+
val profile = otherMember.userProfile
85+
val hasIdentity = !profile.displayName.isNullOrBlank() ||
86+
!profile.verifiedPhoneNumber.isNullOrBlank()
87+
if (!hasIdentity) return@mapNotNull null
8588

8689
val readPointer = metadata.members
8790
.firstOrNull { it.userId == selfId }

0 commit comments

Comments
 (0)