Skip to content

Commit 97101a6

Browse files
committed
chore: fixes around identity reveal; update chat title for balance screen if known
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent f24d2a2 commit 97101a6

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

api/src/main/java/com/getcode/mapper/ConversationMapper.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.getcode.mapper
22

33
import com.getcode.model.Conversation
44
import com.getcode.model.chat.Chat
5+
import com.getcode.model.chat.self
6+
import com.getcode.network.TipController
57
import com.getcode.network.localized
68
import com.getcode.network.repository.base58
79
import com.getcode.util.resources.ResourceHelper
@@ -12,12 +14,13 @@ class ConversationMapper @Inject constructor(
1214
) : Mapper<Chat, Conversation> {
1315
override fun map(from: Chat): Conversation {
1416

17+
val self = from.self?.identity
1518
val identity = from.members.filterNot { it.isSelf }.firstNotNullOfOrNull { it.identity }
1619

1720
return Conversation(
1821
idBase58 = from.id.base58,
1922
title = from.title.localized(resources),
20-
hasRevealedIdentity = identity != null,
23+
hasRevealedIdentity = self != null,
2124
lastActivity = null, // TODO: ?
2225
user = identity?.username,
2326
userImage = null,

api/src/main/java/com/getcode/network/ConversationController.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import com.getcode.model.ConversationWithLastPointers
1515
import com.getcode.model.ID
1616
import com.getcode.model.MessageStatus
1717
import com.getcode.model.chat.ChatType
18+
import com.getcode.model.chat.MessageContent
1819
import com.getcode.model.chat.OutgoingMessageContent
1920
import com.getcode.model.chat.Platform
21+
import com.getcode.model.chat.isConversation
2022
import com.getcode.model.chat.selfId
21-
import com.getcode.model.uuid
2223
import com.getcode.network.client.ChatMessageStreamReference
2324
import com.getcode.network.exchange.Exchange
2425
import com.getcode.network.repository.base58
2526
import com.getcode.network.service.ChatServiceV2
2627
import com.getcode.utils.ErrorUtils
27-
import com.getcode.utils.timestamp
2828
import kotlinx.coroutines.CoroutineScope
2929
import kotlinx.coroutines.Dispatchers
3030
import kotlinx.coroutines.flow.Flow
@@ -137,6 +137,21 @@ class ConversationStreamController @Inject constructor(
137137
messageWithContentMapper.map(chat.id to it)
138138
}
139139

140+
val identityRevealed = messages
141+
.flatMap { it.contents }
142+
.filterIsInstance<MessageContent.IdentityRevealed>()
143+
.firstOrNull()
144+
.takeIf { chat.isConversation }
145+
146+
if (identityRevealed != null && conversation.user == null) {
147+
scope.launch(Dispatchers.IO) {
148+
db.conversationDao()
149+
.upsertConversations(
150+
conversation.copy(user = identityRevealed.identity.username)
151+
)
152+
}
153+
}
154+
140155
println("chat messages: ${messages.count()}, pointers=${pointers.count()}")
141156

142157
scope.launch(Dispatchers.IO) {

api/src/main/java/com/getcode/network/HistoryController.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ class HistoryController @Inject constructor(
246246
private suspend fun fetchChatsWithoutMessages(): List<Chat> {
247247
val owner = owner() ?: return emptyList()
248248
val result = client.fetchChats(owner)
249+
.map { chats ->
250+
chats.map { chat ->
251+
// map revealed identity as title if known
252+
if (chat.isConversation) {
253+
val conversation = conversationMapper.map(chat)
254+
if (conversation.user != null) {
255+
chat.copy(title = Title.Localized(conversation.user))
256+
} else {
257+
chat
258+
}
259+
} else {
260+
chat
261+
}
262+
}
263+
}
249264
.onSuccess { result ->
250265
result.filter { it.isConversation }
251266
.let { chats ->
@@ -257,11 +272,8 @@ class HistoryController @Inject constructor(
257272
chats
258273
}
259274
.onEach {
260-
if (db.conversationDao().findConversation(it.id) == null) {
261-
trace("adding conversation for chat ${it.id.description}")
262-
val conversation = conversationMapper.map(it)
263-
db.conversationDao().upsertConversations(conversation)
264-
}
275+
val conversation = conversationMapper.map(it)
276+
db.conversationDao().upsertConversations(conversation)
265277
}
266278
}
267279
return result.getOrNull().orEmpty()

0 commit comments

Comments
 (0)