Skip to content

Commit 12515ad

Browse files
Merge pull request #1651 from session-foundation/feature/more-pro-states
Feature/more pro states
2 parents bb5fc1d + 61c05e5 commit 12515ad

35 files changed

+1176
-714
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,12 @@ android {
181181
matchingFallbacks += "release"
182182

183183
signingConfig = signingConfigs.getByName("debug")
184-
applicationIdSuffix = ".$name"
185184

186185
devNetDefaultOn(false)
187186
enablePermissiveNetworkSecurityConfig(true)
188187

189188
setAlternativeAppName("Session QA")
190-
setAuthorityPostfix(".qa")
189+
setAuthorityPostfix("")
191190
}
192191

193192
create("automaticQa") {

app/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ interface TextSecurePreferences {
222222
fun setDebugProPlanStatus(status: DebugMenuViewModel.DebugProPlanStatus?)
223223
fun getDebugForceNoBilling(): Boolean
224224
fun setDebugForceNoBilling(hasBilling: Boolean)
225+
fun getDebugIsWithinQuickRefund(): Boolean
226+
fun setDebugIsWithinQuickRefund(isWithin: Boolean)
225227

226228
fun setSubscriptionProvider(provider: String)
227229
fun getSubscriptionProvider(): String?
@@ -388,6 +390,7 @@ interface TextSecurePreferences {
388390
const val DEBUG_SUBSCRIPTION_STATUS = "debug_subscription_status"
389391
const val DEBUG_PRO_PLAN_STATUS = "debug_pro_plan_status"
390392
const val DEBUG_FORCE_NO_BILLING = "debug_pro_has_billing"
393+
const val DEBUG_WITHIN_QUICK_REFUND = "debug_within_quick_refund"
391394

392395
const val SUBSCRIPTION_PROVIDER = "session_subscription_provider"
393396
const val DEBUG_AVATAR_REUPLOAD = "debug_avatar_reupload"
@@ -1799,6 +1802,15 @@ class AppTextSecurePreferences @Inject constructor(
17991802
_events.tryEmit(TextSecurePreferences.DEBUG_FORCE_NO_BILLING)
18001803
}
18011804

1805+
override fun getDebugIsWithinQuickRefund(): Boolean {
1806+
return getBooleanPreference(TextSecurePreferences.DEBUG_WITHIN_QUICK_REFUND, false)
1807+
}
1808+
1809+
override fun setDebugIsWithinQuickRefund(isWithin: Boolean) {
1810+
setBooleanPreference(TextSecurePreferences.DEBUG_WITHIN_QUICK_REFUND, isWithin)
1811+
_events.tryEmit(TextSecurePreferences.DEBUG_FORCE_NO_BILLING)
1812+
}
1813+
18021814
override fun getSubscriptionProvider(): String? {
18031815
return getStringPreference(TextSecurePreferences.SUBSCRIPTION_PROVIDER, null)
18041816
}

app/src/main/java/org/thoughtcrime/securesms/InputBarDialogs.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ fun InputBarDialogs(
6363
}
6464

6565
// Pro CTA
66-
if (inputBarDialogsState.sessionProCharLimitCTA) {
66+
if (inputBarDialogsState.sessionProCharLimitCTA != null) {
6767
LongMessageProCTA(
68+
proSubscription = inputBarDialogsState.sessionProCharLimitCTA.proSubscription,
6869
onDismissRequest = {sendCommand(InputbarViewModel.Commands.HideSessionProCTA)}
6970
)
7071
}

app/src/main/java/org/thoughtcrime/securesms/InputbarViewModel.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.session.libsession.utilities.recipients.isPro
1212
import org.session.libsession.utilities.recipients.shouldShowProBadge
1313
import org.thoughtcrime.securesms.database.RecipientRepository
1414
import org.thoughtcrime.securesms.pro.ProStatusManager
15+
import org.thoughtcrime.securesms.pro.SubscriptionType
1516
import org.thoughtcrime.securesms.ui.SimpleDialogData
1617
import org.thoughtcrime.securesms.util.NumberUtil
1718

@@ -94,7 +95,7 @@ abstract class InputbarViewModel(
9495

9596
fun showSessionProCTA(){
9697
_inputBarStateDialogsState.update {
97-
it.copy(sessionProCharLimitCTA = true)
98+
it.copy(sessionProCharLimitCTA = CharLimitCTAData(proStatusManager.subscriptionState.value.type))
9899
}
99100
}
100101

@@ -165,7 +166,7 @@ abstract class InputbarViewModel(
165166

166167
is Commands.HideSessionProCTA -> {
167168
_inputBarStateDialogsState.update {
168-
it.copy(sessionProCharLimitCTA = false)
169+
it.copy(sessionProCharLimitCTA = null)
169170
}
170171
}
171172
}
@@ -195,7 +196,11 @@ abstract class InputbarViewModel(
195196

196197
data class InputBarDialogsState(
197198
val showSimpleDialog: SimpleDialogData? = null,
198-
val sessionProCharLimitCTA: Boolean = false
199+
val sessionProCharLimitCTA: CharLimitCTAData? = null
200+
)
201+
202+
data class CharLimitCTAData(
203+
val proSubscription: SubscriptionType
199204
)
200205

201206
sealed interface Commands {

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,22 @@ fun MessageDetailDialogs(
706706
if(state.proBadgeCTA != null){
707707
when(state.proBadgeCTA){
708708
is ProBadgeCTA.Generic ->
709-
GenericProCTA(onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)})
709+
GenericProCTA(
710+
proSubscription = state.proBadgeCTA.proSubscription,
711+
onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)}
712+
)
710713

711714
is ProBadgeCTA.LongMessage ->
712-
LongMessageProCTA(onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)})
715+
LongMessageProCTA(
716+
proSubscription = state.proBadgeCTA.proSubscription,
717+
onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)}
718+
)
713719

714720
is ProBadgeCTA.AnimatedProfile ->
715-
AnimatedProfilePicProCTA(onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)})
721+
AnimatedProfilePicProCTA(
722+
proSubscription = state.proBadgeCTA.proSubscription,
723+
onDismissRequest = {sendCommand(Commands.HideProBadgeCTA)}
724+
)
716725
}
717726
}
718727

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.mms.Slide
5151
import org.thoughtcrime.securesms.pro.ProStatusManager
5252
import org.thoughtcrime.securesms.pro.ProStatusManager.MessageProFeature.AnimatedAvatar
5353
import org.thoughtcrime.securesms.pro.ProStatusManager.MessageProFeature.LongMessage
54+
import org.thoughtcrime.securesms.pro.SubscriptionType
5455
import org.thoughtcrime.securesms.ui.GetString
5556
import org.thoughtcrime.securesms.ui.TitledText
5657
import org.thoughtcrime.securesms.util.AvatarUIData
@@ -283,13 +284,14 @@ class MessageDetailsViewModel @AssistedInject constructor(
283284
is Commands.ShowProBadgeCTA -> {
284285
val features = state.value.proFeatures
285286
_dialogState.update {
287+
val proSubscription = proStatusManager.subscriptionState.value.type
286288
it.copy(
287289
proBadgeCTA = when{
288-
features.size > 1 -> ProBadgeCTA.Generic // always show the generic cta when there are more than 1 feature
290+
features.size > 1 -> ProBadgeCTA.Generic(proSubscription) // always show the generic cta when there are more than 1 feature
289291

290-
features.contains(LongMessage) -> ProBadgeCTA.LongMessage
291-
features.contains(AnimatedAvatar) -> ProBadgeCTA.AnimatedProfile
292-
else -> ProBadgeCTA.Generic
292+
features.contains(LongMessage) -> ProBadgeCTA.LongMessage(proSubscription)
293+
features.contains(AnimatedAvatar) -> ProBadgeCTA.AnimatedProfile(proSubscription)
294+
else -> ProBadgeCTA.Generic(proSubscription)
293295
}
294296
)
295297
}
@@ -369,10 +371,10 @@ data class MessageDetailsState(
369371
val canDelete: Boolean get() = !readOnly
370372
}
371373

372-
sealed interface ProBadgeCTA {
373-
data object Generic: ProBadgeCTA
374-
data object LongMessage: ProBadgeCTA
375-
data object AnimatedProfile: ProBadgeCTA
374+
sealed class ProBadgeCTA(open val proSubscription: SubscriptionType) {
375+
data class Generic(override val proSubscription: SubscriptionType): ProBadgeCTA(proSubscription)
376+
data class LongMessage(override val proSubscription: SubscriptionType): ProBadgeCTA(proSubscription)
377+
data class AnimatedProfile(override val proSubscription: SubscriptionType): ProBadgeCTA(proSubscription)
376378
}
377379

378380
data class DialogsState(

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsDialogs.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.thoughtcrime.securesms.conversation.v2.settings.ConversationSettingsV
3636
import org.thoughtcrime.securesms.conversation.v2.settings.ConversationSettingsViewModel.Commands.UpdateGroupDescription
3737
import org.thoughtcrime.securesms.conversation.v2.settings.ConversationSettingsViewModel.Commands.UpdateGroupName
3838
import org.thoughtcrime.securesms.conversation.v2.settings.ConversationSettingsViewModel.Commands.UpdateNickname
39+
import org.thoughtcrime.securesms.pro.SubscriptionType
3940
import org.thoughtcrime.securesms.ui.AlertDialog
4041
import org.thoughtcrime.securesms.ui.CTAImage
4142
import org.thoughtcrime.securesms.ui.DialogButtonData
@@ -232,6 +233,7 @@ fun ConversationSettingsDialogs(
232233
// pin CTA
233234
if(dialogsState.pinCTA != null){
234235
PinProCTA(
236+
proSubscription = dialogsState.pinCTA.proSubscription,
235237
overTheLimit = dialogsState.pinCTA.overTheLimit,
236238
onDismissRequest = {
237239
sendCommand(HidePinCTADialog)
@@ -242,6 +244,7 @@ fun ConversationSettingsDialogs(
242244
when(dialogsState.proBadgeCTA){
243245
is ConversationSettingsViewModel.ProBadgeCTA.Generic -> {
244246
GenericProCTA(
247+
proSubscription = dialogsState.proBadgeCTA.proSubscription,
245248
onDismissRequest = {
246249
sendCommand(HideProBadgeCTA)
247250
}
@@ -438,7 +441,7 @@ fun PreviewCTAGroupDialog() {
438441
PreviewTheme {
439442
ConversationSettingsDialogs(
440443
dialogsState = ConversationSettingsViewModel.DialogsState(
441-
proBadgeCTA = ConversationSettingsViewModel.ProBadgeCTA.Group
444+
proBadgeCTA = ConversationSettingsViewModel.ProBadgeCTA.Group(SubscriptionType.NeverSubscribed)
442445
),
443446
sendCommand = {}
444447
)

app/src/main/java/org/thoughtcrime/securesms/conversation/v2/settings/ConversationSettingsViewModel.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.dependencies.ConfigFactory.Companion.MAX_NAME_
6060
import org.thoughtcrime.securesms.groups.OpenGroupManager
6161
import org.thoughtcrime.securesms.home.HomeActivity
6262
import org.thoughtcrime.securesms.pro.ProStatusManager
63+
import org.thoughtcrime.securesms.pro.SubscriptionType
6364
import org.thoughtcrime.securesms.repository.ConversationRepository
6465
import org.thoughtcrime.securesms.ui.SimpleDialogData
6566
import org.thoughtcrime.securesms.ui.UINavigator
@@ -719,7 +720,10 @@ class ConversationSettingsViewModel @AssistedInject constructor(
719720
if(totalPins >= maxPins){
720721
// the user has reached the pin limit, show the CTA
721722
_dialogState.update {
722-
it.copy(pinCTA = PinProCTA(overTheLimit = totalPins > maxPins))
723+
it.copy(pinCTA = PinProCTA(
724+
overTheLimit = totalPins > maxPins,
725+
proSubscription = proStatusManager.subscriptionState.value.type
726+
))
723727
}
724728
} else {
725729
viewModelScope.launch {
@@ -1236,8 +1240,8 @@ class ConversationSettingsViewModel @AssistedInject constructor(
12361240
is Commands.ShowProBadgeCTA -> {
12371241
_dialogState.update {
12381242
it.copy(
1239-
proBadgeCTA = if(recipient?.isGroupV2Recipient == true) ProBadgeCTA.Group
1240-
else ProBadgeCTA.Generic
1243+
proBadgeCTA = if(recipient?.isGroupV2Recipient == true) ProBadgeCTA.Group(proStatusManager.subscriptionState.value.type)
1244+
else ProBadgeCTA.Generic(proStatusManager.subscriptionState.value.type)
12411245
)
12421246
}
12431247
}
@@ -1441,12 +1445,13 @@ class ConversationSettingsViewModel @AssistedInject constructor(
14411445
)
14421446

14431447
data class PinProCTA(
1444-
val overTheLimit: Boolean
1448+
val overTheLimit: Boolean,
1449+
val proSubscription: SubscriptionType
14451450
)
14461451

1447-
sealed interface ProBadgeCTA {
1448-
data object Generic: ProBadgeCTA
1449-
data object Group: ProBadgeCTA
1452+
sealed class ProBadgeCTA(open val proSubscription: SubscriptionType) {
1453+
data class Generic(override val proSubscription: SubscriptionType): ProBadgeCTA(proSubscription)
1454+
data class Group(override val proSubscription: SubscriptionType): ProBadgeCTA(proSubscription)
14501455
}
14511456

14521457
data class NicknameDialogData(

app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenu.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ fun DebugMenu(
278278
)
279279
}
280280
)
281+
282+
Spacer(modifier = Modifier.height(LocalDimensions.current.xsSpacing))
283+
DebugSwitchRow(
284+
text = "Is Within Quick Refund Window",
285+
checked = uiState.withinQuickRefund,
286+
onCheckedChange = {
287+
sendCommand(DebugMenuViewModel.Commands.WithinQuickRefund(it))
288+
}
289+
)
281290
}
282291
}
283292

@@ -831,6 +840,7 @@ fun PreviewDebugMenu() {
831840
selectedDebugProPlanStatus = DebugMenuViewModel.DebugProPlanStatus.NORMAL,
832841
debugProPlans = emptyList(),
833842
forceNoBilling = false,
843+
withinQuickRefund = true,
834844
forceDeterministicEncryption = false,
835845
debugAvatarReupload = true,
836846
),

app/src/main/java/org/thoughtcrime/securesms/debugmenu/DebugMenuViewModel.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class DebugMenuViewModel @Inject constructor(
110110
.flatMap { it.availablePlans.asSequence().map { plan -> DebugProPlan(it, plan) } }
111111
.toList(),
112112
forceNoBilling = textSecurePreferences.getDebugForceNoBilling(),
113+
withinQuickRefund = textSecurePreferences.getDebugIsWithinQuickRefund(),
113114
availableAltFileServers = TEST_FILE_SERVERS,
114115
alternativeFileServer = textSecurePreferences.alternativeFileServer,
115116
)
@@ -285,6 +286,13 @@ class DebugMenuViewModel @Inject constructor(
285286
}
286287
}
287288

289+
is Commands.WithinQuickRefund -> {
290+
textSecurePreferences.setDebugIsWithinQuickRefund(command.set)
291+
_uiState.update {
292+
it.copy(withinQuickRefund = command.set)
293+
}
294+
}
295+
288296
is Commands.ForcePostPro -> {
289297
textSecurePreferences.setForcePostPro(command.set)
290298
_uiState.update {
@@ -333,7 +341,9 @@ class DebugMenuViewModel @Inject constructor(
333341
}
334342

335343
is Commands.PurchaseDebugPlan -> {
336-
command.plan.apply { manager.purchasePlan(plan) }
344+
viewModelScope.launch {
345+
command.plan.apply { manager.purchasePlan(plan) }
346+
}
337347
}
338348

339349
is Commands.ToggleDeterministicEncryption -> {
@@ -469,6 +479,7 @@ class DebugMenuViewModel @Inject constructor(
469479
val selectedDebugProPlanStatus: DebugProPlanStatus,
470480
val debugProPlans: List<DebugProPlan>,
471481
val forceNoBilling: Boolean,
482+
val withinQuickRefund: Boolean,
472483
val alternativeFileServer: FileServer? = null,
473484
val availableAltFileServers: List<FileServer> = emptyList(),
474485
)
@@ -509,6 +520,7 @@ class DebugMenuViewModel @Inject constructor(
509520
data class ForceOtherUsersAsPro(val set: Boolean) : Commands()
510521
data class ForceIncomingMessagesAsPro(val set: Boolean) : Commands()
511522
data class ForceNoBilling(val set: Boolean) : Commands()
523+
data class WithinQuickRefund(val set: Boolean) : Commands()
512524
data class ForcePostPro(val set: Boolean) : Commands()
513525
data class ForceShortTTl(val set: Boolean) : Commands()
514526
data class SetMessageProFeature(val feature: ProStatusManager.MessageProFeature, val set: Boolean) : Commands()

0 commit comments

Comments
 (0)