diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index f0cd7ce7..2c98aad3 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -294,6 +294,8 @@ 501F8C802A0220E1001AFC1D /* KeychainStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501F8C7F2A0220E1001AFC1D /* KeychainStorage.swift */; }; 501F8C822A0224EB001AFC1D /* KeychainStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501F8C812A0224EB001AFC1D /* KeychainStorageTests.swift */; }; 5053ACA72A56DF3B00851AE3 /* DeveloperSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5053ACA62A56DF3B00851AE3 /* DeveloperSettingsView.swift */; }; + 504323A72A34915F006AE6DC /* RelayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504323A62A34915F006AE6DC /* RelayModel.swift */; }; + 504323A92A3495B6006AE6DC /* RelayModelCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504323A82A3495B6006AE6DC /* RelayModelCache.swift */; }; 50A50A8D29A09E1C00C01BE7 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A50A8C29A09E1C00C01BE7 /* RequestTests.swift */; }; 50A60D142A28BEEE00186190 /* RelayLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A60D132A28BEEE00186190 /* RelayLog.swift */; }; 50B5685329F97CB400A23243 /* CredentialHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50B5685229F97CB400A23243 /* CredentialHandler.swift */; }; @@ -765,6 +767,8 @@ 501F8C7F2A0220E1001AFC1D /* KeychainStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainStorage.swift; sourceTree = ""; }; 501F8C812A0224EB001AFC1D /* KeychainStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainStorageTests.swift; sourceTree = ""; }; 5053ACA62A56DF3B00851AE3 /* DeveloperSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperSettingsView.swift; sourceTree = ""; }; + 504323A62A34915F006AE6DC /* RelayModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayModel.swift; sourceTree = ""; }; + 504323A82A3495B6006AE6DC /* RelayModelCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayModelCache.swift; sourceTree = ""; }; 50A50A8C29A09E1C00C01BE7 /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = ""; }; 50A60D132A28BEEE00186190 /* RelayLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayLog.swift; sourceTree = ""; }; 50B5685229F97CB400A23243 /* CredentialHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialHandler.swift; sourceTree = ""; }; @@ -1477,7 +1481,9 @@ children = ( 4CE8794729941DA700F758CC /* RelayFilters.swift */, 4CE8794B2995B59E00F758CC /* RelayMetadatas.swift */, + 504323A82A3495B6006AE6DC /* RelayModelCache.swift */, 4CC6193929DC777C006A86D1 /* RelayBootstrap.swift */, + 504323A62A34915F006AE6DC /* RelayModel.swift */, ); path = Relays; sourceTree = ""; @@ -1765,6 +1771,7 @@ 4C216F34286F5ACD00040376 /* DMView.swift in Sources */, 4C3EA64428FF558100C48A62 /* sha256.c in Sources */, 4CCF9AAF2A1FDBDB00E03CFB /* VideoPlayer.swift in Sources */, + 504323A72A34915F006AE6DC /* RelayModel.swift in Sources */, 4CF0ABF62985CD5500D66079 /* UserSearch.swift in Sources */, 4C363AA828297703006E126D /* InsertSort.swift in Sources */, 4C285C86283892E7008A31F1 /* CreateAccountModel.swift in Sources */, @@ -1785,6 +1792,7 @@ 4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */, 4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */, 4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */, + 504323A92A3495B6006AE6DC /* RelayModelCache.swift in Sources */, 3A8CC6CC2A2CFEF900940F5F /* StringUtil.swift in Sources */, 4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */, 4C363AA228296A7E006E126D /* SearchView.swift in Sources */, diff --git a/damus/Util/Relays/RelayModel.swift b/damus/Util/Relays/RelayModel.swift new file mode 100644 index 00000000..47c3fe48 --- /dev/null +++ b/damus/Util/Relays/RelayModel.swift @@ -0,0 +1,29 @@ +// +// RelayModel.swift +// damus +// +// Created by Bryan Montz on 6/10/23. +// + +import Foundation + +final class RelayModel: Hashable { + + let url: RelayURL + let log: RelayLog + let metadata: RelayMetadata + + init(_ url: RelayURL, metadata: RelayMetadata) { + self.url = url + self.log = RelayLog(url.url) + self.metadata = metadata + } + + static func == (lhs: RelayModel, rhs: RelayModel) -> Bool { + lhs.url == rhs.url + } + + func hash(into hasher: inout Hasher) { + hasher.combine(url) + } +} diff --git a/damus/Util/Relays/RelayModelCache.swift b/damus/Util/Relays/RelayModelCache.swift new file mode 100644 index 00000000..64a543f2 --- /dev/null +++ b/damus/Util/Relays/RelayModelCache.swift @@ -0,0 +1,27 @@ +// +// RelayModels.swift +// damus +// +// Created by Bryan Montz on 6/10/23. +// + +import Foundation + +final class RelayModelCache { + private var models = [RelayURL: RelayModel]() + + func model(withURL url: RelayURL) -> RelayModel? { + models[url] + } + + func model(with_relay_id url_string: String) -> RelayModel? { + guard let url = RelayURL(url_string) else { + return nil + } + return model(withURL: url) + } + + func insert(model: RelayModel) { + models[model.url] = model + } +}