@@ -15,15 +15,16 @@ import com.getcode.model.ConversationWithLastPointers
1515import com.getcode.model.ID
1616import com.getcode.model.MessageStatus
1717import com.getcode.model.chat.ChatType
18+ import com.getcode.model.chat.MessageContent
1819import com.getcode.model.chat.OutgoingMessageContent
20+ import com.getcode.model.chat.Platform
21+ import com.getcode.model.chat.isConversation
1922import com.getcode.model.chat.selfId
20- import com.getcode.model.uuid
2123import com.getcode.network.client.ChatMessageStreamReference
2224import com.getcode.network.exchange.Exchange
2325import com.getcode.network.repository.base58
2426import com.getcode.network.service.ChatServiceV2
2527import com.getcode.utils.ErrorUtils
26- import com.getcode.utils.timestamp
2728import kotlinx.coroutines.CoroutineScope
2829import kotlinx.coroutines.Dispatchers
2930import kotlinx.coroutines.flow.Flow
@@ -38,7 +39,7 @@ interface ConversationController {
3839 fun openChatStream (scope : CoroutineScope , conversation : Conversation )
3940 fun closeChatStream ()
4041 suspend fun hasInteracted (messageId : ID ): Boolean
41- suspend fun revealIdentity (messageId : ID )
42+ suspend fun revealIdentity (conversationId : ID , platform : Platform , username : String ): Result < Unit >
4243 suspend fun advanceReadPointer (conversationId : ID , messageId : ID , status : MessageStatus )
4344 suspend fun sendMessage (conversationId : ID , message : String ): Result <ID >
4445 fun conversationPagingData (conversationId : ID ): Flow <PagingData <ConversationMessageWithContent >>
@@ -136,6 +137,21 @@ class ConversationStreamController @Inject constructor(
136137 messageWithContentMapper.map(chat.id to it)
137138 }
138139
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+
139155 println (" chat messages: ${messages.count()} , pointers=${pointers.count()} " )
140156
141157 scope.launch(Dispatchers .IO ) {
@@ -169,7 +185,19 @@ class ConversationStreamController @Inject constructor(
169185 return false
170186 }
171187
172- override suspend fun revealIdentity (messageId : ID ) {
188+ override suspend fun revealIdentity (conversationId : ID , platform : Platform , username : String ): Result <Unit > {
189+ val owner = SessionManager .getOrganizer()?.ownerKeyPair ? : return Result .failure(Throwable (" owner not found" ))
190+ val chat = historyController.chats.value?.firstOrNull {
191+ it.id == conversationId
192+ } ? : return Result .failure(Throwable (" Chat not found" ))
193+
194+ val memberId = chat.selfId ? : return Result .failure(Throwable (" Not member of chat" ))
195+
196+ return chatService.revealIdentity(owner, chat, memberId, platform, username)
197+ .map { }
198+ .onSuccess {
199+ db.conversationDao().revealIdentity(conversationId)
200+ }
173201 }
174202
175203 override suspend fun advanceReadPointer (conversationId : ID , messageId : ID , status : MessageStatus ) {
0 commit comments