Skip to content

Commit

Permalink
Merge pull request #837 from planetary-social/fix-empty-stories-view
Browse files Browse the repository at this point in the history
Fixed a bug where not much stories data was downloaded
  • Loading branch information
mplorentz authored Jan 20, 2024
2 parents 08be660 + 6ffb4bc commit 6472b50
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Nos/Views/Home/HomeFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct HomeFeedView: View {
timeIntervalSince1970: Date.now.timeIntervalSince1970 + Double(Self.initialLoadTime)
)
@State private var isVisible = false
@State private var cancellables = [AnyCancellable]()
@State private var relaySubscriptions = [SubscriptionCancellable]()
@State private var performingInitialLoad = true
@State private var isShowingRelayList = false
static let initialLoadTime = 2
Expand All @@ -48,6 +48,23 @@ struct HomeFeedView: View {
)
}

/// Downloads the data we need to show stories.
func downloadStories() async {
relaySubscriptions.removeAll()

let followedKeys = await Array(currentUser.socialGraph.followedKeys)

if !followedKeys.isEmpty {
let textFilter = Filter(
authorKeys: followedKeys,
kinds: [.text, .delete, .repost, .longFormContent, .report],
since: storiesCutoffDate
)
let textSubs = await relayService.subscribeToEvents(matching: textFilter)
relaySubscriptions.append(textSubs)
}
}

var body: some View {
Group {
if performingInitialLoad {
Expand Down Expand Up @@ -148,6 +165,9 @@ struct HomeFeedView: View {
}
.padding(.top, 1)
.nosNavigationBar(title: isShowingStories ? .localizable.stories : .localizable.homeFeed)
.task {
await downloadStories()
}
.onAppear {
if router.selectedTab == .home {
isVisible = true
Expand Down

0 comments on commit 6472b50

Please sign in to comment.