Skip to content

Commit

Permalink
Merge branch 'main' into gg/enhancement/add_sender_hmac_to_message_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
giovasdistillery authored Feb 8, 2024
2 parents 4252ee9 + 165f2b2 commit 4d4c0f7
Show file tree
Hide file tree
Showing 52 changed files with 1,403 additions and 216 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'
- name: Gradle Run ktlint
run: ./gradlew ktlintCheck --continue
- uses: actions/upload-artifact@v2
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '17'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/actions/setup-gradle@v3
- name: Run build with Gradle Wrapper
run: ./gradlew build
- name: Bump version and push tag
Expand Down
48 changes: 22 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,42 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3
- uses: actions/setup-java@v3
uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11'
java-version: '17'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Start local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml up -d
uses: gradle/actions/setup-gradle@v3
- name: Start Docker containers
run: dev/up
- name: Gradle Run Unit Tests
run: ./gradlew library:testDebug
- name: Stop local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml down
library-integration:
name: Library (Integration Tests)
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3
- uses: actions/setup-java@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11'
java-version: '17'
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Set up Docker
run: brew install docker docker-compose
- name: Start Colima
run: colima start
- name: Start local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml up -d
uses: gradle/actions/setup-gradle@v3
- name: Start Docker containers
run: dev/up
- name: Gradle Run Integration Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
script: ./gradlew connectedCheck
- name: Stop local test server
run: docker-compose -p xmtp -f dev/local/docker-compose.yml down

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//}

plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'io.github.gradle-nexus.publish-plugin' version "1.2.0"
id "org.jetbrains.dokka" version "1.8.10"
Expand Down
4 changes: 4 additions & 0 deletions dev/local/compose
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -eou pipefail

docker-compose -f dev/local/docker-compose.yml -p "xmtp-android" "$@"
19 changes: 16 additions & 3 deletions dev/local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
waku-node:
node:
image: xmtp/node-go:latest
platform: linux/amd64
environment:
Expand All @@ -8,14 +8,27 @@ services:
- --store.enable
- --store.db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --store.reader-db-connection-string=postgres://postgres:xmtp@db:5432/postgres?sslmode=disable
- --mls-store.db-connection-string=postgres://postgres:xmtp@mlsdb:5432/postgres?sslmode=disable
- --mls-validation.grpc-address=validation:50051
- --api.enable-mls
- --wait-for-db=30s
- --api.authn.enable
ports:
- 9001:9001
- 5555:5555
- 5556:5556
depends_on:
- db

validation:
image: ghcr.io/xmtp/mls-validation-service:main
platform: linux/amd64

db:
image: postgres:13
environment:
POSTGRES_PASSWORD: xmtp
POSTGRES_PASSWORD: xmtp

mlsdb:
image: postgres:13
environment:
POSTGRES_PASSWORD: xmtp
6 changes: 6 additions & 0 deletions dev/local/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -eou pipefail
script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

"${script_dir}"/compose pull
"${script_dir}"/compose up -d --build
18 changes: 18 additions & 0 deletions dev/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eou pipefail

if [[ "${OSTYPE}" == "darwin"* ]]; then
if ! which buf &>/dev/null; then brew install buf; fi
if ! which shellcheck &>/dev/null; then brew install shellcheck; fi
if ! which markdownlint &>/dev/null; then brew install markdownlint-cli; fi
if ! java -version &>/dev/null; then
brew install java
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/
fi
if ! kotlinc -version &>/dev/null; then brew install kotlin; fi
fi

rustup update

dev/local/up
25 changes: 11 additions & 14 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
lifecycle_version = '2.6.0'
lifecycle_version = '2.7.0'
}

}
Expand Down Expand Up @@ -36,34 +36,31 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
configurations {
all*.exclude module: "bcprov-jdk15to18" // Needed for dev.pinkroom.walletconnectkit
}
}

dependencies {
implementation project(':library')
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.core:core-ktx:1.12.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.firebase:firebase-messaging:23.1.2'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.google.firebase:firebase-messaging:23.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'androidx.activity:activity-ktx:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'org.web3j:crypto:5.0.0'

// WalletConnect V2: core library + WalletConnectModal
Expand All @@ -72,7 +69,7 @@ dependencies {
implementation("com.walletconnect:walletconnect-modal")

//Navigation Component
def nav_version = "2.7.5"
def nav_version = "2.7.6"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

Expand Down
19 changes: 16 additions & 3 deletions example/src/main/java/org/xmtp/android/example/ClientManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xmtp.android.example

import android.content.Context
import androidx.annotation.UiThread
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand All @@ -10,10 +11,21 @@ import org.xmtp.android.library.Client
import org.xmtp.android.library.ClientOptions
import org.xmtp.android.library.XMTPEnvironment
import org.xmtp.android.library.messages.PrivateKeyBundleV1Builder
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChangeCodec

object ClientManager {

val CLIENT_OPTIONS = ClientOptions(api = ClientOptions.Api(XMTPEnvironment.DEV, appVersion = "XMTPAndroidExample/v1.0.0"))
fun clientOptions(appContext: Context?): ClientOptions {
return ClientOptions(
api = ClientOptions.Api(
XMTPEnvironment.DEV,
appVersion = "XMTPAndroidExample/v1.0.0",
isSecure = true
),
enableAlphaMls = true,
appContext = appContext
)
}

private val _clientState = MutableStateFlow<ClientState>(ClientState.Unknown)
val clientState: StateFlow<ClientState> = _clientState
Expand All @@ -28,13 +40,14 @@ object ClientManager {
}

@UiThread
fun createClient(encodedPrivateKeyData: String) {
fun createClient(encodedPrivateKeyData: String, appContext: Context) {
if (clientState.value is ClientState.Ready) return
GlobalScope.launch(Dispatchers.IO) {
try {
val v1Bundle =
PrivateKeyBundleV1Builder.fromEncodedData(data = encodedPrivateKeyData)
_client = Client().buildFrom(v1Bundle, CLIENT_OPTIONS)
_client = Client().buildFrom(v1Bundle, clientOptions(appContext))
Client.register(codec = GroupMembershipChangeCodec())
_clientState.value = ClientState.Ready
} catch (e: Exception) {
_clientState.value = ClientState.Error(e.localizedMessage.orEmpty())
Expand Down
17 changes: 16 additions & 1 deletion example/src/main/java/org/xmtp/android/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.xmtp.android.example.conversation.ConversationDetailActivity
import org.xmtp.android.example.conversation.ConversationsAdapter
import org.xmtp.android.example.conversation.ConversationsClickListener
import org.xmtp.android.example.conversation.NewConversationBottomSheet
import org.xmtp.android.example.conversation.NewGroupBottomSheet
import org.xmtp.android.example.databinding.ActivityMainBinding
import org.xmtp.android.example.pushnotifications.PushNotificationTokenManager
import org.xmtp.android.example.utils.KeyUtil
Expand All @@ -35,6 +36,7 @@ class MainActivity : AppCompatActivity(),
private lateinit var accountManager: AccountManager
private lateinit var adapter: ConversationsAdapter
private var bottomSheet: NewConversationBottomSheet? = null
private var groupBottomSheet: NewGroupBottomSheet? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -48,7 +50,7 @@ class MainActivity : AppCompatActivity(),
return
}

ClientManager.createClient(keys)
ClientManager.createClient(keys, this)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
Expand All @@ -67,6 +69,10 @@ class MainActivity : AppCompatActivity(),
openConversationDetail()
}

binding.groupFab.setOnClickListener {
openGroupDetail()
}

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
ClientManager.clientState.collect(::ensureClientState)
Expand All @@ -86,6 +92,7 @@ class MainActivity : AppCompatActivity(),

override fun onDestroy() {
bottomSheet?.dismiss()
groupBottomSheet?.dismiss()
super.onDestroy()
}

Expand Down Expand Up @@ -127,6 +134,7 @@ class MainActivity : AppCompatActivity(),
is ClientManager.ClientState.Ready -> {
viewModel.fetchConversations()
binding.fab.visibility = View.VISIBLE
binding.groupFab.visibility = View.VISIBLE
}
is ClientManager.ClientState.Error -> showError(clientState.message)
is ClientManager.ClientState.Unknown -> Unit
Expand Down Expand Up @@ -193,4 +201,11 @@ class MainActivity : AppCompatActivity(),
NewConversationBottomSheet.TAG
)
}
private fun openGroupDetail() {
groupBottomSheet = NewGroupBottomSheet.newInstance()
groupBottomSheet?.show(
supportFragmentManager,
NewGroupBottomSheet.TAG
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MainViewModel : ViewModel() {
viewModelScope.launch(Dispatchers.IO) {
val listItems = mutableListOf<MainListItem>()
try {
val conversations = ClientManager.client.conversations.list()
val conversations = ClientManager.client.conversations.list(includeGroups = true)
PushNotificationTokenManager.xmtpPush.subscribe(conversations.map { it.topic })
listItems.addAll(
conversations.map { conversation ->
Expand Down Expand Up @@ -77,7 +77,7 @@ class MainViewModel : ViewModel() {
val stream: StateFlow<MainListItem?> =
stateFlow(viewModelScope, null) { subscriptionCount ->
if (ClientManager.clientState.value is ClientManager.ClientState.Ready) {
ClientManager.client.conversations.stream()
ClientManager.client.conversations.streamAll()
.flowWhileShared(
subscriptionCount,
SharingStarted.WhileSubscribed(1000L)
Expand Down
Loading

0 comments on commit 4d4c0f7

Please sign in to comment.