From a6d013bee9816ffb5e10b57f3734cdb7baafc44a Mon Sep 17 00:00:00 2001 From: islam <2553451+qalandarov@users.noreply.github.com> Date: Thu, 18 Sep 2025 01:49:37 +0100 Subject: [PATCH] Update `FavoritesPersistenceService` to use `Peer` --- bitchat/Services/FavoritesPersistenceService.swift | 8 ++++---- bitchat/Services/MessageRouter.swift | 2 +- bitchat/Services/NostrTransport.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bitchat/Services/FavoritesPersistenceService.swift b/bitchat/Services/FavoritesPersistenceService.swift index effbf41e..1fb89cac 100644 --- a/bitchat/Services/FavoritesPersistenceService.swift +++ b/bitchat/Services/FavoritesPersistenceService.swift @@ -179,10 +179,10 @@ final class FavoritesPersistenceService: ObservableObject { /// Resolve favorite status by short peer ID (16-hex derived from Noise pubkey) /// Falls back to scanning favorites and matching on derived peer ID. - func getFavoriteStatus(forPeerID peerID: String) -> FavoriteRelationship? { - // Quick sanity: peerID should be 16 hex chars (8 bytes) - guard peerID.count == 16 else { return nil } - for (pubkey, rel) in favorites where Peer(publicKey: pubkey).id == peerID { + func getFavoriteStatus(for peer: Peer) -> FavoriteRelationship? { + // Quick sanity: peer.id should be 16 hex chars (8 bytes) + guard peer.isShort else { return nil } + for (pubkey, rel) in favorites where Peer(publicKey: pubkey) == peer { return rel } return nil diff --git a/bitchat/Services/MessageRouter.swift b/bitchat/Services/MessageRouter.swift index 63d8a92d..c30c0e74 100644 --- a/bitchat/Services/MessageRouter.swift +++ b/bitchat/Services/MessageRouter.swift @@ -94,7 +94,7 @@ final class MessageRouter { return true } } else if peerID.count == 16 { - if let fav = FavoritesPersistenceService.shared.getFavoriteStatus(forPeerID: peerID), + if let fav = FavoritesPersistenceService.shared.getFavoriteStatus(for: Peer(str: peerID)), fav.peerNostrPublicKey != nil { return true } diff --git a/bitchat/Services/NostrTransport.swift b/bitchat/Services/NostrTransport.swift index 8aee7ab3..710a958f 100644 --- a/bitchat/Services/NostrTransport.swift +++ b/bitchat/Services/NostrTransport.swift @@ -174,7 +174,7 @@ final class NostrTransport: Transport { return npub } if peerID.count == 16, - let fav = FavoritesPersistenceService.shared.getFavoriteStatus(forPeerID: peerID), + let fav = FavoritesPersistenceService.shared.getFavoriteStatus(for: Peer(str: peerID)), let npub = fav.peerNostrPublicKey { return npub }