From 393c1ec990e1d5ecd0918009c84fecb281449618 Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Tue, 6 Feb 2024 17:46:30 -0300
Subject: [PATCH 1/7] Clean up some formatting/old TODO

---
 .../android/ui/reader/ReaderPostListFragment.java          | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
index 2da410a95ab6..3bf9dc3c615d 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
@@ -1724,9 +1724,6 @@ private void setEmptyTitleDescriptionAndButton(boolean requestFailed) {
         // Ensure the default image is reset for empty views before applying logic
         mActionableEmptyView.image.setImageResource(R.drawable.illustration_reader_empty);
 
-        // TODO thomashortadev
-        //  try to quickly hack some way of making the button black
-
         if (shouldShowEmptyViewForSelfHostedCta()) {
             setEmptyTitleAndDescriptionForSelfHostedCta();
             return;
@@ -1940,7 +1937,9 @@ private void showBookmarksSavedLocallyDialog(ShowBookmarkedSavedOnlyLocallyDialo
                 .setCancelable(false)
                 .create();
         mBookmarksSavedLocallyDialog.show();
-    }    /*
+    }
+
+    /*
      * called by post adapter when data has been loaded
      */
     private final ReaderInterfaces.DataLoadedListener mDataLoadedListener = new ReaderInterfaces.DataLoadedListener() {

From 5b573f64c3b7698ccd434833c64fde9253d07ba2 Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Wed, 7 Feb 2024 00:33:12 -0300
Subject: [PATCH 2/7] Fix tag list check logic to avoid saving same data to DB

IMPORTANT: this breaks ReaderPostListFragment/ViewModel fetch logic because it
was relying on this bug causing FollowedTagsChanged to be triggered in the
EventBus all the time. With this fix the Subscriptions feed is completely broken
(and the other feeds that use this Fragments are likely to be broken as well,
which are all the other except Discover).
---
 .../java/org/wordpress/android/datasets/ReaderTagTable.java | 4 ++++
 .../java/org/wordpress/android/models/ReaderTagList.java    | 2 ++
 .../ui/reader/services/update/ReaderUpdateLogic.java        | 6 ++----
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/ReaderTagTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/ReaderTagTable.java
index 977f7eaf0f2e..7c7530756b12 100644
--- a/WordPress/src/main/java/org/wordpress/android/datasets/ReaderTagTable.java
+++ b/WordPress/src/main/java/org/wordpress/android/datasets/ReaderTagTable.java
@@ -232,6 +232,10 @@ public static ReaderTagList getBookmarkTags() {
         return getTagsOfType(ReaderTagType.BOOKMARKED);
     }
 
+    public static ReaderTagList getDiscoverPostCardsTags() {
+        return getTagsOfType(ReaderTagType.DISCOVER_POST_CARDS);
+    }
+
     private static ReaderTagList getTagsOfType(ReaderTagType tagType) {
         String[] args = {Integer.toString(tagType.toInt())};
         Cursor c = ReaderDatabase.getReadableDb()
diff --git a/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java b/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
index 6a9633c44441..12da31783833 100644
--- a/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
+++ b/WordPress/src/main/java/org/wordpress/android/models/ReaderTagList.java
@@ -44,6 +44,8 @@ public boolean isSameList(ReaderTagList otherList) {
                 return false;
             } else if (!otherTag.getTagTitle().equals(this.get(i).getTagTitle())) {
                 return false;
+            } else if (!otherTag.getTagDisplayName().equals(this.get(i).getTagDisplayName())) {
+                return false;
             }
         }
 
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
index cde09194380f..1da857ba5a16 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
@@ -176,11 +176,9 @@ public void run() {
                 localTopics.addAll(ReaderTagTable.getFollowedTags());
                 localTopics.addAll(ReaderTagTable.getBookmarkTags());
                 localTopics.addAll(ReaderTagTable.getCustomListTags());
+                localTopics.addAll(ReaderTagTable.getDiscoverPostCardsTags());
 
-                if (
-                        !localTopics.isSameList(serverTopics)
-                        || displayNameUpdateWasNeeded
-                ) {
+                if (!localTopics.isSameList(serverTopics)) {
                     AppLog.d(AppLog.T.READER, "reader service > followed topics changed "
                                               + "updatedDisplayNames [" + displayNameUpdateWasNeeded + "]");
 

From f69531c98d270c322ca083aa6ce929b2cd81301b Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Wed, 7 Feb 2024 00:37:22 -0300
Subject: [PATCH 3/7] Fix empty view being hidden when coming back to
 Subscriptions

The empty view is being reused for showing several messages, including the fetch
message. Because of that, that are pieces of code that rely on previous code
showing the "empty view" and just alter its content, without calling "show"
again. If we hide the empty view when the list is actually empty, we get to
a scenario of a blank screen when coming back to this feed from some other
screens. Example: with 0 blog subscriptions, in the Subscriptions feed, going to
the tag suggestions and back cause the Subscriptions feed to be blank.
---
 .../org/wordpress/android/ui/reader/ReaderPostListFragment.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
index 3bf9dc3c615d..fdee851a6f05 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
@@ -2332,7 +2332,7 @@ public void run() {
                             mActionableEmptyView.button.setVisibility(View.GONE);
                             mActionableEmptyView.subtitle.setVisibility(View.GONE);
                             showEmptyView();
-                        } else {
+                        } else if (!isPostAdapterEmpty()) {
                             hideEmptyView();
                         }
                     });

From 4a8ba198caeda3974ce0db642b0e91c16455031b Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Fri, 9 Feb 2024 19:05:46 -0300
Subject: [PATCH 4/7] WIP trying again to fix initial fetching...

Tag Interests has an infinite loading because a use case expects the event that
is not triggered anymore (I think).
---
 .../ui/reader/ReaderPostListFragment.java     | 21 ++++++++++++++++++-
 .../services/update/ReaderUpdateLogic.java    |  1 +
 .../ui/reader/viewmodels/ReaderViewModel.kt   |  3 ++-
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
index fdee851a6f05..69116fd5f7b3 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
@@ -1945,9 +1945,13 @@ private void showBookmarksSavedLocallyDialog(ShowBookmarkedSavedOnlyLocallyDialo
     private final ReaderInterfaces.DataLoadedListener mDataLoadedListener = new ReaderInterfaces.DataLoadedListener() {
         @Override
         public void onDataLoaded(boolean isEmpty) {
-            if (!isAdded() || !mHasUpdatedPosts) {
+            if (!isAdded()) return;
+
+            if (!mHasUpdatedPosts) {
+                fetchInitialData();
                 return;
             }
+
             if (isEmpty) {
                 if (getPostListType() != ReaderPostListType.SEARCH_RESULTS
                     || getSearchTabsPosition() == TAB_SITES && getSiteSearchAdapter().isEmpty()
@@ -1972,6 +1976,21 @@ public void onDataLoaded(boolean isEmpty) {
         }
     };
 
+    private void fetchInitialData() {
+        if (getPostListType() == ReaderPostListType.TAG_FOLLOWED) {
+            reloadTags();
+
+            // update the current tag if the list fragment is empty - this will happen if
+            // the tag table was previously empty (ie: first run)
+            if (isPostAdapterEmpty()) {
+                updateCurrentTag();
+            }
+        }
+
+        if (mReaderViewModel != null) mReaderViewModel.loadTabs();
+        if (mSubFilterViewModel != null) mSubFilterViewModel.loadSubFilters();
+    }
+
     private boolean isBookmarksList() {
         return getPostListType() == ReaderPostListType.TAG_FOLLOWED
                && (mCurrentTag != null && mCurrentTag.isBookmarked());
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
index 1da857ba5a16..b935807df17f 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
@@ -193,6 +193,7 @@ public void run() {
                         ReaderTagTable.replaceTags(serverTopics);
                     }
                     // broadcast the fact that there are changes
+                    // TODO thomashortadev this was being sent EVERY time
                     EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
                 }
                 AppPrefs.setReaderTagsUpdatedTimestamp(new Date().getTime());
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
index a6e26e3f648a..c745626738a2 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
@@ -135,7 +135,8 @@ class ReaderViewModel @Inject constructor(
 //        _showJetpackPoweredBottomSheet.value = Event(true)
     }
 
-    private fun loadTabs(savedInstanceState: Bundle? = null) {
+    @JvmOverloads
+    fun loadTabs(savedInstanceState: Bundle? = null) {
         launch {
             val tagList = loadReaderTabsUseCase.loadTabs()
             if (tagList.isNotEmpty() && readerTagsList != tagList) {

From 7f069f6082c0a1eadeebc4627d0213a3e8643efd Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Mon, 19 Feb 2024 19:30:01 -0300
Subject: [PATCH 5/7] Rename FollowedTagsChanged to FollowedTagsFetched

Upon investigation I realized that most places using this event were actually
using it as a callback for the end of the fetch task rather than something that
is ONLY emitted when the tags CHANGE, which was what the name implied.

That only worked because of the bug mentioned in commit 3017bab that did not
properly compare the local and server tags and considered all fetches as
requiring a local database write, which in turn triggered the event.

The constant triggering of that FollowedTagsChanged event was also the cause of
bugs #20009 and #20010 since part of the code that runs there was actually only
supposed to run some times.

To fix that I renamed it to FollowedTagsFetched to better represent what it does
and figured out which parts of the code inside `ReaderPostListFragment` event
listener were supposed to run and in which scenario. I also added a `didChange`
field in the `FollowedTagsFetched` event for completeness but that part might
not be needed in the future, since the only code using that is legacy code
related to the old subfilter which should be removed in the future.
---
 .../android/ui/reader/ReaderEvents.java       | 15 +++++-
 .../ui/reader/ReaderPostListFragment.java     | 46 +++++++++----------
 .../android/ui/reader/ReaderSubsActivity.java |  3 +-
 .../ui/reader/actions/ReaderTagActions.java   | 12 ++---
 .../repository/ReaderDiscoverDataProvider.kt  |  4 +-
 .../usecases/tags/FetchFollowedTagsUseCase.kt |  4 +-
 .../tags/FollowInterestTagsUseCase.kt         |  4 +-
 .../services/update/ReaderUpdateLogic.java    |  6 ++-
 .../ui/reader/subfilter/SubFilterViewModel.kt |  2 +-
 .../ui/reader/viewmodels/ReaderViewModel.kt   |  2 +-
 .../FetchFollowedTagsUseCaseTest.kt           | 14 +++---
 .../ReaderDiscoverDataProviderTest.kt         |  8 +++-
 .../reader/viewmodels/ReaderViewModelTest.kt  |  2 +-
 13 files changed, 69 insertions(+), 53 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java
index e107db26f932..de72a22e2b40 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderEvents.java
@@ -26,16 +26,27 @@ private ReaderEvents() {
         throw new AssertionError();
     }
 
-    public static class FollowedTagsChanged {
+    public static class FollowedTagsFetched {
         private final boolean mDidSucceed;
+        private final boolean mDidChange;
 
-        public FollowedTagsChanged(boolean didSucceed) {
+        public FollowedTagsFetched(boolean didSucceed) {
             mDidSucceed = didSucceed;
+            mDidChange = true;
+        }
+
+        public FollowedTagsFetched(boolean didSucceed, boolean didChange) {
+            mDidSucceed = didSucceed;
+            mDidChange = didChange;
         }
 
         public boolean didSucceed() {
             return mDidSucceed;
         }
+
+        public boolean didChange() {
+            return mDidChange;
+        }
     }
 
     public static class TagAdded {
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
index 69116fd5f7b3..a721385892dc 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
@@ -84,6 +84,7 @@
 import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment;
 import org.wordpress.android.ui.pages.SnackbarMessageHolder;
 import org.wordpress.android.ui.prefs.AppPrefs;
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched;
 import org.wordpress.android.ui.reader.ReaderEvents.TagAdded;
 import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType;
 import org.wordpress.android.ui.reader.actions.ReaderActions;
@@ -934,14 +935,16 @@ private void resetPostAdapter(ReaderPostListType postListType) {
 
     @SuppressWarnings("unused")
     @Subscribe(threadMode = ThreadMode.MAIN)
-    public void onEventMainThread(ReaderEvents.FollowedTagsChanged event) {
+    public void onEventMainThread(FollowedTagsFetched event) {
         if (getPostListType() == ReaderPostListType.TAG_FOLLOWED) {
-            // reload the tag filter since tags have changed
-            reloadTags();
+            if (event.didChange()) {
+                // reload the tag filter since tags have changed or we just opened the fragment
+                reloadTags();
+            }
 
             // update the current tag if the list fragment is empty - this will happen if
             // the tag table was previously empty (ie: first run)
-            if (isPostAdapterEmpty()) {
+            if (isPostAdapterEmpty() && (ReaderBlogTable.hasFollowedBlogs() || !mHasUpdatedPosts)) {
                 updateCurrentTag();
             }
         }
@@ -1945,12 +1948,7 @@ private void showBookmarksSavedLocallyDialog(ShowBookmarkedSavedOnlyLocallyDialo
     private final ReaderInterfaces.DataLoadedListener mDataLoadedListener = new ReaderInterfaces.DataLoadedListener() {
         @Override
         public void onDataLoaded(boolean isEmpty) {
-            if (!isAdded()) return;
-
-            if (!mHasUpdatedPosts) {
-                fetchInitialData();
-                return;
-            }
+            if (!isAdded() || !mHasUpdatedPosts) return;
 
             if (isEmpty) {
                 if (getPostListType() != ReaderPostListType.SEARCH_RESULTS
@@ -1976,20 +1974,20 @@ public void onDataLoaded(boolean isEmpty) {
         }
     };
 
-    private void fetchInitialData() {
-        if (getPostListType() == ReaderPostListType.TAG_FOLLOWED) {
-            reloadTags();
-
-            // update the current tag if the list fragment is empty - this will happen if
-            // the tag table was previously empty (ie: first run)
-            if (isPostAdapterEmpty()) {
-                updateCurrentTag();
-            }
-        }
-
-        if (mReaderViewModel != null) mReaderViewModel.loadTabs();
-        if (mSubFilterViewModel != null) mSubFilterViewModel.loadSubFilters();
-    }
+//    private void fetchInitialData() {
+//        if (getPostListType() == ReaderPostListType.TAG_FOLLOWED) {
+//            reloadTags();
+//
+//            // update the current tag if the list fragment is empty - this will happen if
+//            // the tag table was previously empty (ie: first run)
+//            if (isPostAdapterEmpty()) {
+//                updateCurrentTag();
+//            }
+//        }
+//
+//        if (mReaderViewModel != null) mReaderViewModel.loadTabs();
+//        if (mSubFilterViewModel != null) mSubFilterViewModel.loadSubFilters();
+//    }
 
     private boolean isBookmarksList() {
         return getPostListType() == ReaderPostListType.TAG_FOLLOWED
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java
index 955a08936ce5..3e8914829792 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java
@@ -41,6 +41,7 @@
 import org.wordpress.android.ui.LocaleAwareActivity;
 import org.wordpress.android.ui.RequestCodes;
 import org.wordpress.android.ui.prefs.AppPrefs;
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched;
 import org.wordpress.android.ui.reader.actions.ReaderActions;
 import org.wordpress.android.ui.reader.actions.ReaderBlogActions;
 import org.wordpress.android.ui.reader.actions.ReaderTagActions;
@@ -203,7 +204,7 @@ protected void onResume() {
 
     @SuppressWarnings("unused")
     @Subscribe(threadMode = ThreadMode.MAIN)
-    public void onEventMainThread(ReaderEvents.FollowedTagsChanged event) {
+    public void onEventMainThread(FollowedTagsFetched event) {
         AppLog.d(AppLog.T.READER, "reader subs > followed tags changed");
         getPageAdapter().refreshFollowedTagFragment();
     }
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java
index 9577553148fa..8e9ec0895f73 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java
@@ -13,7 +13,7 @@
 import org.wordpress.android.models.ReaderTagList;
 import org.wordpress.android.models.ReaderTagType;
 import org.wordpress.android.ui.reader.ReaderConstants;
-import org.wordpress.android.ui.reader.ReaderEvents;
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched;
 import org.wordpress.android.ui.reader.actions.ReaderActions.ActionListener;
 import org.wordpress.android.ui.reader.utils.ReaderUtils;
 import org.wordpress.android.util.AppLog;
@@ -51,7 +51,7 @@ public static boolean deleteTag(final ReaderTag tag,
     private static boolean deleteTagsLocallyOnly(ActionListener actionListener, ReaderTag tag) {
         ReaderTagTable.deleteTag(tag);
         ReaderActions.callActionListener(actionListener, true);
-        EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
+        EventBus.getDefault().post(new FollowedTagsFetched(true));
 
         return true;
     }
@@ -130,7 +130,7 @@ public static boolean addTags(@NonNull final List<ReaderTag> tags,
     private static boolean saveTagsLocallyOnly(ActionListener actionListener, ReaderTagList newTags) {
         ReaderTagTable.addOrUpdateTags(newTags);
         ReaderActions.callActionListener(actionListener, true);
-        EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
+        EventBus.getDefault().post(new FollowedTagsFetched(true));
 
         return true;
     }
@@ -147,7 +147,7 @@ private static boolean saveTagsLocallyAndRemotely(ActionListener actionListener,
             if (actionListener != null) {
                 ReaderActions.callActionListener(actionListener, true);
             }
-            EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
+            EventBus.getDefault().post(new FollowedTagsFetched(true));
         };
 
         RestRequest.ErrorListener errorListener = volleyError -> {
@@ -159,7 +159,7 @@ private static boolean saveTagsLocallyAndRemotely(ActionListener actionListener,
                 if (actionListener != null) {
                     ReaderActions.callActionListener(actionListener, true);
                 }
-                EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
+                EventBus.getDefault().post(new FollowedTagsFetched(true));
                 return;
             }
 
@@ -171,7 +171,7 @@ private static boolean saveTagsLocallyAndRemotely(ActionListener actionListener,
             if (actionListener != null) {
                 ReaderActions.callActionListener(actionListener, false);
             }
-            EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(false));
+            EventBus.getDefault().post(new FollowedTagsFetched(false));
         };
 
         ReaderTagTable.addOrUpdateTags(newTags);
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProvider.kt
index a1a20185e26d..27b8cb35b031 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProvider.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProvider.kt
@@ -14,7 +14,7 @@ import org.wordpress.android.models.discover.ReaderDiscoverCards
 import org.wordpress.android.modules.IO_THREAD
 import org.wordpress.android.modules.UI_THREAD
 import org.wordpress.android.ui.reader.ReaderEvents.FetchDiscoverCardsEnded
-import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsChanged
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.CHANGED
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.FAILED
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.HAS_NEW
@@ -211,7 +211,7 @@ class ReaderDiscoverDataProvider @Inject constructor(
 
     @Suppress("unused", "UNUSED_PARAMETER")
     @Subscribe(threadMode = BACKGROUND)
-    fun onFollowedTagsChanged(event: FollowedTagsChanged) {
+    fun onFollowedTagsFetched(event: FollowedTagsFetched) {
         launch {
             refreshCards()
         }
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FetchFollowedTagsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FetchFollowedTagsUseCase.kt
index 3afd6a0d2cf2..1d109666337d 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FetchFollowedTagsUseCase.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FetchFollowedTagsUseCase.kt
@@ -2,7 +2,7 @@ package org.wordpress.android.ui.reader.repository.usecases.tags
 
 import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
-import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsChanged
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Error.NetworkUnavailable
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Error.RemoteRequestFailure
@@ -48,7 +48,7 @@ class FetchFollowedTagsUseCase @Inject constructor(
 
     @Suppress("unused")
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
-    fun onFollowedTagsChanged(event: FollowedTagsChanged) {
+    fun onFollowedTagsFetched(event: FollowedTagsFetched) {
         val result = if (event.didSucceed()) {
             Success
         } else {
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FollowInterestTagsUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FollowInterestTagsUseCase.kt
index 3002e258d450..8e171e262261 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FollowInterestTagsUseCase.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/repository/usecases/tags/FollowInterestTagsUseCase.kt
@@ -4,7 +4,7 @@ import org.greenrobot.eventbus.Subscribe
 import org.greenrobot.eventbus.ThreadMode
 import org.wordpress.android.fluxc.store.AccountStore
 import org.wordpress.android.models.ReaderTag
-import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsChanged
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched
 import org.wordpress.android.ui.reader.actions.ReaderTagActions
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Error.NetworkUnavailable
@@ -43,7 +43,7 @@ class FollowInterestTagsUseCase @Inject constructor(
 
     @Suppress("unused")
     @Subscribe(threadMode = ThreadMode.BACKGROUND)
-    fun onFollowedTagsChanged(event: FollowedTagsChanged) {
+    fun onFollowedTagsFetched(event: FollowedTagsFetched) {
         val result = if (event.didSucceed()) {
             Success
         } else {
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
index b935807df17f..bafd6275709e 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
@@ -24,6 +24,7 @@
 import org.wordpress.android.ui.prefs.AppPrefs;
 import org.wordpress.android.ui.reader.ReaderConstants;
 import org.wordpress.android.ui.reader.ReaderEvents;
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched;
 import org.wordpress.android.ui.reader.ReaderEvents.InterestTagsFetchEnded;
 import org.wordpress.android.ui.reader.services.ServiceCompletionListener;
 import org.wordpress.android.util.AppLog;
@@ -178,6 +179,7 @@ public void run() {
                 localTopics.addAll(ReaderTagTable.getCustomListTags());
                 localTopics.addAll(ReaderTagTable.getDiscoverPostCardsTags());
 
+                boolean didChangeFollowedTags = false;
                 if (!localTopics.isSameList(serverTopics)) {
                     AppLog.d(AppLog.T.READER, "reader service > followed topics changed "
                                               + "updatedDisplayNames [" + displayNameUpdateWasNeeded + "]");
@@ -193,9 +195,9 @@ public void run() {
                         ReaderTagTable.replaceTags(serverTopics);
                     }
                     // broadcast the fact that there are changes
-                    // TODO thomashortadev this was being sent EVERY time
-                    EventBus.getDefault().post(new ReaderEvents.FollowedTagsChanged(true));
+                    didChangeFollowedTags = true;
                 }
+                EventBus.getDefault().post(new FollowedTagsFetched(true, didChangeFollowedTags));
                 AppPrefs.setReaderTagsUpdatedTimestamp(new Date().getTime());
 
                 taskCompleted(UpdateTask.TAGS);
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt
index e331ecaeb231..a9dd37639a36 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt
@@ -393,7 +393,7 @@ class SubFilterViewModel @Inject constructor(
 
     @Suppress("unused", "UNUSED_PARAMETER")
     @Subscribe(threadMode = ThreadMode.MAIN)
-    fun onEventMainThread(event: ReaderEvents.FollowedTagsChanged) {
+    fun onEventMainThread(event: ReaderEvents.FollowedTagsFetched) {
         AppLog.d(T.READER, "Subfilter bottom sheet > followed tags changed")
         loadSubFilters()
     }
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
index c745626738a2..0e13b2f17e0b 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt
@@ -216,7 +216,7 @@ class ReaderViewModel @Inject constructor(
 
     @Suppress("unused", "UNUSED_PARAMETER")
     @Subscribe(threadMode = MAIN)
-    fun onTagsUpdated(event: ReaderEvents.FollowedTagsChanged) {
+    fun onTagsUpdated(event: ReaderEvents.FollowedTagsFetched) {
         loadTabs()
     }
 
diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/FetchFollowedTagsUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/FetchFollowedTagsUseCaseTest.kt
index a581bc43584f..5c0c086000e0 100644
--- a/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/FetchFollowedTagsUseCaseTest.kt
+++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/FetchFollowedTagsUseCaseTest.kt
@@ -9,7 +9,7 @@ import org.mockito.Mock
 import org.mockito.junit.MockitoJUnitRunner
 import org.mockito.kotlin.whenever
 import org.wordpress.android.BaseUnitTest
-import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsChanged
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Error.NetworkUnavailable
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Error.RemoteRequestFailure
 import org.wordpress.android.ui.reader.repository.ReaderRepositoryCommunication.Success
@@ -61,12 +61,12 @@ class FetchFollowedTagsUseCaseTest : BaseUnitTest() {
     }
 
     @Test
-    fun `Success returned when FollowedTagsChanged event is posted with true`() = test {
+    fun `Success returned when FollowedTagsFetched event is posted with success`() = test {
         // Given
         whenever(networkUtilsWrapper.isNetworkAvailable()).thenReturn(true)
-        val event = FollowedTagsChanged(true)
+        val event = FollowedTagsFetched(true)
         whenever(readerUpdateServiceStarterWrapper.startService(contextProvider.getContext(), EnumSet.of(TAGS)))
-            .then { useCase.onFollowedTagsChanged(event) }
+            .then { useCase.onFollowedTagsFetched(event) }
 
         // When
         val result = useCase.fetch()
@@ -76,12 +76,12 @@ class FetchFollowedTagsUseCaseTest : BaseUnitTest() {
     }
 
     @Test
-    fun `RemoteRequestFailure returned when FollowedTagsChanged event is posted with false`() = test {
+    fun `RemoteRequestFailure returned when FollowedTagsFetched event is posted with failure`() = test {
         // Given
         whenever(networkUtilsWrapper.isNetworkAvailable()).thenReturn(true)
-        val event = FollowedTagsChanged(false)
+        val event = FollowedTagsFetched(false)
         whenever(readerUpdateServiceStarterWrapper.startService(contextProvider.getContext(), EnumSet.of(TAGS)))
-            .then { useCase.onFollowedTagsChanged(event) }
+            .then { useCase.onFollowedTagsFetched(event) }
 
         // When
         val result = useCase.fetch()
diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProviderTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProviderTest.kt
index 18f0d5704887..3a87558edee4 100644
--- a/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProviderTest.kt
+++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/repository/ReaderDiscoverDataProviderTest.kt
@@ -16,7 +16,7 @@ import org.wordpress.android.models.ReaderPost
 import org.wordpress.android.models.discover.ReaderDiscoverCard.ReaderPostCard
 import org.wordpress.android.models.discover.ReaderDiscoverCards
 import org.wordpress.android.ui.reader.ReaderEvents.FetchDiscoverCardsEnded
-import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsChanged
+import org.wordpress.android.ui.reader.ReaderEvents.FollowedTagsFetched
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.FAILED
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.HAS_NEW
 import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResult.UNCHANGED
@@ -249,7 +249,11 @@ class ReaderDiscoverDataProviderTest : BaseUnitTest() {
     @Test
     fun `when followed tags change the discover feed gets refreshed`() = test {
         // Act
-        dataProvider.onFollowedTagsChanged(FollowedTagsChanged(true))
+        dataProvider.onFollowedTagsFetched(
+            FollowedTagsFetched(
+                true
+            )
+        )
         // Assert
         verify(fetchDiscoverCardsUseCase).fetch(REQUEST_FIRST_PAGE)
     }
diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt
index 29780c984015..2f437f24465c 100644
--- a/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt
+++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt
@@ -177,7 +177,7 @@ class ReaderViewModelTest : BaseUnitTest() {
     }
 
     @Test
-    fun `Tags are reloaded when FollowedTagsChanged event is received`() = testWithNonEmptyTags {
+    fun `Tags are reloaded when FollowedTagsFetched event is received`() = testWithNonEmptyTags {
         // Arrange
         var state: ReaderUiState? = null
         viewModel.uiState.observeForever {

From cfd0d99f90d0a80e6a552525855364b5d1d6229b Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Tue, 20 Feb 2024 14:47:41 -0300
Subject: [PATCH 6/7] Remove unused code

---
 .../ui/reader/ReaderPostListFragment.java     | 20 +++----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
index a721385892dc..287204bb16d1 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java
@@ -1948,8 +1948,9 @@ private void showBookmarksSavedLocallyDialog(ShowBookmarkedSavedOnlyLocallyDialo
     private final ReaderInterfaces.DataLoadedListener mDataLoadedListener = new ReaderInterfaces.DataLoadedListener() {
         @Override
         public void onDataLoaded(boolean isEmpty) {
-            if (!isAdded() || !mHasUpdatedPosts) return;
-
+            if (!isAdded() || !mHasUpdatedPosts) {
+                return;
+            }
             if (isEmpty) {
                 if (getPostListType() != ReaderPostListType.SEARCH_RESULTS
                     || getSearchTabsPosition() == TAB_SITES && getSiteSearchAdapter().isEmpty()
@@ -1974,21 +1975,6 @@ public void onDataLoaded(boolean isEmpty) {
         }
     };
 
-//    private void fetchInitialData() {
-//        if (getPostListType() == ReaderPostListType.TAG_FOLLOWED) {
-//            reloadTags();
-//
-//            // update the current tag if the list fragment is empty - this will happen if
-//            // the tag table was previously empty (ie: first run)
-//            if (isPostAdapterEmpty()) {
-//                updateCurrentTag();
-//            }
-//        }
-//
-//        if (mReaderViewModel != null) mReaderViewModel.loadTabs();
-//        if (mSubFilterViewModel != null) mSubFilterViewModel.loadSubFilters();
-//    }
-
     private boolean isBookmarksList() {
         return getPostListType() == ReaderPostListType.TAG_FOLLOWED
                && (mCurrentTag != null && mCurrentTag.isBookmarked());

From c702921923985833cb695944e014795b4357a7d6 Mon Sep 17 00:00:00 2001
From: Thomas Horta <thomas.horta@automattic.com>
Date: Wed, 21 Feb 2024 15:39:06 -0300
Subject: [PATCH 7/7] Remove displayNameUpdatedWasNeeded variable (PR comments)

---
 .../services/update/ReaderUpdateLogic.java    | 20 ++++++++-----------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
index bafd6275709e..e743d7f52bfa 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/update/ReaderUpdateLogic.java
@@ -123,24 +123,21 @@ public void onErrorResponse(VolleyError volleyError) {
                             .get("read/menu", params, null, listener, errorListener);
     }
 
-    private boolean displayNameUpdateWasNeeded(ReaderTagList serverTopics) {
-        boolean updateDone = false;
-
+    /**
+     * Update the display names of the default tags (such as Subscribed and Discover) in the serverTopics list.
+     *
+     * @param serverTopics The list of default tags.
+     */
+    private void updateDisplayNamesIfNeeded(@NonNull ReaderTagList serverTopics) {
         for (ReaderTag tag : serverTopics) {
-            String tagNameBefore = tag.getTagDisplayName();
             if (tag.isFollowedSites()) {
                 tag.setTagDisplayName(mContext.getString(R.string.reader_subscribed_display_name));
-                if (!tagNameBefore.equals(tag.getTagDisplayName())) updateDone = true;
             } else if (tag.isDiscover()) {
                 tag.setTagDisplayName(mContext.getString(R.string.reader_discover_display_name));
-                if (!tagNameBefore.equals(tag.getTagDisplayName())) updateDone = true;
             } else if (tag.isPostsILike()) {
                 tag.setTagDisplayName(mContext.getString(R.string.reader_my_likes_display_name));
-                if (!tagNameBefore.equals(tag.getTagDisplayName())) updateDone = true;
             }
         }
-
-        return updateDone;
     }
 
     private void handleUpdateTagsResponse(final JSONObject jsonObject) {
@@ -152,7 +149,7 @@ public void run() {
                 ReaderTagList serverTopics = new ReaderTagList();
                 serverTopics.addAll(parseTags(jsonObject, "default", ReaderTagType.DEFAULT));
 
-                boolean displayNameUpdateWasNeeded = displayNameUpdateWasNeeded(serverTopics);
+                updateDisplayNamesIfNeeded(serverTopics);
 
                 serverTopics.addAll(parseTags(jsonObject, "subscribed", ReaderTagType.FOLLOWED));
 
@@ -181,8 +178,7 @@ public void run() {
 
                 boolean didChangeFollowedTags = false;
                 if (!localTopics.isSameList(serverTopics)) {
-                    AppLog.d(AppLog.T.READER, "reader service > followed topics changed "
-                                              + "updatedDisplayNames [" + displayNameUpdateWasNeeded + "]");
+                    AppLog.d(AppLog.T.READER, "reader service > followed topics changed");
 
                     if (!mAccountStore.hasAccessToken()) {
                         // Do not delete locally saved tags for logged out user