@@ -782,12 +782,16 @@ extension WebAPI {
782
782
}
783
783
}
784
784
785
+ private enum ReactionItemType : String {
786
+ case file, comment, message
787
+ }
788
+
785
789
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)
787
791
}
788
792
789
793
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)
791
795
}
792
796
793
797
public func getReactionsForMessage(
@@ -797,7 +801,7 @@ extension WebAPI {
797
801
reactions: ( ( [ Reaction ] ) -> Void ) ? ,
798
802
failure: FailureClosure ?
799
803
) {
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)
801
805
}
802
806
803
807
private func getReactionsForItem(
@@ -806,7 +810,7 @@ extension WebAPI {
806
810
channel: String ? = nil ,
807
811
timestamp: String ? = nil ,
808
812
full: Bool ,
809
- itemKey : String ,
813
+ type : ReactionItemType ,
810
814
reactions: ( ( [ Reaction ] ) -> Void ) ? ,
811
815
failure: FailureClosure ?
812
816
) {
@@ -819,11 +823,21 @@ extension WebAPI {
819
823
" full " : full
820
824
]
821
825
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 {
823
827
reactions ? ( [ ] )
824
828
return
825
829
}
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
+ }
827
841
} ) { ( error) in
828
842
failure ? ( error)
829
843
}
0 commit comments