diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 095109ee..5704081a 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -138,6 +138,7 @@ 4C8682872814DE470026224F /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8682862814DE470026224F /* ProfileView.swift */; }; 4C8D00C829DF791C0036AF10 /* CompatibleAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */; }; 4C8D00CA29DF80350036AF10 /* TruncatedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8D00C929DF80350036AF10 /* TruncatedText.swift */; }; + 4C8D00CC29DF92DF0036AF10 /* Hashtags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8D00CB29DF92DF0036AF10 /* Hashtags.swift */; }; 4C8EC52529D1FA6C0085D9A8 /* DamusColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8EC52429D1FA6C0085D9A8 /* DamusColors.swift */; }; 4C90BD162839DB54008EE7EF /* NostrMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C90BD152839DB54008EE7EF /* NostrMetadata.swift */; }; 4C90BD18283A9EE5008EE7EF /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C90BD17283A9EE5008EE7EF /* LoginView.swift */; }; @@ -539,6 +540,7 @@ 4C8682862814DE470026224F /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = ""; }; 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatibleAttribute.swift; sourceTree = ""; }; 4C8D00C929DF80350036AF10 /* TruncatedText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TruncatedText.swift; sourceTree = ""; }; + 4C8D00CB29DF92DF0036AF10 /* Hashtags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hashtags.swift; sourceTree = ""; }; 4C8EC52429D1FA6C0085D9A8 /* DamusColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusColors.swift; sourceTree = ""; }; 4C90BD152839DB54008EE7EF /* NostrMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NostrMetadata.swift; sourceTree = ""; }; 4C90BD17283A9EE5008EE7EF /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; @@ -988,6 +990,7 @@ 4CE4F0F129D4FCFA005914DB /* DebouncedOnChange.swift */, 4C1A9A1929DCA17E00516EAC /* ReplyCounter.swift */, 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */, + 4C8D00CB29DF92DF0036AF10 /* Hashtags.swift */, ); path = Util; sourceTree = ""; @@ -1631,6 +1634,7 @@ 4CE6DF1627F8DEBF00C66700 /* RelayConnection.swift in Sources */, 4C3BEFD6281D995700B3DE84 /* ActionBarModel.swift in Sources */, 4C363AA428296DEE006E126D /* SearchModel.swift in Sources */, + 4C8D00CC29DF92DF0036AF10 /* Hashtags.swift in Sources */, 4CEE2AF3280B25C500AB5EEF /* ProfilePicView.swift in Sources */, 4CC7AAF6297F1A6A00430951 /* EventBody.swift in Sources */, 4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */, diff --git a/damus/Assets.xcassets/Colors/DamusBrown.colorset/Contents.json b/damus/Assets.xcassets/Colors/DamusBrown.colorset/Contents.json new file mode 100644 index 00000000..2f922bce --- /dev/null +++ b/damus/Assets.xcassets/Colors/DamusBrown.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "red" : "0xBE", + "green" : "0x5F", + "blue" : "0x00" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/Hashtags/Contents.json b/damus/Assets.xcassets/Hashtags/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/bitcoin-hashtag.imageset/Contents.json b/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/Contents.json similarity index 100% rename from damus/Assets.xcassets/bitcoin-hashtag.imageset/Contents.json rename to damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/Contents.json diff --git a/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/bitcoin-hashtag.svg b/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/bitcoin-hashtag.svg new file mode 100644 index 00000000..62f133a6 --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/bitcoin-hashtag.imageset/bitcoin-hashtag.svg @@ -0,0 +1,43 @@ + + + + + + + + diff --git a/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/Contents.json b/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/Contents.json new file mode 100644 index 00000000..c4af4c7d --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "coffee.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "coffee.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "coffee.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/coffee.svg b/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/coffee.svg new file mode 100644 index 00000000..ad25418b --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/coffee-hashtag.imageset/coffee.svg @@ -0,0 +1,55 @@ + + + + + Svg Vector Icons : http://www.onlinewebfonts.com/icon + + diff --git a/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/Contents.json b/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/Contents.json new file mode 100644 index 00000000..f63c1f1a --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "nostr-hashtag.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "nostr-hashtag.svg", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "nostr-hashtag.svg", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/nostr-hashtag.svg b/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/nostr-hashtag.svg new file mode 100644 index 00000000..079e981e --- /dev/null +++ b/damus/Assets.xcassets/Hashtags/nostr-hashtag.imageset/nostr-hashtag.svg @@ -0,0 +1,51 @@ + + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + diff --git a/damus/Assets.xcassets/bitcoin-hashtag.imageset/bitcoin-hashtag.svg b/damus/Assets.xcassets/bitcoin-hashtag.imageset/bitcoin-hashtag.svg deleted file mode 100644 index 19bc02e1..00000000 --- a/damus/Assets.xcassets/bitcoin-hashtag.imageset/bitcoin-hashtag.svg +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - diff --git a/damus/Components/DamusColors.swift b/damus/Components/DamusColors.swift index 96841775..e3b73ae8 100644 --- a/damus/Components/DamusColors.swift +++ b/damus/Components/DamusColors.swift @@ -12,6 +12,7 @@ class DamusColors { static let adaptableGrey = Color("DamusAdaptableGrey") static let white = Color("DamusWhite") static let black = Color("DamusBlack") + static let brown = Color("DamusBrown") static let lightGrey = Color("DamusLightGrey") static let mediumGrey = Color("DamusMediumGrey") static let darkGrey = Color("DamusDarkGrey") diff --git a/damus/Util/Hashtags.swift b/damus/Util/Hashtags.swift new file mode 100644 index 00000000..7afd4bfd --- /dev/null +++ b/damus/Util/Hashtags.swift @@ -0,0 +1,60 @@ +// +// Hashtags.swift +// damus +// +// Created by William Casarin on 2023-04-06. +// + +import Foundation +import SwiftUI + +struct CustomHashtag { + let name: String + let color: Color? + + init(name: String, color: Color? = nil) { + self.name = name + self.color = color + } + + static let coffee = CustomHashtag(name: "coffee", color: DamusColors.brown) + static let bitcoin = CustomHashtag(name: "bitcoin", color: Color.orange) + static let nostr = CustomHashtag(name: "nostr", color: DamusColors.purple) +} + + +let custom_hashtags: [String: CustomHashtag] = [ + "bitcoin": CustomHashtag.bitcoin, + "nostr": CustomHashtag.nostr, + "coffee": CustomHashtag.coffee, + "coffeechain": CustomHashtag.coffee, +] + +func hashtag_str(_ htag: String) -> CompatibleText { + var attributedString = AttributedString(stringLiteral: "#\(htag)") + attributedString.link = URL(string: "damus:t:\(htag)") + + let lowertag = htag.lowercased() + + var text = Text(attributedString) + if let custom_hashtag = custom_hashtags[lowertag] { + if let col = custom_hashtag.color { + attributedString.foregroundColor = col + } + + let name = custom_hashtag.name + + text = Text(attributedString) + if let img = UIImage(named: "\(name)-hashtag") { + attributedString = attributedString + " " + attributed_string_attach_icon(&attributedString, img: img) + } + let img = Image("\(name)-hashtag") + text = text + Text(" \(img)") + } else { + attributedString.foregroundColor = DamusColors.purple + } + + return CompatibleText(text: text, attributed: attributedString) + } + diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift index 8ff767d1..0cffc0f2 100644 --- a/damus/Views/NoteContentView.swift +++ b/damus/Views/NoteContentView.swift @@ -218,27 +218,6 @@ func attributed_string_attach_icon(_ astr: inout AttributedString, img: UIImage) astr.append(wrapped) } -func hashtag_str(_ htag: String) -> CompatibleText { - var attributedString = AttributedString(stringLiteral: "#\(htag)") - attributedString.link = URL(string: "damus:t:\(htag)") - - var text = Text(attributedString) - - if htag.lowercased() == "bitcoin" { - attributedString.foregroundColor = Color.orange - if let img = UIImage(named: "bitcoin-hashtag") { - attributedString = attributedString + " " - attributed_string_attach_icon(&attributedString, img: img) - } - let img = Image("bitcoin-hashtag") - text = text.foregroundColor(.orange) + Text(" \(img)") - } else { - attributedString.foregroundColor = DamusColors.purple - } - - return CompatibleText(text: text, attributed: attributedString) - } - func url_str(_ url: URL) -> CompatibleText { var attributedString = AttributedString(stringLiteral: url.absoluteString) attributedString.link = url