refactor: send notification.
This commit is contained in:
parent
41a8a609be
commit
a64fae7de7
|
@ -13,15 +13,20 @@ func InitWorkers(workerNum int64, queueNum int64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendNotification is send message to iOS or Android
|
||||||
|
func SendNotification(msg PushNotification) {
|
||||||
|
switch msg.Platform {
|
||||||
|
case PlatFormIos:
|
||||||
|
PushToIOS(msg)
|
||||||
|
case PlatFormAndroid:
|
||||||
|
PushToAndroid(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func startWorker() {
|
func startWorker() {
|
||||||
for {
|
for {
|
||||||
notification := <-QueueNotification
|
notification := <-QueueNotification
|
||||||
switch notification.Platform {
|
SendNotification(notification)
|
||||||
case PlatFormIos:
|
|
||||||
PushToIOS(notification)
|
|
||||||
case PlatFormAndroid:
|
|
||||||
PushToAndroid(notification)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,10 @@ func (s *server) Send(ctx context.Context, in *pb.NotificationRequest) (*pb.Noti
|
||||||
APIKey: in.Key,
|
APIKey: in.Key,
|
||||||
}
|
}
|
||||||
|
|
||||||
success := false
|
gorush.SendNotification(notification)
|
||||||
switch notification.Platform {
|
|
||||||
case gorush.PlatFormIos:
|
|
||||||
success = gorush.PushToIOS(notification)
|
|
||||||
case gorush.PlatFormAndroid:
|
|
||||||
success = gorush.PushToAndroid(notification)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pb.NotificationReply{
|
return &pb.NotificationReply{
|
||||||
Success: success,
|
Success: false,
|
||||||
Counts: int32(len(notification.Tokens)),
|
Counts: int32(len(notification.Tokens)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue