From ee0e885b092e6db89fa080b69f5a2aad83f91fb7 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Wed, 5 Jun 2024 14:58:17 -0400 Subject: [PATCH] Fetch demo user from Rust --- WordPress/build.gradle | 5 +++ .../android/ui/posts/PostListMainViewModel.kt | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 8ebe0ab44ae4..85b4e2682034 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -41,6 +41,7 @@ repositories { includeGroup "org.wordpress.fluxc" includeGroup "org.wordpress.wellsql" includeGroup "org.wordpress.gutenberg-mobile" + includeGroup "rs.wordpress.api" includeGroupByRegex "org.wordpress.react-native-libraries.*" includeGroup "com.automattic" includeGroup "com.automattic.tracks" @@ -350,6 +351,10 @@ static def addBuildConfigFieldsFromPrefixedProperties(variant, properties, prefi } dependencies { + implementation('rs.wordpress.api:android:0.1-rc-9') { + exclude group: "net.java.dev.jna" + } + implementation 'net.java.dev.jna:jna:5.13.0@aar' implementation 'androidx.webkit:webkit:1.11.0' implementation "androidx.navigation:navigation-compose:$androidxComposeNavigationVersion" compileOnly project(path: ':libs:annotations') diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt index 9b0cdc7c8048..191472092bf9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt @@ -41,6 +41,7 @@ import org.wordpress.android.ui.posts.PostListType.TRASHED import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.ui.uploads.UploadActionUseCase import org.wordpress.android.ui.uploads.UploadStarter +import org.wordpress.android.ui.utils.UiString import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.AppLog import org.wordpress.android.util.NetworkUtilsWrapper @@ -54,6 +55,9 @@ import org.wordpress.android.viewmodel.helpers.ToastMessageHolder import org.wordpress.android.viewmodel.posts.PostFetcher import org.wordpress.android.viewmodel.posts.PostListItemIdentifier.LocalPostId import org.wordpress.android.viewmodel.posts.PostListViewModelConnector +import rs.wordpress.api.kotlin.WpApiClient +import rs.wordpress.api.kotlin.WpRequestSuccess +import uniffi.wp_api.wpAuthenticationFromUsernameAndPassword import javax.inject.Inject import javax.inject.Named import kotlin.coroutines.CoroutineContext @@ -305,6 +309,33 @@ class PostListMainViewModel @Inject constructor( } isStarted = true + + fetchDemoUserFromRust() + } + + private fun fetchDemoUserFromRust() { + // This is an empty test site that'll be destroyed in a few days. + val siteUrl = "https://loudly-special.jurassic.ninja/" + val authentication = wpAuthenticationFromUsernameAndPassword( + username = "demo", password = "50uB 6ivM b7OC vc1K GXjh zZsI" + ) + val client = WpApiClient(siteUrl, authentication) + launch { + val demoUser = client.request { requestBuilder -> + requestBuilder.users().retrieveMeWithEditContext() + } + when (demoUser) { + is WpRequestSuccess -> { + withContext(mainDispatcher) { + _snackBarMessage.value = + SnackbarMessageHolder( + message = UiString.UiStringText("Demo user's name: ${demoUser.data.name}") + ) + } + } + else -> {} + } + } } override fun onCleared() {