mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 15:45:20 +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 * Extract BLE outbound fragment scheduler * Harden app CI media tests * Redact BLE message content from logs * Extract BLE Noise session queues * Fix BLE read receipt UI updates * Allow self-authored RSR ingress replies * Harden read receipt queue test timing * Extract BLE outbound policy and incoming file storage * Avoid duplicate BLE link snapshots during send * Canonicalize Nostr relay URLs --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
47 lines
1.6 KiB
Swift
47 lines
1.6 KiB
Swift
import BitFoundation
|
|
import Foundation
|
|
|
|
struct BLEPendingPrivateMessage: Equatable {
|
|
let content: String
|
|
let messageID: String
|
|
}
|
|
|
|
struct BLENoiseSessionQueues {
|
|
private var privateMessagesByPeerID: [PeerID: [BLEPendingPrivateMessage]] = [:]
|
|
private var typedPayloadsByPeerID: [PeerID: [Data]] = [:]
|
|
|
|
var isEmpty: Bool {
|
|
privateMessagesByPeerID.isEmpty && typedPayloadsByPeerID.isEmpty
|
|
}
|
|
|
|
mutating func removeAll() {
|
|
privateMessagesByPeerID.removeAll()
|
|
typedPayloadsByPeerID.removeAll()
|
|
}
|
|
|
|
mutating func appendPrivateMessage(content: String, messageID: String, for peerID: PeerID) {
|
|
privateMessagesByPeerID[peerID, default: []].append(BLEPendingPrivateMessage(content: content, messageID: messageID))
|
|
}
|
|
|
|
mutating func takePrivateMessages(for peerID: PeerID) -> [BLEPendingPrivateMessage] {
|
|
let messages = privateMessagesByPeerID[peerID] ?? []
|
|
privateMessagesByPeerID.removeValue(forKey: peerID)
|
|
return messages
|
|
}
|
|
|
|
mutating func prependPrivateMessages(_ messages: [BLEPendingPrivateMessage], for peerID: PeerID) {
|
|
guard !messages.isEmpty else { return }
|
|
privateMessagesByPeerID[peerID, default: []].insert(contentsOf: messages, at: 0)
|
|
}
|
|
|
|
mutating func appendTypedPayload(_ payload: Data, for peerID: PeerID) {
|
|
typedPayloadsByPeerID[peerID, default: []].append(payload)
|
|
}
|
|
|
|
mutating func takeTypedPayloads(for peerID: PeerID) -> [Data] {
|
|
let payloads = typedPayloadsByPeerID[peerID] ?? []
|
|
typedPayloadsByPeerID.removeValue(forKey: peerID)
|
|
return payloads
|
|
}
|
|
}
|