mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 23:45:18 +00:00
Favorites: remove npub resend tracking and nickname-based key migration; rely on Noise key as identity
This commit is contained in:
@@ -13,12 +13,16 @@ final class FavoritesPersistenceService: ObservableObject {
|
|||||||
let theyFavoritedUs: Bool
|
let theyFavoritedUs: Bool
|
||||||
let favoritedAt: Date
|
let favoritedAt: Date
|
||||||
let lastUpdated: Date
|
let lastUpdated: Date
|
||||||
|
// Track what we last sent as OUR npub to this peer, to avoid resending unless it changes
|
||||||
|
// Note: we do not track which npub we last sent to them; sending happens only on favorite toggle
|
||||||
|
|
||||||
var isMutual: Bool {
|
var isMutual: Bool {
|
||||||
isFavorite && theyFavoritedUs
|
isFavorite && theyFavoritedUs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We intentionally do not track when we last sent our npub; sending happens only on favorite toggle.
|
||||||
|
|
||||||
private static let storageKey = "chat.bitchat.favorites"
|
private static let storageKey = "chat.bitchat.favorites"
|
||||||
private static let keychainService = "chat.bitchat.favorites"
|
private static let keychainService = "chat.bitchat.favorites"
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ final class MessageRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendFavoriteNotification(to peerID: String, isFavorite: Bool) {
|
func sendFavoriteNotification(to peerID: String, isFavorite: Bool) {
|
||||||
|
// Route via mesh when connected; else use Nostr
|
||||||
if mesh.isPeerConnected(peerID) {
|
if mesh.isPeerConnected(peerID) {
|
||||||
mesh.sendFavoriteNotification(to: peerID, isFavorite: isFavorite)
|
mesh.sendFavoriteNotification(to: peerID, isFavorite: isFavorite)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -195,27 +195,6 @@ final class UnifiedPeerService: ObservableObject, TransportPeerEventsDelegate {
|
|||||||
let favoriteStatus = favorites[noiseKey] {
|
let favoriteStatus = favorites[noiseKey] {
|
||||||
peer.favoriteStatus = favoriteStatus
|
peer.favoriteStatus = favoriteStatus
|
||||||
peer.nostrPublicKey = favoriteStatus.peerNostrPublicKey
|
peer.nostrPublicKey = favoriteStatus.peerNostrPublicKey
|
||||||
} else {
|
|
||||||
// Check by nickname for reconnected peers
|
|
||||||
let favoriteByNickname = favorites.values.first {
|
|
||||||
$0.peerNickname == peerInfo.nickname
|
|
||||||
}
|
|
||||||
|
|
||||||
if let favorite = favoriteByNickname,
|
|
||||||
let noiseKey = peerInfo.noisePublicKey {
|
|
||||||
SecureLogger.debug("🔄 Found favorite for '\(peerInfo.nickname)' by nickname, updating noise key", category: .session)
|
|
||||||
|
|
||||||
// Update the favorite's key in persistence
|
|
||||||
favoritesService.updateNoisePublicKey(
|
|
||||||
from: favorite.peerNoisePublicKey,
|
|
||||||
to: noiseKey,
|
|
||||||
peerNickname: peerInfo.nickname
|
|
||||||
)
|
|
||||||
|
|
||||||
// Get updated favorite
|
|
||||||
peer.favoriteStatus = favoritesService.getFavoriteStatus(for: noiseKey)
|
|
||||||
peer.nostrPublicKey = peer.favoriteStatus?.peerNostrPublicKey ?? favorite.peerNostrPublicKey
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return peer
|
return peer
|
||||||
|
|||||||
Reference in New Issue
Block a user