File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import Foundation
2+ import Vapor
3+
4+ extension FCM {
5+ public func getTopics( token: String , on eventLoop: EventLoop ) -> EventLoopFuture < [ String ] > {
6+ return _getTopics ( token: token, on: eventLoop)
7+ }
8+
9+ public func _getTopics( token: String , on eventLoop: EventLoop ) -> EventLoopFuture < [ String ] > {
10+ guard let configuration = self . configuration else {
11+ fatalError ( " FCM not configured. Use app.fcm.configuration = ... " )
12+ }
13+ guard let serverKey = configuration. serverKey else {
14+ fatalError ( " FCM: GetTopics: Server Key is missing. " )
15+ }
16+ let url = self . iidURL + " info/ \( token) ?details=true "
17+ return getAccessToken ( ) . flatMap { accessToken -> EventLoopFuture < ClientResponse > in
18+ var headers = HTTPHeaders ( )
19+ headers. add ( name: . authorization, value: " key= \( serverKey) " )
20+
21+ return self . client. get ( URI ( string: url) , headers: headers)
22+ }
23+ . validate ( )
24+ . flatMapThrowing { response in
25+ struct Result : Codable {
26+ let rel : Relations
27+
28+ struct Relations : Codable {
29+ let topics : [ String : TopicMetadata ]
30+ }
31+
32+ struct TopicMetadata : Codable {
33+ let addDate : String
34+ }
35+ }
36+ let result = try response. content. decode ( Result . self, using: JSONDecoder ( ) )
37+ return Array ( result. rel. topics. keys)
38+ }
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments