Skip to content

Commit 746a90c

Browse files
authored
Merge pull request #560 from code-payments/release/2.1.11
release 2.1.11
2 parents 818d06e + 145b761 commit 746a90c

File tree

105 files changed

+1150
-1021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1150
-1021
lines changed

.github/workflows/build-upload-android-internal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
SERVICE_ACCOUNT_KEY_JSON: ${{ steps.service_account_json_file.outputs.filePath }}
9090

9191
- name: Upload build artifacts
92-
uses: actions/upload-artifact@v2
92+
uses: actions/upload-artifact@v4
9393
with:
9494
name: assets
9595
path: |

api/src/main/java/com/getcode/analytics/AnalyticsManager.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ import timber.log.Timber
1717
import javax.inject.Inject
1818
import javax.inject.Singleton
1919

20-
enum class Action(val value: String) {
21-
CreateAccount("Action: Create Account"),
22-
EnterPhone("Action: Enter Phone"),
23-
VerifyPhone("Action: Verify Phone"),
24-
ConfirmAccessKey("Action: Confirm Access Key"),
25-
CompletedOnboarding("Action: Completed Onboarding"),
20+
sealed class Action(private val _value: String) {
21+
data object CreateAccount : Action("Create Account")
22+
data object EnterPhone : Action("Enter Phone")
23+
data object VerifyPhone : Action("Verify Phone")
24+
data object ConfirmAccessKey : Action("Confirm Access Key")
25+
data object CompletedOnboarding : Action("Completed Onboarding")
26+
data object OpenConnectAccount: Action("Open Connect X Screen")
27+
data object MessageCodeOnX: Action("Message Code on X")
28+
29+
val value: String
30+
get() = "Action: $_value"
2631
}
2732

2833
enum class ActionSource(val value: String) {

api/src/main/java/com/getcode/db/ConversationDao.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.getcode.db
22

3-
import androidx.paging.PagingData
43
import androidx.paging.PagingSource
54
import androidx.room.Dao
65
import androidx.room.Delete
76
import androidx.room.Insert
87
import androidx.room.OnConflictStrategy
98
import androidx.room.Query
109
import androidx.room.RewriteQueriesToDropUnusedColumns
11-
import androidx.room.Transaction
1210
import com.getcode.model.Conversation
1311
import com.getcode.model.ConversationWithLastPointers
1412
import com.getcode.model.ID

api/src/main/java/com/getcode/model/Fiat.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.getcode.model
22

3+
import kotlinx.serialization.Serializable
4+
35
sealed interface Value
46

7+
@Serializable
58
data class Fiat(
69
val currency: CurrencyCode,
710
val amount: Double,

api/src/main/java/com/getcode/model/KinAmount.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ data class KinAmount(
2727
}
2828

2929
companion object {
30+
val Zero = newInstance(0, Rate.oneToOne)
31+
3032
fun newInstance(kin: Int, rate: Rate): KinAmount {
3133
return newInstance(fromKin(kin), rate)
3234
}

api/src/main/java/com/getcode/model/TwitterUser.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.getcode.model
22

33
import android.webkit.MimeTypeMap
44
import com.codeinc.gen.user.v1.IdentityService
5+
import com.codeinc.gen.user.v1.friendshipCostOrNull
56
import com.getcode.solana.keys.PublicKey
67
import com.getcode.solana.keys.base58
78
import com.getcode.utils.serializer.PublicKeyAsStringSerializer
@@ -21,7 +22,9 @@ data class TwitterUser(
2122
override val imageUrl: String?,
2223
val displayName: String,
2324
val followerCount: Int,
24-
val verificationStatus: VerificationStatus
25+
val verificationStatus: VerificationStatus,
26+
val costOfFriendship: Fiat,
27+
val isFriend: Boolean,
2528
): TipMetadata {
2629

2730
override val platform: String = "X"
@@ -52,7 +55,10 @@ data class TwitterUser(
5255
imageUrl = avatarUrl,
5356
followerCount = proto.followerCount,
5457
tipAddress = tipAddress,
55-
verificationStatus = VerificationStatus.entries.getOrNull(proto.verifiedTypeValue) ?: VerificationStatus.unknown
58+
verificationStatus = VerificationStatus.entries.getOrNull(proto.verifiedTypeValue) ?: VerificationStatus.unknown,
59+
// costOfFriendship = kotlin.runCatching { proto.friendshipCostOrNull }.getOrNull()
60+
costOfFriendship = Fiat(currency = CurrencyCode.USD, amount = 1.00),
61+
isFriend = runCatching { proto.isFriend }.getOrNull() ?: false
5662
)
5763
}
5864
}

api/src/main/java/com/getcode/model/chat/MessageContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ sealed interface MessageContent {
340340
proto: MessageContentV1,
341341
): MessageContent? {
342342
return when (proto.typeCase) {
343-
ChatServiceV1.Content.TypeCase.LOCALIZED -> Localized(
343+
ChatServiceV1.Content.TypeCase.SERVER_LOCALIZED -> Localized(
344344
isFromSelf = false,
345-
value = proto.localized.keyOrText
345+
value = proto.serverLocalized.keyOrText
346346
)
347347

348348
ChatServiceV1.Content.TypeCase.EXCHANGE_DATA -> {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.getcode.network
2+
3+
import androidx.paging.Pager
4+
import androidx.paging.PagingConfig
5+
import androidx.paging.PagingSource
6+
import androidx.paging.PagingState
7+
import com.getcode.model.chat.Chat
8+
import javax.inject.Inject
9+
10+
class ConversationListController @Inject constructor(
11+
private val historyController: ChatHistoryController,
12+
) {
13+
private val pagingConfig = PagingConfig(pageSize = 20)
14+
15+
fun observeConversations() =
16+
Pager(
17+
config = pagingConfig,
18+
initialKey = null,
19+
) { ChatPagingSource(historyController.chats.value.orEmpty()) }.flow
20+
}
21+
22+
class ChatPagingSource(
23+
private val chats: List<Chat>
24+
) : PagingSource<Int, Chat>() {
25+
26+
override fun getRefreshKey(state: PagingState<Int, Chat>): Int? {
27+
return state.anchorPosition?.let { anchorPosition ->
28+
val anchorPage = state.closestPageToPosition(anchorPosition)
29+
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1)
30+
}
31+
}
32+
33+
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Chat> {
34+
val currentList = chats
35+
val position = params.key ?: 0
36+
val pageSize = params.loadSize
37+
38+
return try {
39+
val items = currentList.subList(
40+
position.coerceAtMost(currentList.size),
41+
(position + pageSize).coerceAtMost(currentList.size)
42+
)
43+
44+
LoadResult.Page(
45+
data = items,
46+
prevKey = if (position > 0) position - pageSize else null,
47+
nextKey = if (position + pageSize < currentList.size) position + pageSize else null
48+
)
49+
} catch (e: Exception) {
50+
LoadResult.Error(e)
51+
}
52+
}
53+
}

api/src/main/java/com/getcode/network/TipController.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import kotlin.concurrent.fixedRateTimer
3939

4040
typealias TipUser = Pair<String, CodePayload>
4141

42+
4243
@Singleton
4344
class TipController @Inject constructor(
4445
private val client: Client,
@@ -108,10 +109,11 @@ class TipController @Inject constructor(
108109

109110
private suspend fun callForConnectedUser() {
110111
Timber.d("twitter poll call")
111-
val tipAddress = SessionManager.getOrganizer()?.primaryVault ?: return
112+
val organizer = SessionManager.getOrganizer() ?: return
113+
val tipAddress = organizer.primaryVault
112114
// only set lastPoll if we actively attempt to reach RPC
113115
lastPoll = System.currentTimeMillis()
114-
client.fetchTwitterUser(tipAddress)
116+
client.fetchTwitterUser(organizer, tipAddress)
115117
.onSuccess {
116118
Timber.d("current user twitter connected @ ${it.username}")
117119
prefRepository.set(PrefsString.KEY_TIP_ACCOUNT, Json.encodeToString(it))
@@ -152,10 +154,11 @@ class TipController @Inject constructor(
152154
}
153155

154156
suspend fun fetch(username: String): TwitterUser? {
157+
val organizer = SessionManager.getOrganizer() ?: return null
155158
val key = username.lowercase()
156159
return cachedUsers.getOrPutIfNonNull(key) {
157160
Timber.d("fetching user $username")
158-
client.fetchTwitterUser(username).getOrThrow()
161+
client.fetchTwitterUser(organizer, username).getOrThrow()
159162
}
160163
}
161164

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.getcode.network
2+
3+
import com.getcode.manager.SessionManager
4+
import com.getcode.model.TwitterUser
5+
import com.getcode.network.client.Client
6+
import com.getcode.network.client.fetchTwitterUser
7+
import com.getcode.network.repository.BetaFlagsRepository
8+
import com.getcode.network.repository.PrefRepository
9+
import com.getcode.utils.getOrPutIfNonNull
10+
import timber.log.Timber
11+
import javax.inject.Inject
12+
import javax.inject.Singleton
13+
14+
@Singleton
15+
class TwitterUserController @Inject constructor(
16+
private val client: Client,
17+
betaFlags: BetaFlagsRepository,
18+
private val prefRepository: PrefRepository,
19+
) {
20+
private var cachedUsers = mutableMapOf<String, TwitterUser>()
21+
22+
23+
suspend fun fetchUser(username: String, ignoreCache: Boolean = false): TwitterUser? {
24+
val organizer = SessionManager.getOrganizer() ?: return null
25+
val key = username.lowercase()
26+
27+
if (ignoreCache) {
28+
val user = client.fetchTwitterUser(organizer, username).getOrThrow()
29+
cachedUsers[key] = user
30+
return user
31+
}
32+
33+
return cachedUsers.getOrPutIfNonNull(key) {
34+
Timber.d("fetching user $username")
35+
client.fetchTwitterUser(organizer, username).getOrThrow()
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)