Skip to content

Commit

Permalink
Merge pull request #1718 from planetary-social/bdm/fix-lists-bug
Browse files Browse the repository at this point in the history
fixed a case where lists don't show up immediately after signing in
  • Loading branch information
bryanmontz authored Jan 2, 2025
2 parents 8a5ed3e + 8a02fee commit ad81857
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added pop-up tip for feed customization. [#101](https://github.com/verse-pbc/issues/issues/101)
- Added remembering which feed source is selected.
- Factored out the segmented picker on the ProfileHeader for reusability.
- Fixed a case where lists don't show up immediately after signing in.

### Internal Changes
- Upgraded to Xcode 16. [#1570](https://github.com/planetary-social/nos/issues/1570)
Expand Down
14 changes: 4 additions & 10 deletions Nos/Controller/FeedController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ enum FeedSource: RawRepresentable, Hashable, Equatable {
@Observable @MainActor final class FeedController {

@ObservationIgnored @Dependency(\.persistenceController) private var persistenceController
@ObservationIgnored @Dependency(\.currentUser) private var currentUser

let author: Author

var enabledSources: [FeedSource] = [.following]

Expand Down Expand Up @@ -106,7 +107,8 @@ enum FeedSource: RawRepresentable, Hashable, Equatable {

private var cancellables = Set<AnyCancellable>()

init() {
init(author: Author) {
self.author = author
observeLists()
observeRelays()

Expand All @@ -118,10 +120,6 @@ enum FeedSource: RawRepresentable, Hashable, Equatable {
}

private func observeLists() {
guard let author = currentUser.author else {
return
}

let request = NSFetchRequest<AuthorList>(entityName: "AuthorList")
request.sortDescriptors = [NSSortDescriptor(keyPath: \Event.createdAt, ascending: false)]
request.predicate = NSPredicate(
Expand All @@ -147,10 +145,6 @@ enum FeedSource: RawRepresentable, Hashable, Equatable {
}

private func observeRelays() {
guard let author = currentUser.author else {
return
}

let request = Relay.relays(for: author)

let relayWatcher = NSFetchedResultsController(
Expand Down
7 changes: 6 additions & 1 deletion Nos/Service/CurrentUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ import Dependencies
}

/// Subscribes to relays for important events concerning the current user like their latest contact list,
/// notifications, reports, mutes, zaps, etc.
/// notifications, reports, mutes, zaps, lists etc.
@MainActor func subscribe() async {
guard let key = publicKeyHex, let author else {
return
Expand All @@ -191,6 +191,11 @@ import Dependencies
await relayService.requestContactList(for: key, since: author.lastUpdatedContactList)
)

// Always request the user's lists
subscriptions.append(
await relayService.requestAuthorLists(for: key, since: nil)
)

// Subscribe to important events we may not get incidentally while browsing the feed
let latestReceivedEvent = try? viewContext.fetch(Event.lastReceived(for: author)).first
let importantEventsFilter = Filter(
Expand Down
9 changes: 8 additions & 1 deletion Nos/Views/Home/HomeFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct HomeFeedView: View {

@State private var refreshController = RefreshController(lastRefreshDate: Date.now + Self.staticLoadTime)
@State private var isVisible = false
@State private var feedController = FeedController()
@State private var feedController: FeedController

/// When set to true this will display a fullscreen progress wheel for a set amount of time to give us a chance
/// to get some data from relay. The amount of time is defined in `staticLoadTime`.
Expand All @@ -30,6 +30,13 @@ struct HomeFeedView: View {
@Binding var showFeedTip: Bool
@Binding var scrollOffsetY: CGFloat

init(user: Author, showFeedTip: Binding<Bool>, scrollOffsetY: Binding<CGFloat>) {
self.user = user
self._showFeedTip = showFeedTip
self._scrollOffsetY = scrollOffsetY
_feedController = State(initialValue: FeedController(author: user))
}

/// A tip to display at the top of the feed.
private let welcomeTip = WelcomeToFeedTip()

Expand Down
2 changes: 1 addition & 1 deletion NosTests/Service/Relay/RelayServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RelayServiceTests: XCTestCase {
XCTAssertEqual(resultFilter, expectedFilter)
}

func test_requestFollowSets_uses_correct_filter() async throws {
func test_requestAuthorLists_uses_correct_filter() async throws {
let since = Date()
let expectedFilter = Filter(
authorKeys: ["test"],
Expand Down

0 comments on commit ad81857

Please sign in to comment.