Skip to content
This repository was archived by the owner on Jan 28, 2019. It is now read-only.

Commit 461de5e

Browse files
committed
Fix parsing
1 parent 8d798f9 commit 461de5e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Sources/WebAPI.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,12 +782,16 @@ extension WebAPI {
782782
}
783783
}
784784

785+
private enum ReactionItemType: String {
786+
case file, comment, message
787+
}
788+
785789
public func getReactionsForFile(_ file: String, full: Bool = true, reactions: (([Reaction]) -> Void)?, failure: FailureClosure?) {
786-
getReactionsForItem(file, full: full, itemKey: "file", reactions: reactions, failure: failure)
790+
getReactionsForItem(file, full: full, type: .file, reactions: reactions, failure: failure)
787791
}
788792

789793
public func getReactionsForComment(_ comment: String, full: Bool = true, reactions: (([Reaction]) -> Void)?, failure: FailureClosure?) {
790-
getReactionsForItem(comment: comment, full: full, itemKey: "file", reactions: reactions, failure: failure)
794+
getReactionsForItem(comment: comment, full: full, type: .comment, reactions: reactions, failure: failure)
791795
}
792796

793797
public func getReactionsForMessage(
@@ -797,7 +801,7 @@ extension WebAPI {
797801
reactions: (([Reaction]) -> Void)?,
798802
failure: FailureClosure?
799803
) {
800-
getReactionsForItem(channel: channel, timestamp: timestamp, full: full, itemKey: "message", reactions: reactions, failure: failure)
804+
getReactionsForItem(channel: channel, timestamp: timestamp, full: full, type: .message, reactions: reactions, failure: failure)
801805
}
802806

803807
private func getReactionsForItem(
@@ -806,7 +810,7 @@ extension WebAPI {
806810
channel: String? = nil,
807811
timestamp: String? = nil,
808812
full: Bool,
809-
itemKey: String,
813+
type: ReactionItemType,
810814
reactions: (([Reaction]) -> Void)?,
811815
failure: FailureClosure?
812816
) {
@@ -819,11 +823,21 @@ extension WebAPI {
819823
"full": full
820824
]
821825
networkInterface.request(.reactionsGet, parameters: parameters, successClosure: {(response) in
822-
guard let item = response[itemKey] as? [[String: Any]] else {
826+
guard let item = response[type.rawValue] as? [String: Any] else {
823827
reactions?([])
824828
return
825829
}
826-
reactions?(item.map({ Reaction(reaction: $0) }))
830+
switch type {
831+
case .message:
832+
let message = Message(dictionary: item)
833+
reactions?(message.reactions)
834+
case .file:
835+
let file = File(file: item)
836+
reactions?(file.reactions)
837+
case .comment:
838+
let comment = Comment(comment: item)
839+
reactions?(comment.reactions)
840+
}
827841
}) {(error) in
828842
failure?(error)
829843
}

0 commit comments

Comments
 (0)