Skip to content

Commit

Permalink
Merge pull request #824 from planetary-social/feature/show-profile-on…
Browse files Browse the repository at this point in the history
…-matching-npub-search

Show profile when search matches a valid npub
  • Loading branch information
joshuatbrown authored Jan 18, 2024
2 parents 6c0ae55 + 3eb7fd9 commit d1279ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Show the profile view when a search matches a valid User ID (npub).
- Added tabs to Profiles to filter posts.
- Fixed a bug that could cause the out of network warning to be shown on reposts in the stories view.
- Fixed a bug that prevented notes that failed to be published to be re-published again.
Expand Down
19 changes: 12 additions & 7 deletions Nos/Controller/SearchController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ class SearchController: ObservableObject {
@Published var query: String = ""
@Published var namedAuthors = [Author]()
@Published var authorSuggestions = [Author]()

var isSearching: Bool {
query.isEmpty
}


@Dependency(\.router) private var router
@Dependency(\.relayService) private var relayService
@Dependency(\.persistenceController) private var persistenceController
@Dependency(\.unsAPI) var unsAPI
Expand All @@ -45,8 +42,8 @@ class SearchController: ObservableObject {
.map { query in
// SIDE EFFECT WARNING
// These functions search other systems for the given query and add relevant authors to the database.
// The database then generates a notification which is listened to above and resulst are reloaded.
Task {
// The database then generates a notification which is listened to above and results are reloaded.
Task {
self.searchSubscriptions.removeAll()
self.searchRelays(for: query)
self.searchUNS(for: query)
Expand All @@ -60,6 +57,14 @@ class SearchController: ObservableObject {
}

func authors(named name: String) -> [Author] {
if let publicKey = PublicKey(npub: name),
let author = try? Author.findOrCreate(by: publicKey.hex, context: context) {
Task { @MainActor in
router.push(author)
}
clear()
return []
}
guard let authors = try? Author.find(named: name, context: context) else {
return []
}
Expand Down
2 changes: 1 addition & 1 deletion Nos/Views/DiscoverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct DiscoverView: View {
let strippedString = publicKeyString.trimmingCharacters(
in: NSCharacterSet.whitespacesAndNewlines
)
guard let publicKey = PublicKey(note: strippedString) ?? PublicKey(note: strippedString) else {
guard let publicKey = PublicKey(note: strippedString) else {
return nil
}
guard let note = try? Event.findOrCreateStubBy(id: publicKey.hex, context: viewContext) else {
Expand Down

0 comments on commit d1279ba

Please sign in to comment.