diff --git a/bitchat/Services/FavoritesPersistenceService.swift b/bitchat/Services/FavoritesPersistenceService.swift index 21e7be5d..ff4d9e08 100644 --- a/bitchat/Services/FavoritesPersistenceService.swift +++ b/bitchat/Services/FavoritesPersistenceService.swift @@ -189,115 +189,6 @@ final class FavoritesPersistenceService: ObservableObject { return nil } - /// Update Nostr public key for a peer - func updateNostrPublicKey(for peerNoisePublicKey: Data, nostrPubkey: String) { - guard let existing = favorites[peerNoisePublicKey] else { return } - - let updated = FavoriteRelationship( - peerNoisePublicKey: existing.peerNoisePublicKey, - peerNostrPublicKey: nostrPubkey, - peerNickname: existing.peerNickname, - isFavorite: existing.isFavorite, - theyFavoritedUs: existing.theyFavoritedUs, - favoritedAt: existing.favoritedAt, - lastUpdated: Date() - ) - - favorites[peerNoisePublicKey] = updated - saveFavorites() - } - - /// Update nickname for an existing favorite - func updateNickname(for peerNoisePublicKey: Data, newNickname: String) { - guard let existing = favorites[peerNoisePublicKey] else { return } - - // Skip if nickname hasn't changed - if existing.peerNickname == newNickname { return } - - // Updating nickname for favorite - - let updated = FavoriteRelationship( - peerNoisePublicKey: existing.peerNoisePublicKey, - peerNostrPublicKey: existing.peerNostrPublicKey, - peerNickname: newNickname, - isFavorite: existing.isFavorite, - theyFavoritedUs: existing.theyFavoritedUs, - favoritedAt: existing.favoritedAt, - lastUpdated: Date() - ) - - favorites[peerNoisePublicKey] = updated - saveFavorites() - - // Notify observers - NotificationCenter.default.post( - name: .favoriteStatusChanged, - object: nil, - userInfo: ["peerPublicKey": peerNoisePublicKey] - ) - } - - /// Update noise public key when peer reconnects with new ID - func updateNoisePublicKey(from oldKey: Data, to newKey: Data, peerNickname: String) { - guard let existing = favorites[oldKey] else { - SecureLogger.warning("⚠️ Cannot update noise key - no favorite found for \(oldKey.hexEncodedString())", category: .session) - return - } - - // Check if we already have a favorite with the new key - if favorites[newKey] != nil { - SecureLogger.warning("⚠️ Favorite already exists with new key \(newKey.hexEncodedString()), removing old entry", category: .session) - favorites.removeValue(forKey: oldKey) - saveFavorites() - return - } - - // Updating noise public key - - // Remove old entry - favorites.removeValue(forKey: oldKey) - - // Add with new key - let updated = FavoriteRelationship( - peerNoisePublicKey: newKey, - peerNostrPublicKey: existing.peerNostrPublicKey, - peerNickname: peerNickname, - isFavorite: existing.isFavorite, - theyFavoritedUs: existing.theyFavoritedUs, - favoritedAt: existing.favoritedAt, - lastUpdated: Date() - ) - - favorites[newKey] = updated - saveFavorites() - - // Notify observers with both old and new keys - NotificationCenter.default.post( - name: .favoriteStatusChanged, - object: nil, - userInfo: [ - "peerPublicKey": newKey, - "oldPeerPublicKey": oldKey, - "isKeyUpdate": true - ] - ) - } - - /// Get all favorites (including non-mutual) - func getAllFavorites() -> [FavoriteRelationship] { - favorites.values.filter { $0.isFavorite } - } - - /// Get only mutual favorites - func getMutualFavorites() -> [FavoriteRelationship] { - favorites.values.filter { $0.isMutual } - } - - /// Get all favorite relationships (including where they favorited us) - func getAllRelationships() -> [FavoriteRelationship] { - Array(favorites.values) - } - /// Clear all favorites - used for panic mode func clearAllFavorites() { SecureLogger.warning("🧹 Clearing all favorites (panic mode)", category: .session) diff --git a/bitchat/Services/NotificationService.swift b/bitchat/Services/NotificationService.swift index 595c85db..1f5a972c 100644 --- a/bitchat/Services/NotificationService.swift +++ b/bitchat/Services/NotificationService.swift @@ -70,26 +70,6 @@ final class NotificationService { sendLocalNotification(title: title, body: body, identifier: identifier, userInfo: userInfo) } - func sendFavoriteOnlineNotification(nickname: String) { - // Send directly without checking app state for favorites - DispatchQueue.main.async { - let content = UNMutableNotificationContent() - content.title = "⭐ \(nickname) is online!" - content.body = "wanna get in there?" - content.sound = .default - - let request = UNNotificationRequest( - identifier: "favorite-online-\(UUID().uuidString)", - content: content, - trigger: nil - ) - - UNUserNotificationCenter.current().add(request) { _ in - // Notification added - } - } - } - // Geohash public chat notification with deep link to a specific geohash func sendGeohashActivityNotification(geohash: String, titlePrefix: String = "#", bodyPreview: String) { let title = "\(titlePrefix)\(geohash)"