commit fb82cc0531e1f5857186e14b7bd92cbd08f383f9 parent 90cd48ead78120a8bb9a5e82f2e94439722fceec Author: William Casarin <jb55@jb55.com> Date: Tue, 7 Feb 2023 10:20:12 -0800 ProfileModel: add follows helper This will be used for "Follows You" logic Diffstat:
M | damus/Models/ProfileModel.swift | | | 18 | ++++++++++++++++++ |
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git 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)