Skip to content

Commit

Permalink
Merge pull request #69 from planetary-social/remove-passive-notificat…
Browse files Browse the repository at this point in the history
…ions

Remove passive interruption level and leave default
  • Loading branch information
dcadenas authored Sep 24, 2024
2 parents 207c4b9 + 66b0261 commit ddb885b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
9 changes: 4 additions & 5 deletions service/adapters/apns/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ func FollowChangePayloadWithValidation(followChange domain.FollowChangeBatch, va

payload := map[string]interface{}{
"aps": map[string]interface{}{
"alert": alertObject,
"sound": "default",
"badge": 1,
"thread-id": followeeNpub,
"interruption-level": "passive",
"alert": alertObject,
"sound": "default",
"badge": 1,
"thread-id": followeeNpub,
},
"data": data,
}
Expand Down
48 changes: 23 additions & 25 deletions service/adapters/apns/apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ func TestFollowChangePayload_SingleFollow(t *testing.T) {

expectedPayload := map[string]interface{}{
"aps": map[string]interface{}{
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
"interruption-level": "passive",
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
},
"data": map[string]interface{}{
"follows": []interface{}{pk2Npub}, // Use []interface{}
Expand Down Expand Up @@ -70,11 +69,10 @@ func TestFollowChangePayload_MultipleFollowsUnfollows(t *testing.T) {

expectedPayload := map[string]interface{}{
"aps": map[string]interface{}{
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
"interruption-level": "passive",
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
},
"data": map[string]interface{}{
"follows": []interface{}{pk2Npub, pk3Npub}, // Use []interface{}
Expand Down Expand Up @@ -108,11 +106,10 @@ func TestFollowChangePayload_SingleFollow_WithFriendlyFollower(t *testing.T) {

expectedPayload := map[string]interface{}{
"aps": map[string]interface{}{
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
"interruption-level": "passive",
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
},
"data": map[string]interface{}{
"follows": []interface{}{pk2Npub}, // Use []interface{}
Expand Down Expand Up @@ -154,11 +151,10 @@ func TestFollowChangePayload_BatchedFollow_WithNoFriendlyFollower(t *testing.T)

expectedPayload := map[string]interface{}{
"aps": map[string]interface{}{
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
"interruption-level": "passive",
"alert": expectedAlert,
"sound": "default",
"badge": float64(1), // Convert badge to float64
"thread-id": pk1Npub,
},
"data": map[string]interface{}{
"follows": []interface{}{pk2Npub, pk3Npub}, // Use []interface{}
Expand All @@ -178,7 +174,7 @@ func TestFollowChangePayload_BatchedFollow_WithNoFriendlyFollower(t *testing.T)

require.Equal(t, expectedPayload, actualPayload)
}
func TestFollowChangePayload_Exceeds4096Bytes_With59TotalNpubs(t *testing.T) {
func TestFollowChangePayload_Exceeds4096Bytes_With60TotalNpubs(t *testing.T) {
pk1, _ := fixtures.PublicKeyAndNpub()

batch := domain.FollowChangeBatch{
Expand All @@ -187,17 +183,17 @@ func TestFollowChangePayload_Exceeds4096Bytes_With59TotalNpubs(t *testing.T) {
Follows: []domain.PublicKey{},
}

for i := 0; i < 59; i++ {
for i := 0; i < 60; i++ {
follow, _ := fixtures.PublicKeyAndNpub()
batch.Follows = append(batch.Follows, follow)
}

payload, err := apns.FollowChangePayloadWithValidation(batch, false)
require.NoError(t, err)

// Ensure 59 is the maximum size we can get
// 60 pubkeys should exceed 4096 bytes.
payloadSize := len(payload)
t.Logf("Payload size with 59 total follows and unfollows: %d bytes", payloadSize)
t.Logf("Payload size with 60 total follows and unfollows: %d bytes", payloadSize)
require.True(t, payloadSize > 4096, fmt.Sprintf("Payload size should exceed 4096 bytes, but was %d bytes", payloadSize))
}

Expand All @@ -218,7 +214,9 @@ func TestFollowChangePayload_ValidPayload_With58TotalNpubs_IsValid(t *testing.T)
payload, err := apns.FollowChangePayloadWithValidation(batch, true) // With validation
require.NoError(t, err)

// Ensure 58 is the maximum size we can get
// Ensure 58 is the maximum size we can get. 59 is in fact also fitting in
// 4096 but let's leave some padding for future addition of payload fields
// and have room for variability.
payloadSize := len(payload)
t.Logf("Payload size with 58 total follows and unfollows: %d bytes", payloadSize)
require.True(t, payloadSize <= 4096, fmt.Sprintf("Payload size should be within 4096 bytes, but was %d bytes", payloadSize))
Expand Down

0 comments on commit ddb885b

Please sign in to comment.