Skip to content

Commit 830887f

Browse files
committed
feat: add confirmation modal to reveal identity
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent f773696 commit 830887f

3 files changed

Lines changed: 49 additions & 12 deletions

File tree

app/src/main/java/com/getcode/view/main/chat/conversation/ChatConversationScreen.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.ui.text.font.FontWeight
3030
import androidx.compose.ui.text.style.TextDecoration
3131
import androidx.compose.ui.text.withStyle
3232
import androidx.paging.compose.LazyPagingItems
33+
import com.getcode.manager.BottomBarManager
3334
import com.getcode.theme.CodeTheme
3435
import com.getcode.ui.components.CodeScaffold
3536
import com.getcode.ui.components.chat.utils.ChatItem
@@ -48,7 +49,11 @@ fun ChatConversationScreen(
4849
CodeScaffold(
4950
topBar = {
5051
IdentityRevealHeader(state = state) {
51-
dispatchEvent(ConversationViewModel.Event.RevealIdentity)
52+
if (state.identityAvailable) {
53+
dispatchEvent(ConversationViewModel.Event.RevealIdentity)
54+
} else {
55+
// TODO: connect UI flow
56+
}
5257
}
5358
},
5459
bottomBar = {

app/src/main/java/com/getcode/view/main/chat/conversation/ConversationViewModel.kt

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import androidx.paging.PagingData
1010
import androidx.paging.flatMap
1111
import androidx.paging.map
1212
import com.getcode.BuildConfig
13+
import com.getcode.R
14+
import com.getcode.manager.BottomBarManager
1315
import com.getcode.model.ConversationWithLastPointers
1416
import com.getcode.model.Feature
1517
import com.getcode.model.ID
@@ -23,19 +25,15 @@ import com.getcode.model.uuid
2325
import com.getcode.network.ConversationController
2426
import com.getcode.network.TipController
2527
import com.getcode.network.repository.FeatureRepository
26-
import com.getcode.solana.keys.PublicKey
2728
import com.getcode.ui.components.chat.utils.ChatItem
2829
import com.getcode.ui.components.chat.utils.ConversationMessageIndice
29-
import com.getcode.util.CurrencyUtils
3030
import com.getcode.util.resources.ResourceHelper
3131
import com.getcode.util.toInstantFromMillis
3232
import com.getcode.utils.ErrorUtils
33-
import com.getcode.utils.floored
3433
import com.getcode.utils.timestamp
3534
import com.getcode.view.BaseViewModel2
3635
import dagger.hilt.android.lifecycle.HiltViewModel
3736
import kotlinx.coroutines.Dispatchers
38-
import kotlinx.coroutines.delay
3937
import kotlinx.coroutines.flow.Flow
4038
import kotlinx.coroutines.flow.distinctUntilChanged
4139
import kotlinx.coroutines.flow.filter
@@ -46,6 +44,7 @@ import kotlinx.coroutines.flow.launchIn
4644
import kotlinx.coroutines.flow.map
4745
import kotlinx.coroutines.flow.mapNotNull
4846
import kotlinx.coroutines.flow.onEach
47+
import kotlinx.coroutines.launch
4948
import kotlinx.datetime.Instant
5049
import timber.log.Timber
5150
import 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,

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@
4343
<string name="error_description_missingBiometrics">Biometrics are no longer available on your device.</string>
4444

4545
<string name="title_accessKeySnapshotDescription">Warning! This image gives access to all the funds you have in Code. Do not share this image with anyone else.\nKeep it secure and safe.</string>
46+
<string name="prompt_title_revealIdentity">Reveal your identity?</string>
47+
<string name="prompt_subtitle_revealIdentity">%1$s will be able to see that you are %2$s.</string>
4648
</resources>

0 commit comments

Comments
 (0)