mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:25:19 +00:00
Fix compilation errors and prepare for App Store submission
- Fix NotificationService warnings by replacing unused error parameters with _ - Add public domain header to NotificationService.swift - Fix BluetoothMeshService compilation errors: - Replace removeAll with filter for processedKeyExchanges cleanup - Remove duplicate cleanupStalePeers function declaration - Remove duplicate peerLastSeenTimestamps property declaration - All code now compiles cleanly for both iOS and macOS targets
This commit is contained in:
@@ -40,12 +40,5 @@
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -88,10 +88,6 @@ class BluetoothMeshService: NSObject {
|
||||
private var peerListUpdateTimer: Timer?
|
||||
private let peerListUpdateDebounceInterval: TimeInterval = 0.1 // 100ms debounce for more responsive updates
|
||||
|
||||
// Stale peer cleanup
|
||||
private var stalePeerCleanupTimer: Timer?
|
||||
private var peerLastSeenTimestamps: [String: Date] = [:] // Track when we last saw each peer
|
||||
|
||||
// Cover traffic for privacy
|
||||
private var coverTrafficTimer: Timer?
|
||||
private let coverTrafficPrefix = "☂DUMMY☂" // Prefix to identify dummy messages after decryption
|
||||
@@ -850,7 +846,7 @@ class BluetoothMeshService: NSObject {
|
||||
peerRSSI.removeValue(forKey: peerID)
|
||||
announcedPeers.remove(peerID)
|
||||
announcedToPeers.remove(peerID)
|
||||
processedKeyExchanges.removeAll { $0.contains(peerID) }
|
||||
processedKeyExchanges = processedKeyExchanges.filter { !$0.contains(peerID) }
|
||||
|
||||
peerNicknamesLock.lock()
|
||||
let nickname = peerNicknames[peerID]
|
||||
@@ -1504,7 +1500,7 @@ class BluetoothMeshService: NSObject {
|
||||
peerLastSeenTimestamps.removeValue(forKey: stalePeerID)
|
||||
|
||||
// Remove from processed key exchanges
|
||||
processedKeyExchanges.removeAll { $0.contains(stalePeerID) }
|
||||
processedKeyExchanges = processedKeyExchanges.filter { !$0.contains(stalePeerID) }
|
||||
}
|
||||
|
||||
// If we had stale peers, notify the UI immediately
|
||||
@@ -2393,68 +2389,6 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
|
||||
return coverTrafficPrefix + (templates.randomElement() ?? "ok")
|
||||
}
|
||||
|
||||
// MARK: - Stale Peer Cleanup
|
||||
|
||||
private func cleanupStalePeers() {
|
||||
let staleThreshold: TimeInterval = 60.0 // Consider peers stale after 60 seconds of no activity
|
||||
let now = Date()
|
||||
|
||||
var peersToRemove: [String] = []
|
||||
|
||||
// Check for stale peers
|
||||
activePeersLock.lock()
|
||||
for peerID in activePeers {
|
||||
if let lastSeen = peerLastSeenTimestamps[peerID] {
|
||||
if now.timeIntervalSince(lastSeen) > staleThreshold {
|
||||
peersToRemove.append(peerID)
|
||||
}
|
||||
} else {
|
||||
// No timestamp recorded, consider it stale
|
||||
peersToRemove.append(peerID)
|
||||
}
|
||||
}
|
||||
activePeersLock.unlock()
|
||||
|
||||
// Remove stale peers
|
||||
for peerID in peersToRemove {
|
||||
print("[CLEANUP] Removing stale peer \(peerID) - last seen: \(peerLastSeenTimestamps[peerID]?.description ?? "never")")
|
||||
|
||||
// Remove from all tracking structures
|
||||
activePeersLock.lock()
|
||||
activePeers.remove(peerID)
|
||||
activePeersLock.unlock()
|
||||
|
||||
peerNicknamesLock.lock()
|
||||
let nickname = peerNicknames[peerID]
|
||||
peerNicknames.removeValue(forKey: peerID)
|
||||
peerNicknamesLock.unlock()
|
||||
|
||||
// Remove from other tracking
|
||||
announcedPeers.remove(peerID)
|
||||
announcedToPeers.remove(peerID)
|
||||
peerRSSI.removeValue(forKey: peerID)
|
||||
peerLastSeenTimestamps.removeValue(forKey: peerID)
|
||||
cachedMessagesSentToPeer.remove(peerID)
|
||||
|
||||
// Disconnect any associated peripherals
|
||||
if let peripheral = connectedPeripherals[peerID] {
|
||||
intentionalDisconnects.insert(peripheral.identifier.uuidString)
|
||||
centralManager.cancelPeripheralConnection(peripheral)
|
||||
connectedPeripherals.removeValue(forKey: peerID)
|
||||
peripheralCharacteristics.removeValue(forKey: peripheral)
|
||||
}
|
||||
|
||||
// Log the cleanup
|
||||
if let nick = nickname {
|
||||
print("[CLEANUP] Removed stale peer: \(nick) (\(peerID))")
|
||||
}
|
||||
}
|
||||
|
||||
// Notify UI if any peers were removed
|
||||
if !peersToRemove.isEmpty {
|
||||
notifyPeerListUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
private func updatePeerLastSeen(_ peerID: String) {
|
||||
peerLastSeenTimestamps[peerID] = Date()
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
//
|
||||
// NotificationService.swift
|
||||
// bitchat
|
||||
//
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
// For more information, see <https://unlicense.org>
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
#if os(iOS)
|
||||
@@ -12,11 +20,9 @@ class NotificationService {
|
||||
private init() {}
|
||||
|
||||
func requestAuthorization() {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
|
||||
if granted {
|
||||
// Permission granted
|
||||
} else if let error = error {
|
||||
// print("[NOTIFICATIONS] Permission error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,12 +55,8 @@ class NotificationService {
|
||||
trigger: nil // Deliver immediately
|
||||
)
|
||||
|
||||
UNUserNotificationCenter.current().add(request) { error in
|
||||
if let error = error {
|
||||
// print("[NOTIFICATIONS] Error sending notification: \(error)")
|
||||
} else {
|
||||
// Notification sent
|
||||
}
|
||||
UNUserNotificationCenter.current().add(request) { _ in
|
||||
// Notification added
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user