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 @@ -20,6 +20,8 @@ sealed interface DeeplinkType: Parcelable {

@Serializable data class Chat(val identifier: ChatIdentifier): DeeplinkType, Navigatable

@Serializable data class TipChat(val identifier: ChatIdentifier): DeeplinkType, Navigatable

@Serializable data class Tipcard(val userId: ID): DeeplinkType

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ object Linkify {
fun tokenInfo(token: Token): String = tokenInfo(token.address)
fun tokenInfo(mint: Mint): String = "https://app.flipcash.com/token/${mint.base58()}"
fun chatById(chatId: ChatId): String = "https://app.flipcash.com/chat/${chatId.bytes.encodeBase64(urlSafe = true)}"
fun tipChatById(chatId: ChatId): String = "https://app.flipcash.com/tip/chat/${chatId.bytes.encodeBase64(urlSafe = true)}"
fun chatByPhone(phoneNumber: String): String = "https://app.flipcash.com/chat/${phoneNumber.urlEncode()}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import com.flipcash.app.phone.PhoneUtils
import com.flipcash.features.directsend.R
import com.flipcash.services.models.chat.ChatMember
import com.flipcash.services.models.chat.ChatType
import com.flipcash.services.models.chat.MessageContent
import com.flipcash.services.user.UserManager
import com.flipcash.shared.chat.ChatSummary
import com.flipcash.shared.chat.ui.ConversationReference
import com.getcode.opencode.model.core.ID
import com.flipcash.shared.chat.ui.toConversationReference
import com.getcode.opencode.model.financial.Token
import com.getcode.solana.keys.Mint
import com.getcode.util.resources.ResourceHelper
Expand Down Expand Up @@ -110,11 +108,7 @@ internal class ContactListBuilder @Inject constructor(
contact = contact,
isOnFlipcash = true,
lastActivity = summary.metadata.lastActivity,
conversation = ConversationReference(
chatId = chatId,
lastMessagePreview = formatPreview(summary, selfId, tokensByMint),
unreadCount = summary.unreadCount,
),
conversation = summary.toConversationReference(selfId, tokensByMint, resources),
)
}

Expand Down Expand Up @@ -145,45 +139,4 @@ internal class ContactListBuilder @Inject constructor(
other.forEach { add(ContactListItem.ContactRow(it, isOnFlipcash = false)) }
}
}

private fun formatPreview(
summary: ChatSummary,
selfId: ID?,
tokensByMint: Map<Mint, Token>,
): String? {
val lastMsg = summary.metadata.lastMessage ?: return null
val sentBySelf = lastMsg.senderId != null && lastMsg.senderId == selfId
return lastMsg.content.firstOrNull()?.let { content ->
when (content) {
is MessageContent.Text -> {
val message = content.text.takeIf { it.isNotEmpty() } ?: return null
if (sentBySelf) {
resources.getString(R.string.label_chat_preview_sentMessage, message)
} else {
message
}
}
is MessageContent.Cash -> {
val formatted = content.amount.formatted()
val name = content.tokenName.ifBlank { tokensByMint[content.mint]?.name.orEmpty() }
val label = if (name.isNotBlank()) {
resources.getString(R.string.label_chat_preview_cash_suffix, formatted, name)
} else {
formatted
}
if (sentBySelf) {
resources.getString(R.string.label_chat_preview_sentCash, label)
} else {
resources.getString(R.string.label_chat_preview_receivedCash, label)
}
}

// TODO:
is MessageContent.Deleted -> null
is MessageContent.Media -> null
is MessageContent.Reply -> null
is MessageContent.System -> null
}
}
}
}
1 change: 1 addition & 0 deletions apps/flipcash/features/messenger/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(project(":apps:flipcash:shared:contacts"))
implementation(project(":apps:flipcash:shared:featureflags"))
implementation(project(":apps:flipcash:shared:funding"))
implementation(project(":apps:flipcash:shared:payments"))
implementation(project(":apps:flipcash:shared:tokens"))
implementation(project(":libs:vibrator:bindings"))
implementation(project(":libs:messaging"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.flipcash.app.messenger.internal

import com.flipcash.app.core.contacts.DeviceContact
import com.flipcash.services.models.UserProfile
import com.getcode.opencode.model.core.ID

/**
* The counterparty a DM header and info card renders.
*
* A conversation is backed by one of two identity sources depending on its
* [com.flipcash.services.models.chat.ChatType]:
*
* - [Contact] — a `CONTACT_DM`. Identity comes from a device [DeviceContact]: it has a phone
* number and supports the "add to contacts" action.
* - [TipUser] — a `TIP_DM`. The counterparty has no device contact; identity comes from their
* server [UserProfile] (display name + profile picture), the same source the tips list uses.
*/
internal sealed interface ChatParticipant {
val displayName: String

data class Contact(val contact: DeviceContact) : ChatParticipant {
override val displayName: String get() = contact.displayName
}

data class TipUser(val userId: ID, val profile: UserProfile) : ChatParticipant {
override val displayName: String get() = profile.displayName.orEmpty()
}
}
Loading
Loading