From fb82cc0531e1f5857186e14b7bd92cbd08f383f9 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 7 Feb 2023 10:20:12 -0800 Subject: [PATCH] ProfileModel: add follows helper This will be used for "Follows You" logic --- damus/Models/ProfileModel.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift index c463fe98..b743b97b 100644 --- a/damus/Models/ProfileModel.swift +++ b/damus/Models/ProfileModel.swift @@ -20,6 +20,24 @@ class ProfileModel: ObservableObject, Equatable { var sub_id = UUID().description var prof_subid = UUID().description + func follows(pubkey: String) -> Bool { + guard let contacts = self.contacts else { + return false + } + + for tag in contacts.tags { + guard tag.count >= 2 && tag[0] == "p" else { + continue + } + + if tag[1] == pubkey { + return true + } + } + + return false + } + func get_follow_target() -> FollowTarget { if let contacts = contacts { return .contact(contacts)