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

Add a @State date to the ProfileView that we use when refreshing auth… #1751

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Nos/Views/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct ProfileView: View {
@State private var showingOptions = false
@State private var showingReportMenu = false
@State private var relaySubscriptions = SubscriptionCancellables()

/// Keep track of the last time we downloaded Author data so we don't do it too much.
@State private var lastDownloadedAuthorData: Date?

@State private var selectedTab: ProfileFeedType = .notes

Expand Down Expand Up @@ -46,24 +49,30 @@ struct ProfileView: View {
}

// Profile data
// We use our own local date for fetching contact lists and follow sets, because we want to refresh them
// when the page is opened, especially because a lot of contact list data gets purged during the DatabaseCleaner
// routine, but we don't want to end up in an infinite loop like in
// [#175](https://github.com/verse-pbc/issues/issues/175)
relaySubscriptions.append(
await relayService.requestProfileData(
for: authorKey,
lastUpdateMetadata: author.lastUpdatedMetadata,
lastUpdatedContactList: nil, // always grab contact list because we purge follows aggressively
lastUpdatedFollowSets: nil // TODO: consider how we want to do this
lastUpdatedContactList: lastDownloadedAuthorData,
lastUpdatedFollowSets: lastDownloadedAuthorData
)
)

// reports
let reportFilter = Filter(
kinds: [.report],
pTags: [authorKey],
since: lastDownloadedAuthorData,
keepSubscriptionOpen: true
)
relaySubscriptions.append(
await relayService.fetchEvents(matching: reportFilter)
)
lastDownloadedAuthorData = .now
}

private var title: AttributedString {
Expand Down Expand Up @@ -189,9 +198,12 @@ struct ProfileView: View {
}
)
.alert(unwrapping: $alert)
.task {
.task {
await downloadAuthorData()
}
.onChange(of: refreshController.lastRefreshDate, { _, _ in
Task { await downloadAuthorData() }
})
}

var noteListView: some View {
Expand Down