damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 3b07a207c408f58b34d939dcb7c6b7b54596b627
parent d9a06e69aeae3dcaef6442f5489567b93cf2f15c
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 28 Jun 2023 16:26:39 +0200

post: extract createUserTag so it can be re-used

Diffstat:
Mdamus/Views/Posting/UserSearch.swift | 30++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/damus/Views/Posting/UserSearch.swift b/damus/Views/Posting/UserSearch.swift @@ -39,7 +39,7 @@ struct UserSearch: View { guard let pk = bech32_pubkey(user.pubkey) else { return } - let tagAttributedString = createUserTag(for: user, with: pk) + let tagAttributedString = user_tag_attr_string(profile: user.profile, pubkey: pk) appendUserTag(withTag: tagAttributedString) } @@ -57,19 +57,6 @@ struct UserSearch: View { newCursorIndex = wordRange.location + tagAttributedString.string.count } - private func createUserTag(for user: SearchedUser, with pk: String) -> NSMutableAttributedString { - let name = Profile.displayName(profile: user.profile, pubkey: pk).username.truncate(maxLength: 50) - let tagString = "@\(name)\u{200B} " - - let tagAttributedString = NSMutableAttributedString(string: tagString, - attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), - NSAttributedString.Key.link: "nostr:\(pk)"]) - tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2)) - tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2)) - - return tagAttributedString - } - var body: some View { VStack(spacing: 0) { Divider() @@ -161,3 +148,18 @@ func search_users_for_autocomplete(profiles: Profiles, tags: [[String]], search return matches } + +func user_tag_attr_string(profile: Profile?, pubkey: String) -> NSMutableAttributedString { + let display_name = Profile.displayName(profile: profile, pubkey: pubkey) + let name = display_name.username.truncate(maxLength: 50) + let tagString = "@\(name)\u{200B} " + + let tagAttributedString = NSMutableAttributedString(string: tagString, + attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18.0), + NSAttributedString.Key.link: "nostr:\(pubkey)"]) + tagAttributedString.removeAttribute(.link, range: NSRange(location: tagAttributedString.length - 2, length: 2)) + tagAttributedString.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.label], range: NSRange(location: tagAttributedString.length - 2, length: 2)) + + return tagAttributedString +} +