Skip to content

Commit

Permalink
style: refactor notification handling and documentation
Browse files Browse the repository at this point in the history
- Update Apple documentation reference link in `PushNotification` struct
- Rename variables in `TestIOSAlertNotificationStructure` for consistency with camelCase convention
- Remove unnecessary blank lines in `notification_fcm.go`

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Sep 17, 2024
1 parent 3c3a5d3 commit 8122319
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion notify/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type PushNotification struct {
InterruptionLevel string `json:"interruption_level,omitempty"`

// live-activity support
// ref: https://developer.apple.com/documentation/activitykit/updating-and-ending-your-live-activity-with-activitykit-push-notifications
// ref: https://apple.co/3MLe2DB
ContentState D `json:"content-state,omitempty"`
StaleDate int64 `json:"stale-date,omitempty"`
DismissalDate int64 `json:"dismissal-date"`
Expand Down
18 changes: 9 additions & 9 deletions notify/notification_apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,10 @@ func TestMessageAndTitle(t *testing.T) {
func TestIOSAlertNotificationStructure(t *testing.T) {
var dat map[string]interface{}
unix := time.Now().Unix()
stale_date := time.Now().Unix()
dismissal_date := stale_date + 5
staleDate := time.Now().Unix()
dismissalDate := staleDate + 5
timeStamp := time.Now().Unix()
itemId := float64(12345)
itemID := float64(12345)

req := &PushNotification{
Message: "Welcome",
Expand All @@ -534,12 +534,12 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
TitleLocKey: testMessage,
},
InterruptionLevel: testMessage,
StaleDate: stale_date,
DismissalDate: dismissal_date,
StaleDate: staleDate,
DismissalDate: dismissalDate,
Event: testMessage,
Timestamp: timeStamp,
ContentState: D{
"item_id": itemId,
"item_id": itemID,
"item_name": testMessage,
},
}
Expand All @@ -563,15 +563,15 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
subtitle, _ := jsonparser.GetString(data, "aps", "alert", "subtitle")
titleLocKey, _ := jsonparser.GetString(data, "aps", "alert", "title-loc-key")
interruptionLevel, _ := jsonparser.GetString(data, "aps", "interruption-level")
staleDate, _ := jsonparser.GetInt(data, "aps", "stale-date")
staleDate, _ = jsonparser.GetInt(data, "aps", "stale-date")
event, _ := jsonparser.GetString(data, "aps", "event")
timestamp, _ := jsonparser.GetInt(data, "aps", "timestamp")
aps := dat["aps"].(map[string]interface{})
alert := aps["alert"].(map[string]interface{})
titleLocArgs := alert["title-loc-args"].([]interface{})
locArgs := alert["loc-args"].([]interface{})
contentState := aps["content-state"].(map[string]interface{})
contentStateItemId := contentState["item_id"]
contentStateItemID := contentState["item_id"]
contentStateItemName := contentState["item_name"]

assert.Equal(t, testMessage, action)
Expand All @@ -588,7 +588,7 @@ func TestIOSAlertNotificationStructure(t *testing.T) {
assert.Equal(t, unix, timestamp)

// dynamic contentState content
assert.Equal(t, contentStateItemId, itemId)
assert.Equal(t, contentStateItemID, itemID)
assert.Equal(t, contentStateItemName, testMessage)
assert.Contains(t, contentState, "item_id")
assert.Contains(t, contentState, "item_name")
Expand Down
2 changes: 0 additions & 2 deletions notify/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
}
default:
req.APNS.Payload.Aps.Sound = sound

}

if req.Android == nil {
Expand All @@ -139,7 +138,6 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
}
}
}

}

// Check if the notification is a topic
Expand Down

0 comments on commit 8122319

Please sign in to comment.