Mac: build GatewayProtocol target and typed presence handling

This commit is contained in:
Peter Steinberger
2025-12-09 15:35:06 +01:00
parent a7737912b0
commit 336c9d6caa
6 changed files with 262 additions and 101 deletions

View File

@@ -120,7 +120,8 @@ private actor GatewayChannelActor {
}
switch frame {
case let .res(res):
if let id = res.id, let waiter = pending.removeValue(forKey: id) {
let id = res.id
if let waiter = pending.removeValue(forKey: id) {
waiter.resume(returning: .res(res))
}
case let .event(evt):
@@ -182,12 +183,14 @@ private actor GatewayChannelActor {
throw NSError(domain: "Gateway", code: 2, userInfo: [NSLocalizedDescriptionKey: "unexpected frame"])
}
if res.ok == false {
let msg = (res.error?.message) ?? "gateway error"
let msg = (res.error?["message"]?.value as? String) ?? "gateway error"
throw NSError(domain: "Gateway", code: 3, userInfo: [NSLocalizedDescriptionKey: msg])
}
if let payload = res.payload?.value {
let payloadData = try JSONSerialization.data(withJSONObject: payload)
return payloadData
if JSONSerialization.isValidJSONObject(payload) {
let payloadData = try JSONSerialization.data(withJSONObject: payload)
return payloadData
}
}
return Data()
}

View File

@@ -97,8 +97,8 @@ final class InstancesStore: ObservableObject {
let frame = note.object as? GatewayFrame else { return }
switch frame {
case let .helloOk(hello):
let presence = hello.snapshot.presence
if let data = try? JSONEncoder().encode(presence) {
if JSONSerialization.isValidJSONObject(hello.snapshot.presence),
let data = try? JSONEncoder().encode(hello.snapshot.presence) {
Task { @MainActor [weak self] in self?.decodeAndApplyPresenceData(data) }
}
default: