feat: decode reactions when polling for open group messages

pull/638/head
ryanzhao 3 years ago
parent f99ae07309
commit a742e97d00

@ -33,20 +33,20 @@ extension OpenGroupAPI {
public let base64EncodedData: String? public let base64EncodedData: String?
public let base64EncodedSignature: String? public let base64EncodedSignature: String?
public let reactions: [String:Reaction]?
}
public struct Reaction: Codable, Equatable { public struct Reaction: Codable, Equatable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case total case count
case reactors case reactors
case you case you
} }
public let total: Int64 public let count: Int64
public let reactors: [String]? public let reactors: [String]?
public let you: Bool public let you: Bool
} }
public let reactions: [String:Reaction]?
}
} }
// MARK: - Decoder // MARK: - Decoder
@ -102,17 +102,17 @@ extension OpenGroupAPI.Message {
whisperTo: try? container.decode(String.self, forKey: .whisperTo), whisperTo: try? container.decode(String.self, forKey: .whisperTo),
base64EncodedData: maybeBase64EncodedData, base64EncodedData: maybeBase64EncodedData,
base64EncodedSignature: maybeBase64EncodedSignature, base64EncodedSignature: maybeBase64EncodedSignature,
reactions: [:] reactions: maybeReactions
) )
} }
} }
extension OpenGroupAPI.Reaction { extension OpenGroupAPI.Message.Reaction {
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self) let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
self = OpenGroupAPI.Reaction( self = OpenGroupAPI.Message.Reaction(
total: try container.decode(Int64.self, forKey: .total), count: try container.decode(Int64.self, forKey: .count),
reactors: try? container.decode([String].self, forKey: .reactors), reactors: try? container.decode([String].self, forKey: .reactors),
you: (try? container.decode(Bool.self, forKey: .you)) ?? false you: (try? container.decode(Bool.self, forKey: .you)) ?? false
) )

Loading…
Cancel
Save