mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
push: log number of events in push payloads
This commit is contained in:
parent
6e8dd0e591
commit
23f2699909
1 changed files with 11 additions and 5 deletions
|
@ -157,12 +157,18 @@ func (pn *PushNotification) Split(yield func(*PushNotification) bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gmx *Gomuks) SendPushNotification(ctx context.Context, pushRegs []*database.PushRegistration, notif *PushNotification) {
|
func (gmx *Gomuks) SendPushNotification(ctx context.Context, pushRegs []*database.PushRegistration, notif *PushNotification) {
|
||||||
|
log := zerolog.Ctx(ctx).With().
|
||||||
|
Bool("important", notif.HasImportant).
|
||||||
|
Int("message_count", len(notif.RawMessages)).
|
||||||
|
Int("dismiss_count", len(notif.Dismiss)).
|
||||||
|
Logger()
|
||||||
|
ctx = log.WithContext(ctx)
|
||||||
rawPayload, err := json.Marshal(notif)
|
rawPayload, err := json.Marshal(notif)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Msg("Failed to marshal push notification")
|
log.Err(err).Msg("Failed to marshal push notification")
|
||||||
return
|
return
|
||||||
} else if base64.StdEncoding.EncodedLen(len(rawPayload)) >= 4000 {
|
} else if base64.StdEncoding.EncodedLen(len(rawPayload)) >= 4000 {
|
||||||
zerolog.Ctx(ctx).Error().Msg("Generated push payload too long")
|
log.Error().Msg("Generated push payload too long")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, reg := range pushRegs {
|
for _, reg := range pushRegs {
|
||||||
|
@ -172,7 +178,7 @@ func (gmx *Gomuks) SendPushNotification(ctx context.Context, pushRegs []*databas
|
||||||
var err error
|
var err error
|
||||||
devicePayload, err = encryptPush(rawPayload, reg.Encryption.Key)
|
devicePayload, err = encryptPush(rawPayload, reg.Encryption.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Str("device_id", reg.DeviceID).Msg("Failed to encrypt push payload")
|
log.Err(err).Str("device_id", reg.DeviceID).Msg("Failed to encrypt push payload")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
encrypted = true
|
encrypted = true
|
||||||
|
@ -180,7 +186,7 @@ func (gmx *Gomuks) SendPushNotification(ctx context.Context, pushRegs []*databas
|
||||||
switch reg.Type {
|
switch reg.Type {
|
||||||
case database.PushTypeFCM:
|
case database.PushTypeFCM:
|
||||||
if !encrypted {
|
if !encrypted {
|
||||||
zerolog.Ctx(ctx).Warn().
|
log.Warn().
|
||||||
Str("device_id", reg.DeviceID).
|
Str("device_id", reg.DeviceID).
|
||||||
Msg("FCM push registration doesn't have encryption key")
|
Msg("FCM push registration doesn't have encryption key")
|
||||||
continue
|
continue
|
||||||
|
@ -188,7 +194,7 @@ func (gmx *Gomuks) SendPushNotification(ctx context.Context, pushRegs []*databas
|
||||||
var token string
|
var token string
|
||||||
err = json.Unmarshal(reg.Data, &token)
|
err = json.Unmarshal(reg.Data, &token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(ctx).Err(err).Str("device_id", reg.DeviceID).Msg("Failed to unmarshal FCM token")
|
log.Err(err).Str("device_id", reg.DeviceID).Msg("Failed to unmarshal FCM token")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
gmx.SendFCMPush(ctx, token, devicePayload, notif.HasImportant)
|
gmx.SendFCMPush(ctx, token, devicePayload, notif.HasImportant)
|
||||||
|
|
Loading…
Add table
Reference in a new issue