Skip to content

Commit 4dbd8e8

Browse files
committed
feat: send user settings on app foreground
locale (realistically languageTag), and region (currency code) - used for formatting appreciation push notifications Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 18f25b5 commit 4dbd8e8

19 files changed

Lines changed: 202 additions & 25 deletions

File tree

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/feed/ActivityFeedMessage.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ sealed interface MessageMetadata {
5252
@Serializable
5353
data object Unknown : MessageMetadata
5454

55-
@Serializable
56-
data object WelcomeBonus : MessageMetadata
57-
5855
@Serializable
5956
data object GaveCrypto : MessageMetadata
6057

apps/flipcash/shared/permissions/src/main/kotlin/com/flipcash/app/permissions/CameraPermissionScreen.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/flipcash/shared/persistence/sources/src/main/kotlin/com/flipcash/app/persistence/sources/mapper/notifications/NotificationToEntityMapper.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class MetadataMapper @Inject constructor(): Mapper<NotificationMetadata?, Messag
5959
NotificationMetadata.ReceivedCrypto -> MessageMetadata.ReceivedCrypto
6060
is NotificationMetadata.SentCrypto -> MessageMetadata.SentCrypto(from.creator, from.canCancel)
6161
NotificationMetadata.Unknown -> MessageMetadata.Unknown
62-
NotificationMetadata.WelcomeBonus -> MessageMetadata.WelcomeBonus
6362
NotificationMetadata.WithdrewCrypto -> MessageMetadata.WithdrewCrypto
6463
NotificationMetadata.DepositedCrypto -> MessageMetadata.DepositedCrypto
6564
NotificationMetadata.BoughtToken -> MessageMetadata.BoughtToken

apps/flipcash/shared/session/src/main/kotlin/com/flipcash/app/session/internal/RealSessionController.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.flipcash.app.tokens.TokenCoordinator
3131
import com.flipcash.app.tokens.TokenUpdater
3232
import com.flipcash.core.R
3333
import com.flipcash.services.controllers.AccountController
34+
import com.flipcash.services.controllers.SettingsController
3435
import com.flipcash.services.user.AuthState
3536
import com.flipcash.services.user.UserManager
3637
import com.getcode.manager.BottomBarAction
@@ -105,6 +106,7 @@ class RealSessionController @Inject constructor(
105106
private val billController: BillController,
106107
private val userManager: UserManager,
107108
private val accountController: AccountController,
109+
private val settingsController: SettingsController,
108110
private val feedCoordinator: ActivityFeedCoordinator,
109111
private val transactionController: TransactionController,
110112
private val networkObserver: NetworkConnectivityListener,
@@ -205,6 +207,7 @@ class RealSessionController @Inject constructor(
205207
)
206208
startPolling()
207209
updateUserFlags()
210+
updateSettings()
208211
checkPendingItemsInFeed()
209212
bringActivityFeedCurrent()
210213
shareSheetController.checkForShare()
@@ -258,6 +261,14 @@ class RealSessionController @Inject constructor(
258261
}
259262
}
260263

264+
private fun updateSettings() {
265+
if (userManager.authState.canAccessAuthenticatedApis) {
266+
scope.launch {
267+
settingsController.update()
268+
}
269+
}
270+
}
271+
261272
private fun checkPendingItemsInFeed() {
262273
if (userManager.authState.canAccessAuthenticatedApis) {
263274
scope.launch {

definitions/flipcash/protos/src/main/proto/activity/v1/model.proto

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ message Notification {
2424
NotificationState state = 5;
2525
// Additional metadata for this notification specific to the notification
2626
oneof additional_metadata {
27-
WelcomeBonusNotificationMetadata welcome_bonus = 6;
2827
GaveCryptoNotificationMetadata gave_crypto = 7;
2928
ReceivedCryptoNotificationMetadata received_crypto = 8;
3029
WithdrewCryptoNotificationMetadata withdrew_crypto = 9;
@@ -33,8 +32,7 @@ message Notification {
3332
BoughtCryptoNotificationMetadata bought_crypto = 12;
3433
SoldCryptoNotificationMetadata sold_crypto = 13;
3534
}
36-
}
37-
message WelcomeBonusNotificationMetadata {
35+
reserved 6; // Deprecated WelcomeBonusNotificationMetadata
3836
}
3937
message GaveCryptoNotificationMetadata {
4038
}

definitions/flipcash/protos/src/main/proto/common/v1/common.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,11 @@ message CountryCode {
100100
// ISO 3166-1 Alpha-2
101101
string value = 1 ;
102102
}
103+
// Locale represents an IETF BCP 47 language tag (e.g. "en", "en-US", "zh-Hans-CN")
104+
message Locale {
105+
string value = 1 ;
106+
}
107+
// Region represents a fiat currency region identified by its ISO 4217 alpha-3 currency code (e.g. "usd", "eur")
108+
message Region {
109+
string value = 1 ;
110+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
syntax = "proto3";
2+
package flipcash.settings.v1;
3+
option go_package = "github.com/code-payments/flipcash2-protobuf-api/generated/go/settings/v1;settingspb";
4+
option java_package = "com.codeinc.flipcash.gen.settings.v1";
5+
option objc_class_prefix = "FPBSettingsV1";
6+
import "common/v1/common.proto";
7+
8+
service Settings {
9+
rpc UpdateSettings(UpdateSettingsRequest) returns (UpdateSettingsResponse);
10+
}
11+
message UpdateSettingsRequest {
12+
// Locale setting, only updated if present
13+
common.v1.Locale locale = 1;
14+
// Region setting, only updated if present
15+
common.v1.Region region = 2;
16+
common.v1.Auth auth = 10;
17+
}
18+
message UpdateSettingsResponse {
19+
Result result = 1;
20+
enum Result {
21+
OK = 0;
22+
DENIED = 1;
23+
INVALID_LOCALE = 2;
24+
INVALID_REGION = 3;
25+
}
26+
}

libs/locale/impl/src/main/kotlin/com/getcode/util/locale/AndroidLocale.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import javax.inject.Inject
88
class AndroidLocale @Inject constructor(
99
@ApplicationContext private val context: Context,
1010
): LocaleHelper {
11+
override fun getLanguageTag(): String {
12+
return LocaleUtils.getLanguageTag()
13+
}
14+
1115
override fun getDefaultCurrencyName(): String {
1216
return LocaleUtils.getDefaultCurrency(context)
1317
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.getcode.util.locale
22

33
interface LocaleHelper {
4+
fun getLanguageTag(): String
45
fun getDefaultCurrencyName(): String
56
suspend fun getDefaultCountry(): String?
67
}

libs/locale/public/src/main/kotlin/com/getcode/util/locale/LocaleUtils.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import java.util.*
1414
import java.util.concurrent.TimeUnit
1515

1616
object LocaleUtils {
17+
18+
fun getLanguageTag() = Locale.getDefault().toLanguageTag()
19+
1720
suspend fun getDefaultCountry(context: Context): String? {
1821
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
1922
val networkCountryIso = tm.networkCountryIso.uppercase()
@@ -36,7 +39,7 @@ object LocaleUtils {
3639
val request = Request.Builder().url("http://ip-api.com/json/?fields=countryCode").build()
3740
val response = client.newCall(request).execute()
3841
if (response.isSuccessful) {
39-
val json = JSONObject(response.body?.string() ?: "{}")
42+
val json = JSONObject(response.body.string())
4043
val ipCountry = json.optString("countryCode", "").uppercase()
4144
if (ipCountry.length == 2) ipCountry else "US"
4245
} else null

0 commit comments

Comments
 (0)