@@ -10,6 +10,8 @@ import androidx.paging.PagingData
1010import androidx.paging.flatMap
1111import androidx.paging.map
1212import com.getcode.BuildConfig
13+ import com.getcode.R
14+ import com.getcode.manager.BottomBarManager
1315import com.getcode.model.ConversationWithLastPointers
1416import com.getcode.model.Feature
1517import com.getcode.model.ID
@@ -23,19 +25,15 @@ import com.getcode.model.uuid
2325import com.getcode.network.ConversationController
2426import com.getcode.network.TipController
2527import com.getcode.network.repository.FeatureRepository
26- import com.getcode.solana.keys.PublicKey
2728import com.getcode.ui.components.chat.utils.ChatItem
2829import com.getcode.ui.components.chat.utils.ConversationMessageIndice
29- import com.getcode.util.CurrencyUtils
3030import com.getcode.util.resources.ResourceHelper
3131import com.getcode.util.toInstantFromMillis
3232import com.getcode.utils.ErrorUtils
33- import com.getcode.utils.floored
3433import com.getcode.utils.timestamp
3534import com.getcode.view.BaseViewModel2
3635import dagger.hilt.android.lifecycle.HiltViewModel
3736import kotlinx.coroutines.Dispatchers
38- import kotlinx.coroutines.delay
3937import kotlinx.coroutines.flow.Flow
4038import kotlinx.coroutines.flow.distinctUntilChanged
4139import kotlinx.coroutines.flow.filter
@@ -46,6 +44,7 @@ import kotlinx.coroutines.flow.launchIn
4644import kotlinx.coroutines.flow.map
4745import kotlinx.coroutines.flow.mapNotNull
4846import kotlinx.coroutines.flow.onEach
47+ import kotlinx.coroutines.launch
4948import kotlinx.datetime.Instant
5049import timber.log.Timber
5150import java.util.UUID
@@ -56,6 +55,7 @@ class ConversationViewModel @Inject constructor(
5655 private val conversationController : ConversationController ,
5756 features : FeatureRepository ,
5857 tipController : TipController ,
58+ resources : ResourceHelper ,
5959) : BaseViewModel2<ConversationViewModel.State, ConversationViewModel.Event>(
6060 initialState = State .Default ,
6161 updateStateForEvent = updateStateForEvent
@@ -67,6 +67,7 @@ class ConversationViewModel @Inject constructor(
6767 val title : String ,
6868 val textFieldState : TextFieldState ,
6969 val tipChatCash : Feature ,
70+ val identityAvailable : Boolean ,
7071 val identityRevealed : Boolean? ,
7172 val user : User ? ,
7273 val lastSeen : Instant ? ,
@@ -84,6 +85,7 @@ class ConversationViewModel @Inject constructor(
8485 tipChatCash = TipChatCashFeature (),
8586 title = " Anonymous Tipper" ,
8687 textFieldState = TextFieldState (),
88+ identityAvailable = false ,
8789 identityRevealed = null ,
8890 user = null ,
8991 lastSeen = null ,
@@ -111,6 +113,7 @@ class ConversationViewModel @Inject constructor(
111113 data object SendMessage : Event
112114 data object RevealIdentity : Event
113115
116+ data class OnIdentityAvailable (val available : Boolean ): Event
114117 data object OnIdentityRevealed : Event
115118
116119 data class OnPointersUpdated (val pointers : Map <UUID , MessageStatus >) : Event
@@ -169,17 +172,19 @@ class ConversationViewModel @Inject constructor(
169172 }.flatMapLatest { (conversation, _) ->
170173 conversationController.observeConversation(conversation.id)
171174 }.filterNotNull()
172- .map { it.pointers }
173175 .distinctUntilChanged()
174- .onEach {
175- dispatchEvent(Event .OnPointersUpdated (it))
176- }
176+ .onEach { dispatchEvent(Event .OnConversationChanged (it)) }
177177 .launchIn(viewModelScope)
178178
179179 features.tipChatCash
180180 .onEach { dispatchEvent(Event .OnTipsChatCashChanged (it)) }
181181 .launchIn(viewModelScope)
182182
183+ tipController.connectedAccount
184+ .onEach {
185+ dispatchEvent(Event .OnIdentityAvailable (it != null ))
186+ }.launchIn(viewModelScope)
187+
183188 eventFlow
184189 .filterIsInstance<Event .MarkRead >()
185190 .map { it.messageId }
@@ -220,13 +225,34 @@ class ConversationViewModel @Inject constructor(
220225 .filterIsInstance<Event .RevealIdentity >()
221226 .mapNotNull { stateFlow.value.conversationId }
222227 .onEach { conversationId ->
228+ val user = stateFlow.value.user?.username ? : " This user"
223229 val identity = tipController.connectedAccount.value ? : return @onEach
224230 val platform = when (identity) {
225231 is TwitterUser -> Platform .Twitter
226232 }
227- conversationController.revealIdentity(conversationId, platform, identity.username)
228- .onSuccess { dispatchEvent(Event .OnIdentityRevealed ) }
229- .onFailure { it.printStackTrace() }
233+ BottomBarManager .showMessage(
234+ BottomBarManager .BottomBarMessage (
235+ title = resources.getString(R .string.prompt_title_revealIdentity),
236+ subtitle = resources.getString(
237+ R .string.prompt_subtitle_revealIdentity,
238+ user,
239+ identity.username
240+ ),
241+ positiveText = resources.getString(R .string.action_yes),
242+ type = BottomBarManager .BottomBarMessageType .REMOTE_SEND ,
243+ onPositive = {
244+ viewModelScope.launch {
245+ conversationController.revealIdentity(
246+ conversationId,
247+ platform,
248+ identity.username
249+ ).onSuccess { dispatchEvent(Event .OnIdentityRevealed ) }
250+ .onFailure { it.printStackTrace() }
251+ }
252+ },
253+ negativeText = resources.getString(R .string.action_nevermind)
254+ )
255+ )
230256 }
231257 .launchIn(viewModelScope)
232258
@@ -322,6 +348,10 @@ class ConversationViewModel @Inject constructor(
322348 state.copy(pointers = event.pointers)
323349 }
324350
351+ is Event .OnIdentityAvailable -> { state ->
352+ state.copy(identityAvailable = event.available)
353+ }
354+
325355 is Event .OnChatIdChanged ,
326356 is Event .Error ,
327357 Event .RevealIdentity ,
0 commit comments