Skip to content

Commit

Permalink
fix: realtime event payload
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed May 17, 2022
1 parent 24792b7 commit 871beac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ open class Client {
return response.body as! T
default:
let data = try await response.body.collect(upTo: Int.max)
if data.readableBytes == 0 {
return true as! T
}
let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any]

return converter?(dict!) ?? dict! as! T
Expand Down
16 changes: 16 additions & 0 deletions Sources/Appwrite/Models/AppwriteError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ open class AppwriteError : Swift.Error, Decodable {
self.type = type
}
}

extension AppwriteError: CustomStringConvertible {
public var description: String {
get {
return self.message
}
}
}

extension AppwriteError: LocalizedError {
public var errorDescription: String? {
get {
return self.message
}
}
}
6 changes: 3 additions & 3 deletions Sources/Appwrite/Models/RealtimeModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public class RealtimeCallback {
}

public class RealtimeResponseEvent {
public let event: String?
public let events: [String]?
public let channels: [String]?
public let timestamp: Int64?
public var payload: [String: Any]?

init(
event: String,
events: [String],
channels: [String],
timestamp: Int64,
payload: [String: Any]
) {
self.event = event
self.events = events
self.channels = channels
self.timestamp = timestamp
self.payload = payload
Expand Down
5 changes: 4 additions & 1 deletion Sources/Appwrite/Services/Realtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ extension Realtime: WebSocketClientDelegate {
guard let channels = data["channels"] as? Array<String> else {
return
}
guard let events = data["events"] as? Array<String> else {
return
}
guard let payload = data["payload"] as? [String: Any] else {
return
}
Expand All @@ -204,7 +207,7 @@ extension Realtime: WebSocketClientDelegate {
for subscription in activeSubscriptions {
if channels.contains(where: { subscription.value.channels.contains($0) }) {
let response = RealtimeResponseEvent(
event: data["event"] as! String,
events: events,
channels: channels,
timestamp: data["timestamp"] as! Int64,
payload: payload
Expand Down

0 comments on commit 871beac

Please sign in to comment.