From 2c1d3ac4b56111efd4f3893c433c3ec483fe9547 Mon Sep 17 00:00:00 2001
From: kean <grebenyuk.alexander@gmail.com>
Date: Fri, 8 Nov 2024 18:45:07 -0500
Subject: [PATCH] Remove remaining unused code

---
 .../Classes/Models/ReaderDefaultTopic.swift   |  2 --
 .../System/Root View/ReaderPresenter.swift    | 21 ++++++++++++-------
 .../ReaderPostActions/ReaderPostMenu.swift    |  8 +++----
 .../Sidebar/ReaderSidebarViewModel.swift      | 10 +++++++++
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/WordPress/Classes/Models/ReaderDefaultTopic.swift b/WordPress/Classes/Models/ReaderDefaultTopic.swift
index 7b78c177ffd6..f96d33f5128d 100644
--- a/WordPress/Classes/Models/ReaderDefaultTopic.swift
+++ b/WordPress/Classes/Models/ReaderDefaultTopic.swift
@@ -25,7 +25,5 @@ import Foundation
         case recommended = "/jpios/discover/recommended"
         case firstPosts = "/jpios/discover/first-posts"
         case latest = "/jpios/discover/latest"
-        case recent = "/jpios/recent"
-        case liked = "/jpios/liked"
     }
 }
diff --git a/WordPress/Classes/System/Root View/ReaderPresenter.swift b/WordPress/Classes/System/Root View/ReaderPresenter.swift
index 435c08650eef..e2cae6ff5413 100644
--- a/WordPress/Classes/System/Root View/ReaderPresenter.swift	
+++ b/WordPress/Classes/System/Root View/ReaderPresenter.swift	
@@ -117,15 +117,20 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
 
     private func makeViewController(for screen: ReaderStaticScreen) -> UIViewController {
         switch screen {
-        case .recent, .discover, .likes:
-            if screen == .discover {
-                return ReaderDiscoverViewController()
+        case .discover:
+            return ReaderDiscoverViewController()
+        case .recent:
+            // TODO: (tech debt) Fix an issue where this fails if opened before the menus are fetched for the first time
+            if let topic = sidebarViewModel.getRecentTopic() {
+                return ReaderStreamViewController.controllerWithTopic(topic)
+            } else {
+                return makeErrorViewController()
+            }
+        case .likes:
+            if let topic = sidebarViewModel.getLikesTopic() {
+                return ReaderStreamViewController.controllerWithTopic(topic)
             } else {
-                if let topic = screen.topicType.flatMap(sidebarViewModel.getTopic) {
-                    return ReaderStreamViewController.controllerWithTopic(topic)
-                } else {
-                    return makeErrorViewController() // This should never happen
-                }
+                return makeErrorViewController()
             }
         case .saved:
             return ReaderStreamViewController.controllerForContentType(.saved)
diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderPostMenu.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderPostMenu.swift
index c34749b1047d..1b7e5ecdabe0 100644
--- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderPostMenu.swift
+++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderPostMenu.swift
@@ -154,10 +154,10 @@ struct ReaderPostMenu {
         guard let topic else {
             return false
         }
-        return ReaderHelpers.isTopicTag(topic) ||
-            ReaderHelpers.topicIsDiscover(topic) ||
-            ReaderHelpers.topicIsFreshlyPressed(topic) ||
-            ReaderHelpers.topicIsFollowing(topic)
+        if ReaderHelpers.isTopicTag(topic) {
+            return true
+        }
+        return (topic is ReaderDefaultTopic) && !ReaderHelpers.topicIsLiked(topic)
     }
 
     // MARK: Helpers
diff --git a/WordPress/Classes/ViewRelated/Reader/Sidebar/ReaderSidebarViewModel.swift b/WordPress/Classes/ViewRelated/Reader/Sidebar/ReaderSidebarViewModel.swift
index e54ad900af32..26568ceef201 100644
--- a/WordPress/Classes/ViewRelated/Reader/Sidebar/ReaderSidebarViewModel.swift
+++ b/WordPress/Classes/ViewRelated/Reader/Sidebar/ReaderSidebarViewModel.swift
@@ -34,6 +34,16 @@ final class ReaderSidebarViewModel: ObservableObject {
         }
     }
 
+    func getRecentTopic() -> ReaderAbstractTopic? {
+        try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext)
+            .first(where: ReaderHelpers.topicIsFollowing)
+    }
+
+    func getLikesTopic() -> ReaderAbstractTopic? {
+        try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext)
+            .first(where: ReaderHelpers.topicIsLiked)
+    }
+
     func getTopic(for topicType: ReaderTopicType) -> ReaderAbstractTopic? {
         return try? ReaderAbstractTopic.lookupAllMenus(in: contextManager.mainContext).first {
             ReaderHelpers.topicType($0) == topicType