mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 03:45:21 +00:00
Fix Nostr subscriptions: connect on subscribe; handle inbound frames correctly\n\n- Call ensureConnections(to:) in subscribe() so queued REQs open sockets immediately and flush after ping\n- Correct ParsedInbound failable initializer to return parsed EVENT/EOSE/OK/NOTICE instead of always nil\n- Improves chat receipt of geohash and DM events after Tor readiness
This commit is contained in:
@@ -253,6 +253,8 @@ final class NostrRelayManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
SecureLogger.log("📋 Queued subscription id=\(id) for \(urls.count) relay(s)",
|
SecureLogger.log("📋 Queued subscription id=\(id) for \(urls.count) relay(s)",
|
||||||
category: SecureLogger.session, level: .debug)
|
category: SecureLogger.session, level: .debug)
|
||||||
|
// Ensure we actually have sockets opening to these relays so queued REQs can flush
|
||||||
|
ensureConnections(to: urls)
|
||||||
// If some targets are already connected, flush immediately for them
|
// If some targets are already connected, flush immediately for them
|
||||||
for url in urls {
|
for url in urls {
|
||||||
if let r = relays.first(where: { $0.url == url }), r.isConnected {
|
if let r = relays.first(where: { $0.url == url }), r.isConnected {
|
||||||
@@ -625,8 +627,7 @@ private enum ParsedInbound {
|
|||||||
guard let data = message.data,
|
guard let data = message.data,
|
||||||
let array = try? JSONSerialization.jsonObject(with: data) as? [Any],
|
let array = try? JSONSerialization.jsonObject(with: data) as? [Any],
|
||||||
array.count >= 2,
|
array.count >= 2,
|
||||||
let type = array[0] as? String
|
let type = array[0] as? String else {
|
||||||
else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,27 +638,33 @@ private enum ParsedInbound {
|
|||||||
let eventDict = array[2] as? [String: Any],
|
let eventDict = array[2] as? [String: Any],
|
||||||
let event = try? NostrEvent(from: eventDict) {
|
let event = try? NostrEvent(from: eventDict) {
|
||||||
self = .event(subId: subId, event: event)
|
self = .event(subId: subId, event: event)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
case "EOSE":
|
case "EOSE":
|
||||||
if let subId = array[1] as? String {
|
if let subId = array[1] as? String {
|
||||||
self = .eose(subscriptionId: subId)
|
self = .eose(subscriptionId: subId)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
case "OK":
|
case "OK":
|
||||||
if array.count >= 3,
|
if array.count >= 3,
|
||||||
let eventId = array[1] as? String,
|
let eventId = array[1] as? String,
|
||||||
let success = array[2] as? Bool {
|
let success = array[2] as? Bool {
|
||||||
let reason = array.count >= 4 ? (array[3] as? String ?? "no reason given") : "no reason given"
|
let reason = array.count >= 4 ? (array[3] as? String ?? "no reason given") : "no reason given"
|
||||||
self = .ok(eventId: eventId, success: success, reason: reason)
|
self = .ok(eventId: eventId, success: success, reason: reason)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
case "NOTICE":
|
case "NOTICE":
|
||||||
if array.count >= 2, let msg = array[1] as? String {
|
if array.count >= 2, let msg = array[1] as? String {
|
||||||
self = .notice(msg)
|
self = .notice(msg)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
break
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user