From ecf94d06f9b3957f2650c08ebebf6d973e396338 Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Tue, 27 Aug 2024 10:03:38 -0300 Subject: [PATCH] Avoid showing npubs, use thread_id, passive interruptions --- service/adapters/apns/apns.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/service/adapters/apns/apns.go b/service/adapters/apns/apns.go index 8833b27..e580d65 100644 --- a/service/adapters/apns/apns.go +++ b/service/adapters/apns/apns.go @@ -2,6 +2,7 @@ package apns import ( "encoding/json" + "strings" "time" "github.com/boreq/errors" @@ -132,17 +133,28 @@ func (a *APNS) buildFollowChangeNotification(followChange domain.FollowChange, a func followChangePayload(followChange domain.FollowChange) ([]byte, error) { alertMessage := "" - if followChange.ChangeType == "unfollowed" { - alertMessage = followChange.FriendlyFollower + " has unfollowed you!" + if strings.HasPrefix(followChange.FriendlyFollowee, "npub") { + if followChange.ChangeType == "unfollowed" { + alertMessage = "You've been unfollowed!" + } else { + alertMessage = "You have a new follower!" + } } else { - alertMessage = followChange.FriendlyFollower + " is a new follower!" + if followChange.ChangeType == "unfollowed" { + alertMessage = followChange.FriendlyFollower + " has unfollowed you!" + } else { + alertMessage = followChange.FriendlyFollower + " is a new follower!" + } } + // See https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification payload := map[string]interface{}{ "aps": map[string]interface{}{ - "alert": alertMessage, - "sound": "default", - "badge": 1, + "alert": alertMessage, + "sound": "default", + "badge": 1, + "thread-id": followChange.Followee.Hex(), + "interruption-level": "passive", }, "data": map[string]interface{}{ "changeType": followChange.ChangeType,