Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus committed Jan 17, 2024
1 parent d51334c commit 3360fc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
11 changes: 8 additions & 3 deletions notifications/push/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ type (
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
ImageURL string `json:"imageUrl,omitempty"`
MinDelay uint `json:"minDelay"`
MaxDelay uint `json:"maxDelay"`
}
DelayedNotification struct {
*Notification[SubscriptionTopic]
MinDelay uint `json:"minDelay"`
MaxDelay uint `json:"maxDelay"`
}
Client interface {
io.Closer

Send(context.Context, *Notification[DeviceToken], chan<- error)
Broadcast(context.Context, *Notification[SubscriptionTopic]) error
BroadcastDelayed(context.Context, *DelayedNotification) error
}
)

Expand All @@ -52,12 +56,13 @@ const (

dataOnlyTitle = "title"
dataOnlyBody = "body"
dataOnlyImageURL = "imageURL"
dataOnlyImageURL = "imageUrl"
dataOnlyMinDelay = "minDelaySec"
dataOnlyMaxDelay = "maxDelaySec"
dataOnlyType = "type"

typeDelayedNotification = "delayed"
priorityHigh = "high"
)

type (
Expand Down
24 changes: 20 additions & 4 deletions notifications/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ func (p *push) Send(ctx context.Context, notif *Notification[DeviceToken], respo
}

func (p *push) Broadcast(ctx context.Context, notification *Notification[SubscriptionTopic]) error {
return errors.Wrapf(retry(ctx, func() error {
_, err := p.client.Send(ctx, &fcm.Message{
Data: notification.Data,
Notification: &fcm.Notification{
Title: notification.Title,
Body: notification.Body,
ImageURL: notification.ImageURL,
},
Topic: string(notification.Target),
})

return err //nolint:wrapcheck // No need to do that, it's wrapped outside.
}), "[%v] permanently failed to broadcast %#v", p.applicationYAMLKey, notification)
}

func (p *push) BroadcastDelayed(ctx context.Context, notification *DelayedNotification) error {
return errors.Wrapf(retry(ctx, func() error {
_, err := p.client.Send(ctx, &fcm.Message{
Data: notification.Data,
Expand All @@ -132,10 +148,10 @@ func (p *push) Broadcast(ctx context.Context, notification *Notification[Subscri
})

return err //nolint:wrapcheck // No need to do that, it's wrapped outside.
}), "[%v] permanently failed to broadcast %#v", p.applicationYAMLKey, notification)
}), "[%v] permanently failed to broadcast delayed notification %#v", p.applicationYAMLKey, notification)
}

func buildAndroidDataOnlyNotification(notification *Notification[SubscriptionTopic]) *fcm.AndroidConfig {
func buildAndroidDataOnlyNotification(notification *DelayedNotification) *fcm.AndroidConfig {
dataOnlyNotification := make(map[string]string, len(notification.Data)+3)
for k, v := range notification.Data {
dataOnlyNotification[k] = v
Expand All @@ -149,11 +165,11 @@ func buildAndroidDataOnlyNotification(notification *Notification[SubscriptionTop

return &fcm.AndroidConfig{
Data: dataOnlyNotification,
Priority: "high",
Priority: priorityHigh,
}
}

func buildAppleNotification(notification *Notification[SubscriptionTopic]) *fcm.APNSConfig {
func buildAppleNotification(notification *DelayedNotification) *fcm.APNSConfig {
return &fcm.APNSConfig{
Payload: &fcm.APNSPayload{
Aps: &fcm.Aps{
Expand Down

0 comments on commit 3360fc3

Please sign in to comment.