Update FavoritesPersistenceService to use Peer

This commit is contained in:
islam
2025-09-20 01:26:19 +01:00
parent 7b20bdf821
commit a6d013bee9
3 changed files with 6 additions and 6 deletions
@@ -179,10 +179,10 @@ final class FavoritesPersistenceService: ObservableObject {
/// Resolve favorite status by short peer ID (16-hex derived from Noise pubkey) /// Resolve favorite status by short peer ID (16-hex derived from Noise pubkey)
/// Falls back to scanning favorites and matching on derived peer ID. /// Falls back to scanning favorites and matching on derived peer ID.
func getFavoriteStatus(forPeerID peerID: String) -> FavoriteRelationship? { func getFavoriteStatus(for peer: Peer) -> FavoriteRelationship? {
// Quick sanity: peerID should be 16 hex chars (8 bytes) // Quick sanity: peer.id should be 16 hex chars (8 bytes)
guard peerID.count == 16 else { return nil } guard peer.isShort else { return nil }
for (pubkey, rel) in favorites where Peer(publicKey: pubkey).id == peerID { for (pubkey, rel) in favorites where Peer(publicKey: pubkey) == peer {
return rel return rel
} }
return nil return nil
+1 -1
View File
@@ -94,7 +94,7 @@ final class MessageRouter {
return true return true
} }
} else if peerID.count == 16 { } 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 { fav.peerNostrPublicKey != nil {
return true return true
} }
+1 -1
View File
@@ -174,7 +174,7 @@ final class NostrTransport: Transport {
return npub return npub
} }
if peerID.count == 16, if peerID.count == 16,
let fav = FavoritesPersistenceService.shared.getFavoriteStatus(forPeerID: peerID), let fav = FavoritesPersistenceService.shared.getFavoriteStatus(for: Peer(str: peerID)),
let npub = fav.peerNostrPublicKey { let npub = fav.peerNostrPublicKey {
return npub return npub
} }