Skip to content

Commit 8f98ea9

Browse files
adalpariclaude
andauthored
CMM-2297: Send support login straight to WordPress.com OAuth (#23221)
* CMM-2297: Send support login straight to WordPress.com OAuth The Jetpack support flow launched the login prologue, whose "Enter your existing site address" option uses application-password auth that does not grant the WordPress.com token support chat (Odie) needs — a dead-end. Go directly to the WP.com OAuth screen instead, matching the WordPress flow. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * CMM-2297: Return to the Support screen after WordPress.com login Use a dedicated SUPPORT login flow (WP.com OAuth, finish-back-to-caller) so that after authenticating the user lands back on the Support screen with support chat ready, instead of being dropped on the main activity. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f36006f commit 8f98ea9

4 files changed

Lines changed: 43 additions & 8 deletions

File tree

WordPress/src/main/java/org/wordpress/android/support/main/ui/SupportActivity.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.content.Intent
55
import android.os.Build
66
import android.os.Bundle
7+
import androidx.activity.result.contract.ActivityResultContracts
78
import androidx.activity.viewModels
89
import androidx.appcompat.app.AppCompatActivity
910
import androidx.compose.runtime.collectAsState
@@ -16,7 +17,6 @@ import androidx.lifecycle.repeatOnLifecycle
1617
import com.chuckerteam.chucker.api.Chucker
1718
import dagger.hilt.android.AndroidEntryPoint
1819
import kotlinx.coroutines.launch
19-
import org.wordpress.android.BuildConfig
2020
import org.wordpress.android.R
2121
import org.wordpress.android.WordPress
2222
import org.wordpress.android.analytics.AnalyticsTracker
@@ -38,6 +38,14 @@ class SupportActivity : AppCompatActivity() {
3838

3939
private lateinit var composeView: ComposeView
4040

41+
private val loginLauncher = registerForActivityResult(
42+
ActivityResultContracts.StartActivityForResult()
43+
) { result ->
44+
if (result.resultCode == RESULT_OK) {
45+
viewModel.refreshLoginState()
46+
}
47+
}
48+
4149
override fun onCreate(savedInstanceState: Bundle?) {
4250
super.onCreate(savedInstanceState)
4351
viewModel.init()
@@ -132,11 +140,12 @@ private fun getRetentionPeriodStringRes(period: NetworkRequestsRetentionPeriod):
132140
}
133141

134142
private fun navigateToLogin() {
135-
if (BuildConfig.IS_JETPACK_APP) {
136-
ActivityLauncher.showSignInForResultJetpackOnly(this)
137-
} else {
138-
ActivityLauncher.showSignInForResultWpComOnly(this)
139-
}
143+
// Support chat (Odie) requires WordPress.com authentication. Go straight to the WP.com
144+
// OAuth screen instead of the login prologue: the prologue's "Enter your existing site
145+
// address" option authenticates via application password, which does not grant the WP.com
146+
// token support needs, so it's a dead-end here. The login finishes back to this screen so
147+
// the user can carry on to support chat once authenticated. See CMM-2297.
148+
loginLauncher.launch(ActivityLauncher.createWpComSignInForSupportIntent(this))
140149
}
141150

142151
private fun navigateToHelpCenter() {

WordPress/src/main/java/org/wordpress/android/support/main/ui/SupportViewModel.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ class SupportViewModel @Inject constructor(
7373
val networkTrackingState: StateFlow<NetworkTrackingState> = _networkTrackingState.asStateFlow()
7474

7575
fun init() {
76+
refreshLoginState()
77+
initNetworkTrackingState()
78+
}
79+
80+
/**
81+
* Re-reads the account state so the screen reflects a login that happened after it was created
82+
* (e.g. the user returning from the support login flow). See CMM-2297.
83+
*/
84+
fun refreshLoginState() {
7685
val hasAccessToken = accountStore.hasAccessToken()
7786
_isLoggedIn.value = hasAccessToken
7887

@@ -86,8 +95,6 @@ class SupportViewModel @Inject constructor(
8695
_optionsVisibility.value = SupportOptionsVisibility(
8796
showUnifiedSupport = hasAccessToken && BuildConfig.IS_JETPACK_APP,
8897
)
89-
90-
initNetworkTrackingState()
9198
}
9299

93100
private fun initNetworkTrackingState() {

WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
import static org.wordpress.android.imageeditor.preview.PreviewImageFragment.ARG_EDIT_IMAGE_DATA;
156156
import static org.wordpress.android.ui.accounts.LoginFlow.PROLOGUE;
157157
import static org.wordpress.android.ui.accounts.LoginFlow.JETPACK_REST_CONNECT;
158+
import static org.wordpress.android.ui.accounts.LoginFlow.SUPPORT;
158159
import static org.wordpress.android.ui.accounts.LoginFlow.WPCOM_LOGIN;
159160
import static org.wordpress.android.push.NotificationsProcessingService.ARG_NOTIFICATION_TYPE;
160161
import static org.wordpress.android.ui.WPWebViewActivity.ENCODING_UTF8;
@@ -1500,6 +1501,17 @@ public static void showSignInForResultWpComOnly(Activity activity) {
15001501
activity.startActivityForResult(intent, RequestCodes.ADD_ACCOUNT);
15011502
}
15021503

1504+
/**
1505+
* Builds the intent for the WordPress.com login required to access support chat (Odie).
1506+
* Goes straight to WP.com OAuth and, once done, finishes back to the caller (the Support
1507+
* screen) instead of navigating to the main activity.
1508+
*/
1509+
public static Intent createWpComSignInForSupportIntent(@NonNull Context context) {
1510+
Intent intent = new Intent(context, LoginActivity.class);
1511+
SUPPORT.putInto(intent);
1512+
return intent;
1513+
}
1514+
15031515
/**
15041516
* Sign in to WordPress.com from the Jetpack REST connection flow.
15051517
* This method is specifically for the Jetpack connection process where

WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginFlow.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ enum class LoginFlow(
5656
completionBehavior = CompletionBehavior.FINISH
5757
),
5858

59+
/** WP.com login required for support chat (Odie); returns to the Support screen when done */
60+
SUPPORT(
61+
analyticsSource = "support",
62+
initialScreen = InitialScreen.WPCOM_OAUTH,
63+
completionBehavior = CompletionBehavior.FINISH
64+
),
65+
5966
/** Re-authentication after token expiry */
6067
WPCOM_REAUTHENTICATE(
6168
analyticsSource = "reauthentication",

0 commit comments

Comments
 (0)