Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: Local Default Topics #23788

Draft
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Draft

Reader: Local Default Topics #23788

wants to merge 8 commits into from

Conversation

kean
Copy link
Contributor

@kean kean commented Nov 8, 2024

Background

When you open the Reader, it fetches /read/menu that contains the following fields:

  "default": {
    "discover": {
      "URL": "https://public-api.wordpress.com/rest/v1.2/read/sites/53424024/posts",
      "title": "Discover"
    },
    "following": {
      "URL": "https://public-api.wordpress.com/rest/v1.2/read/following",
      "title": "Followed Sites"
    },
    "liked": {
      "URL": "https://public-api.wordpress.com/rest/v1.2/read/liked",
      "title": "My Likes"
    },
  },

For each of these menu items, the app creates a ReaderDefaultTopic instance of Core Data. The main role of these topics is to be used in predicates for caching posts: NSPredicate(format: "topic = %@).

There are two main issue with this approach:

  • The app can't open any of these menus until it successfully fetches /read/menu
  • The app hardcodes this path (read/sites/53424024/posts) for Discover. If the path ever changes on the backend, Discover will completely stop working in the app.

With Discover, the app uses neither the URL nor the title field from the response, so it's a pretty easy update to no longer rely on this value. This is not the case for "Followed Sites" and "My Likes" where the app actually uses the path in multiple ways, including for fetching the respective feeds.

Changes

  • Create ReaderDefaultTopic for "Discover" locally
  • Remove currentTopic (no longer used)
  • Remove ReaderTopicType (not needed anymore)

To test:

  • Set a network breakpoint on /read/menu
  • Open the app for the first time
  • Open Reader
  • Tap Discover
  • Verify that the screen opens and loads the channels ("Recommended", "Latest", etc)

Future Changes

  • Update "Recent" and "Likes" to also stop relying on the /read/menu. This is a larger change and I decided not to make it in the scope of this PR.

Regression Notes

  1. Potential unintended areas of impact

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

  3. What automated tests I added (or what prevented me from doing so)

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@dangermattic
Copy link
Collaborator

dangermattic commented Nov 8, 2024

1 Warning
⚠️ This PR is assigned to the milestone 25.5. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 8, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr23788-6f712d3
Version25.4.2
Bundle IDorg.wordpress.alpha
Commit6f712d3
App Center BuildWPiOS - One-Offs #11059
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Nov 8, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr23788-6f712d3
Version25.4.2
Bundle IDcom.jetpack.alpha
Commit6f712d3
App Center Buildjetpack-installable-builds #10099
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@kean kean force-pushed the fix/default-topics branch from 114123d to 2c1d3ac Compare November 8, 2024 23:55
let topic = ReaderDefaultTopic(entity: ReaderDefaultTopic.entity(), insertInto: context)
topic.type = TopicType
topic.path = path.rawValue
topic.title = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a required field but it's never used only by other topic types.

@@ -10,9 +10,6 @@
@import WordPressKit;
@import WordPressShared;

NSString * const ReaderTopicFreshlyPressedPathCommponent = @"freshly-pressed";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer used.

if ReaderHelpers.isTopicTag(topic) {
return true
}
return (topic is ReaderDefaultTopic) && !ReaderHelpers.topicIsLiked(topic)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has to be a better way to do it, but I'm not refactoring it in the scope of this PR.

@@ -214,11 +214,6 @@ import AutomatticTracks
/// - Returns: An instance of the controller
///
@objc class func controllerWithTopic(_ topic: ReaderAbstractTopic) -> ReaderStreamViewController {
// if a default discover topic is provided, treat it as a site to retrieve the header
if ReaderHelpers.topicIsDiscover(topic) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this anymore. The worst case scenario, it'll just open as a regular site feed.

@kean kean requested a review from crazytonyli November 8, 2024 23:58
@kean kean added the Reader label Nov 8, 2024
@kean kean added this to the 25.5 milestone Nov 8, 2024
@kean kean marked this pull request as ready for review November 9, 2024 00:06
@crazytonyli
Copy link
Contributor

Set a network breakpoint on /read/menu

Is this a breakpoint in Xcode, or do you mean intercepting the HTTP request from HTTP proxy apps?

case recommended = "/jpios/discover/recommended"
case firstPosts = "/jpios/discover/first-posts"
case latest = "/jpios/discover/latest"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean there should be three unique "default topics" (a.k.a "Discover" topics?) in Core Data? If that's the case, should we delete -[ReaderTopicService defaultTopicForRemoteTopic:inContext:] to avoid arbitrary ReaderDefaultTopic being created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two that are still remaining: one for "Recent" and one for "Likes", so I can't remove them just yet. The "Discover" topic will also be in the database for now, but the app never displays them anywhere, so it's going to be fine. My plan is to ultimately remove ReaderDefaultTopic entirely. There are no good reasons to store them in Core Data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this PR also fixes the following issue:

Steps

  • Open Discover
  • Select "Latest Posts" and wait until they load
  • Terminate the app
  • Reopen Discover (it shows "Recommended" again)

Expected result:

  • It loads new posts

Actual result:

  • It shows posts cached for "Latest Posts", then reloads

crazytonyli
crazytonyli previously approved these changes Nov 15, 2024
topic.type = TopicType
topic.path = path.rawValue
topic.title = ""
try context.save()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use performAndSave instead of saving the context directly. Or, at bare minimal, use ContextManager.save.

Also, we don't update and save the main context.

@kean kean force-pushed the fix/default-topics branch from 45c09af to 6f712d3 Compare November 15, 2024 13:29
@kean
Copy link
Contributor Author

kean commented Nov 18, 2024

I don't feel comfortable merging this late in the game, so I'm moving it to draft.

@kean kean marked this pull request as draft November 18, 2024 16:41
@wpmobilebot wpmobilebot modified the milestones: 25.5, 25.6 Dec 5, 2024
@wpmobilebot
Copy link
Contributor

Version 25.5 has now entered code-freeze, so the milestone of this PR has been updated to 25.6.

@wpmobilebot wpmobilebot modified the milestones: 25.6, 25.7 Dec 16, 2024
@wpmobilebot
Copy link
Contributor

Version 25.6 has now entered code-freeze, so the milestone of this PR has been updated to 25.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants