mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-24 20:57:43 +00:00
sandbox and production clients
This commit is contained in:
parent
989a04da3b
commit
6bd4981201
1 changed files with 11 additions and 6 deletions
|
@ -43,7 +43,8 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, st
|
||||||
log.Fatal("token error:", err)
|
log.Fatal("token error:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := apns2.NewTokenClient(token)
|
sandboxClient := apns2.NewTokenClient(token)
|
||||||
|
productionClient := apns2.NewTokenClient(token).Production()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -116,9 +117,8 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, st
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
devices := []string{}
|
|
||||||
query = `
|
query = `
|
||||||
SELECT apns_token FROM devices
|
SELECT apns_token, sandbox FROM devices
|
||||||
LEFT JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
LEFT JOIN devices_accounts ON devices.id = devices_accounts.device_id
|
||||||
WHERE devices_accounts.account_id = $1`
|
WHERE devices_accounts.account_id = $1`
|
||||||
|
|
||||||
|
@ -128,18 +128,23 @@ func accountWorker(id int, rc *reddit.Client, db *sql.DB, logger *log.Logger, st
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
|
devices := []data.Device{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var device string
|
device := data.Device{}
|
||||||
rows.Scan(&device)
|
rows.Scan(&device.APNSToken, &device.Sandbox)
|
||||||
devices = append(devices, device)
|
devices = append(devices, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range msgs.MessageListing.Messages {
|
for _, msg := range msgs.MessageListing.Messages {
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
notification := &apns2.Notification{}
|
notification := &apns2.Notification{}
|
||||||
notification.DeviceToken = device
|
notification.DeviceToken = device.APNSToken
|
||||||
notification.Topic = "com.christianselig.Apollo"
|
notification.Topic = "com.christianselig.Apollo"
|
||||||
notification.Payload = payload.NewPayload().AlertTitle(msg.Subject).AlertBody(msg.Body)
|
notification.Payload = payload.NewPayload().AlertTitle(msg.Subject).AlertBody(msg.Body)
|
||||||
|
client := productionClient
|
||||||
|
if device.Sandbox {
|
||||||
|
client = sandboxClient
|
||||||
|
}
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
res, err := client.Push(notification)
|
res, err := client.Push(notification)
|
||||||
t2 := time.Now()
|
t2 := time.Now()
|
||||||
|
|
Loading…
Reference in a new issue