Skip to content

Commit

Permalink
Merge pull request #61 from planetary-social/tweak-follow-notifications
Browse files Browse the repository at this point in the history
Avoid showing npubs, use thread_id, passive interruptions
  • Loading branch information
dcadenas authored Aug 27, 2024
2 parents 944d0bc + ecf94d0 commit 8738b57
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions service/adapters/apns/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apns

import (
"encoding/json"
"strings"
"time"

"github.com/boreq/errors"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8738b57

Please sign in to comment.