@@ -128,11 +128,6 @@ func New(conf *config.Config) (*Server, error) {
128
128
if err != nil {
129
129
return nil , err
130
130
}
131
- for _ , t := range topics {
132
- if firebaseSubscriber != nil {
133
- t .Subscribe (firebaseSubscriber )
134
- }
135
- }
136
131
return & Server {
137
132
config : conf ,
138
133
cache : cache ,
@@ -284,13 +279,20 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request, _ *visito
284
279
if m .Message == "" {
285
280
return errHTTPBadRequest
286
281
}
287
- title , priority , tags , cache := parseHeaders (r .Header )
282
+ title , priority , tags , cache , firebase := parseHeaders (r .Header )
288
283
m .Title = title
289
284
m .Priority = priority
290
285
m .Tags = tags
291
286
if err := t .Publish (m ); err != nil {
292
287
return err
293
288
}
289
+ if s .firebase != nil && firebase {
290
+ go func () {
291
+ if err := s .firebase (m ); err != nil {
292
+ log .Printf ("Unable to publish to Firebase: %v" , err .Error ())
293
+ }
294
+ }()
295
+ }
294
296
if cache {
295
297
if err := s .cache .AddMessage (m ); err != nil {
296
298
return err
@@ -306,7 +308,7 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request, _ *visito
306
308
return nil
307
309
}
308
310
309
- func parseHeaders (header http.Header ) (title string , priority int , tags []string , cache bool ) {
311
+ func parseHeaders (header http.Header ) (title string , priority int , tags []string , cache bool , firebase bool ) {
310
312
title = readHeader (header , "x-title" , "title" , "ti" , "t" )
311
313
priorityStr := readHeader (header , "x-priority" , "priority" , "prio" , "p" )
312
314
if priorityStr != "" {
@@ -333,7 +335,8 @@ func parseHeaders(header http.Header) (title string, priority int, tags []string
333
335
}
334
336
}
335
337
cache = readHeader (header , "x-cache" , "cache" ) != "no"
336
- return title , priority , tags , cache
338
+ firebase = readHeader (header , "x-firebase" , "firebase" ) != "no"
339
+ return title , priority , tags , cache , firebase
337
340
}
338
341
339
342
func readHeader (header http.Header , names ... string ) string {
@@ -512,9 +515,6 @@ func (s *Server) topicsFromIDs(ids ...string) ([]*topic, error) {
512
515
return nil , errHTTPTooManyRequests
513
516
}
514
517
s .topics [id ] = newTopic (id )
515
- if s .firebase != nil {
516
- s .topics [id ].Subscribe (s .firebase )
517
- }
518
518
}
519
519
topics = append (topics , s .topics [id ])
520
520
}
@@ -547,7 +547,7 @@ func (s *Server) updateStatsAndExpire() {
547
547
log .Printf ("cannot get stats for topic %s: %s" , t .ID , err .Error ())
548
548
continue
549
549
}
550
- if msgs == 0 && ( subs == 0 || ( s . firebase != nil && subs == 1 )) { // Firebase is a subscriber!
550
+ if msgs == 0 && subs == 0 {
551
551
delete (s .topics , t .ID )
552
552
continue
553
553
}
0 commit comments