mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:25:18 +00:00
* Refactor BLE transport event handling * Make image output paths unique * Keep queued Nostr read receipts alive * Refine BLE ingress fanout * Rediscover BLE service after invalidation * Extract BLE notification retry buffer * Extract BLE inbound write buffer * Extract BLE fragment assembly buffer * Tidy secure log handling from device run * Allow self-authored RSR ingress replies * Harden read receipt queue test timing --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
48 lines
1.2 KiB
Swift
48 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
struct BLEPendingNotification<Target> {
|
|
let data: Data
|
|
let targets: [Target]?
|
|
}
|
|
|
|
struct BLEOutboundNotificationBuffer<Target> {
|
|
enum EnqueueResult {
|
|
case enqueued(count: Int)
|
|
case full(count: Int)
|
|
}
|
|
|
|
private var notifications: [BLEPendingNotification<Target>] = []
|
|
|
|
var count: Int {
|
|
notifications.count
|
|
}
|
|
|
|
var isEmpty: Bool {
|
|
notifications.isEmpty
|
|
}
|
|
|
|
mutating func removeAll() {
|
|
notifications.removeAll()
|
|
}
|
|
|
|
mutating func enqueue(data: Data, targets: [Target]?, capCount: Int) -> EnqueueResult {
|
|
guard notifications.count < capCount else {
|
|
return .full(count: notifications.count)
|
|
}
|
|
|
|
notifications.append(BLEPendingNotification(data: data, targets: targets))
|
|
return .enqueued(count: notifications.count)
|
|
}
|
|
|
|
mutating func takeAll() -> [BLEPendingNotification<Target>] {
|
|
let pending = notifications
|
|
notifications.removeAll()
|
|
return pending
|
|
}
|
|
|
|
mutating func prepend(_ pending: [BLEPendingNotification<Target>]) {
|
|
guard !pending.isEmpty else { return }
|
|
notifications.insert(contentsOf: pending, at: 0)
|
|
}
|
|
}
|