Skip to content

Commit

Permalink
Add a @State date to the ProfileView that we use when refreshing auth…
Browse files Browse the repository at this point in the history
…or data
  • Loading branch information
mplorentz committed Jan 31, 2025
1 parent 0d3df3c commit 2eab277
Showing 1 changed file with 15 additions and 3 deletions.
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

Check failure on line 53 in Nos/Views/Profile/ProfileView.swift

View workflow job for this annotation

GitHub Actions / swift_lint

Line should be 120 characters or less; currently it has 121 characters (line_length)

Check failure on line 53 in Nos/Views/Profile/ProfileView.swift

View workflow job for this annotation

GitHub Actions / swift_lint

Line should be 120 characters or less; currently it has 121 characters (line_length)
// 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

0 comments on commit 2eab277

Please sign in to comment.