Skip to content

Commit

Permalink
Each notification renders its own display message
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Jan 11, 2024
1 parent 0c9d52b commit c2bddf2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 5 additions & 3 deletions breezsdk/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ func createMessageFactory() services.FCMMessageBuilder {
notify.NOTIFICATION_ADDRESS_TXS_CHANGED,
notify.NOTIFICATION_WEBHOOK_CALLBACK:

return createSilentPush(notification)
return createPush(notification)
}

return nil, nil
}
}

func createSilentPush(notification *notify.Notification) (*messaging.Message, error) {
func createPush(notification *notify.Notification) (*messaging.Message, error) {
data := notification.Data
data["notification_type"] = notification.Template

return &messaging.Message{
Token: notification.TargetIdentifier,
Data: data,
Expand All @@ -47,6 +46,9 @@ func createSilentPush(notification *notify.Notification) (*messaging.Message, er
},
Payload: &messaging.APNSPayload{
Aps: &messaging.Aps{
Alert: &messaging.ApsAlert{
Title: notification.DisplayMessage,
},
ContentAvailable: false,
MutableContent: true,
},
Expand Down
24 changes: 21 additions & 3 deletions http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type NotificationConvertible interface {
}

type WebhookCallbackMessagePayload struct {
Template string `json:"template" binding:"required,eq=webhook_callback_message"`
Data struct {
Template string `json:"template" binding:"required,eq=webhook_callback_message"`
MessageType string `json:"message_type" binding:"required"`
Data struct {
CallbackURL string `json:"callback_url" binding:"required"`
MessagePayload string `json:"message_payload"`
} `json:"data"`
Expand All @@ -33,10 +34,24 @@ type WebhookCallbackMessagePayload struct {
func (p *WebhookCallbackMessagePayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification {
return &notify.Notification{
Template: p.Template,
DisplayMessage: p.GenerateDisplayMessage(),
Type: query.Platform,
TargetIdentifier: query.Token,
Data: map[string]string{"callback_url": p.Data.CallbackURL, "message_payload": p.Data.MessagePayload},
Data: map[string]string{
"callback_url": p.Data.CallbackURL,
"message_payload": p.Data.MessagePayload,
},
}
}

func (p *WebhookCallbackMessagePayload) GenerateDisplayMessage() string {
switch p.MessageType {
case "lnulrpay_info":
return "Receiving payment"
case "lnurlpay_invoice":
return "Invoice requested"
}
return ""
}

type PaymentReceivedPayload struct {
Expand All @@ -49,6 +64,7 @@ type PaymentReceivedPayload struct {
func (p *PaymentReceivedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification {
return &notify.Notification{
Template: p.Template,
DisplayMessage: "Incoming payment",
Type: query.Platform,
TargetIdentifier: query.Token,
Data: map[string]string{"payment_hash": p.Data.PaymentHash},
Expand All @@ -65,6 +81,7 @@ type TxConfirmedPayload struct {
func (p *TxConfirmedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification {
return &notify.Notification{
Template: p.Template,
DisplayMessage: "Transaction confirmed",
Type: query.Platform,
TargetIdentifier: query.Token,
Data: map[string]string{"tx_id": p.Data.TxID},
Expand All @@ -81,6 +98,7 @@ type AddressTxsChangedPayload struct {
func (p *AddressTxsChangedPayload) ToNotification(query *MobilePushWebHookQuery) *notify.Notification {
return &notify.Notification{
Template: p.Template,
DisplayMessage: "Address transactions changed",
Type: query.Platform,
TargetIdentifier: query.Token,
Data: map[string]string{"address": p.Data.Address},
Expand Down
1 change: 1 addition & 0 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (

type Notification struct {
Template string
DisplayMessage string
Type string
TargetIdentifier string
Data map[string]string
Expand Down

0 comments on commit c2bddf2

Please sign in to comment.