From 3d8eedb5a76f297905639926b5e4c7e8215b0747 Mon Sep 17 00:00:00 2001 From: jhnstn Date: Mon, 8 Jan 2024 17:18:36 -0500 Subject: [PATCH 1/5] Add site info to editor failed upload events --- .../wordpress/android/ui/posts/editor/media/EditorMedia.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt index 4332f516783a..9abf63880289 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/EditorMedia.kt @@ -38,6 +38,7 @@ import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.StringUtils import org.wordpress.android.util.ToastUtils.Duration import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.analytics.AnalyticsUtils import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.SingleLiveEvent @@ -294,7 +295,11 @@ class EditorMedia @Inject constructor( it["error_type"] = error.type.name } } - analyticsTrackerWrapper.track(EDITOR_UPLOAD_MEDIA_FAILED, properties) + AnalyticsUtils.trackWithSiteDetails( + analyticsTrackerWrapper, + EDITOR_UPLOAD_MEDIA_FAILED, + site, + properties) listener.onMediaUploadFailed(media.id.toString()) } From a93fa5a473d366b8d51663c978fef989730d6b39 Mon Sep 17 00:00:00 2001 From: jhnstn Date: Mon, 8 Jan 2024 18:06:35 -0500 Subject: [PATCH 2/5] Add site info to editor upload retry event --- .../org/wordpress/android/ui/posts/EditPostActivity.java | 2 +- .../posts/editor/media/RetryFailedMediaUploadUseCase.kt | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 8eb3b555a0c8..79a85b302106 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -3347,7 +3347,7 @@ public boolean onMediaRetryClicked(final String mediaId) { mEditorMedia.retryFailedMediaAsync(Collections.singletonList(media.getId())); } - AnalyticsTracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED); + AnalyticsUtils.trackWithSiteDetails(Stat.EDITOR_UPLOAD_MEDIA_RETRIED, mSite); return true; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt index 1a00989a78ce..7343f3ac4411 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt @@ -3,7 +3,11 @@ package org.wordpress.android.ui.posts.editor.media import dagger.Reusable import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.ui.CommentFullScreenDialogFragment import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.analytics.AnalyticsUtils import javax.inject.Inject @Reusable @@ -13,6 +17,8 @@ class RetryFailedMediaUploadUseCase @Inject constructor( private val uploadMediaUseCase: UploadMediaUseCase, private val tracker: AnalyticsTrackerWrapper ) { + @Inject + lateinit var siteStore: SiteStore suspend fun retryFailedMediaAsync( editorMediaListener: EditorMediaListener, failedMediaLocalIds: List @@ -33,7 +39,8 @@ class RetryFailedMediaUploadUseCase @Inject constructor( editorMediaListener, mediaModels ) - tracker.track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED) + val site: SiteModel? = siteStore.getSiteByLocalId(editorMediaListener.getImmutablePost().localSiteId) + AnalyticsUtils.trackWithSiteDetails(tracker, Stat.EDITOR_UPLOAD_MEDIA_RETRIED, site, null); } } } From 07981f2eded3f3125153028bc3613a1baa4eec3a Mon Sep 17 00:00:00 2001 From: Jason Johnston Date: Mon, 15 Jan 2024 13:05:57 -0500 Subject: [PATCH 3/5] Update WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt Co-authored-by: Siobhan Bamber --- .../ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt index 7343f3ac4411..69373ee95e8d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt @@ -5,7 +5,6 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.SiteStore -import org.wordpress.android.ui.CommentFullScreenDialogFragment import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.analytics.AnalyticsUtils import javax.inject.Inject From 28a517eb6dbaf7513c33232a5dec671eda308bd5 Mon Sep 17 00:00:00 2001 From: jhnstn Date: Mon, 15 Jan 2024 13:08:03 -0500 Subject: [PATCH 4/5] linting: line length --- .../ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt index 69373ee95e8d..d3edb6ff9269 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt @@ -38,7 +38,8 @@ class RetryFailedMediaUploadUseCase @Inject constructor( editorMediaListener, mediaModels ) - val site: SiteModel? = siteStore.getSiteByLocalId(editorMediaListener.getImmutablePost().localSiteId) + val siteId = editorMediaListener.getImmutablePost().localSiteId + val site: SiteModel? = siteStore.getSiteByLocalId(siteId) AnalyticsUtils.trackWithSiteDetails(tracker, Stat.EDITOR_UPLOAD_MEDIA_RETRIED, site, null); } } From 825e67e4e2053d7ea03f28e4f086e0676bea7fbb Mon Sep 17 00:00:00 2001 From: jhnstn Date: Tue, 16 Jan 2024 11:04:39 -0500 Subject: [PATCH 5/5] Inject siteStore in constructor Also fix tests --- .../media/RetryFailedMediaUploadUseCase.kt | 5 ++-- .../RetryFailedMediaUploadUseCaseTest.kt | 25 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt index d3edb6ff9269..8ae1a20c0480 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCase.kt @@ -14,10 +14,9 @@ class RetryFailedMediaUploadUseCase @Inject constructor( private val getMediaModelUseCase: GetMediaModelUseCase, private val updateMediaModelUseCase: UpdateMediaModelUseCase, private val uploadMediaUseCase: UploadMediaUseCase, - private val tracker: AnalyticsTrackerWrapper + private val tracker: AnalyticsTrackerWrapper, + private val siteStore: SiteStore ) { - @Inject - lateinit var siteStore: SiteStore suspend fun retryFailedMediaAsync( editorMediaListener: EditorMediaListener, failedMediaLocalIds: List diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt index 366303e9fe00..c51bbaa40fbb 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/media/RetryFailedMediaUploadUseCaseTest.kt @@ -18,6 +18,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.MediaModel import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED +import org.wordpress.android.fluxc.model.PostImmutableModel +import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @ExperimentalCoroutinesApi @@ -29,8 +31,9 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { val getMediaModelUseCase = createGetMediaModelUseCase() val useCase = createUseCase(getMediaModelUseCase = getMediaModelUseCase) + // Act - useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS) + useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS) // Assert verify(getMediaModelUseCase).loadMediaByLocalId(FAILED_MEDIA_IDS) } @@ -42,7 +45,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { val useCase = createUseCase(updateMediaModelUseCase = updateMediaModelUseCase) // Act - useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS) + useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS) // Assert verify(updateMediaModelUseCase, times(FAILED_MEDIA_IDS.size)).updateMediaModel( @@ -59,7 +62,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { val useCase = createUseCase(uploadMediaUseCase = uploadMediaUseCase) // Act - useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS) + useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS) // Assert verify(uploadMediaUseCase).saveQueuedPostAndStartUpload( @@ -74,7 +77,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { val trackerWrapper: AnalyticsTrackerWrapper = mock() val useCase = createUseCase(tracker = trackerWrapper) // Act - useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS) + useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS) // Assert verify(trackerWrapper).track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED) } @@ -112,13 +115,15 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { getMediaModelUseCase: GetMediaModelUseCase = createGetMediaModelUseCase(), updateMediaModelUseCase: UpdateMediaModelUseCase = mock(), uploadMediaUseCase: UploadMediaUseCase = mock(), - tracker: AnalyticsTrackerWrapper = mock() + tracker: AnalyticsTrackerWrapper = mock(), + siteStore: SiteStore = mock() ): RetryFailedMediaUploadUseCase { return RetryFailedMediaUploadUseCase( getMediaModelUseCase, updateMediaModelUseCase, uploadMediaUseCase, - tracker + tracker, + siteStore ) } @@ -136,5 +141,13 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() { this.id = mediaModelId this.uploadState = MediaUploadState.FAILED.name } + + fun createEditorMediaListener() = mock { + on { getImmutablePost() } doAnswer { + mock { + on { localSiteId } doAnswer { 0 } + } + } + } } }