Skip to content

Commit

Permalink
Push Payload Changes (#114)
Browse files Browse the repository at this point in the history
Change content-available to mutable-content and also add event_id in payload if provided. This is intended to enable modifying push notification content on the client side (iOS). For details:
  • Loading branch information
ismailgulek authored May 7, 2020
1 parent b4ce6e2 commit 9a1e3c8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/114.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change aps payload to be mutable, include event_id in payload.
4 changes: 3 additions & 1 deletion sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _get_payload_full(self, n, log):
aps["badge"] = badge

if loc_key:
aps["content-available"] = 1
aps["mutable-content"] = 1

if loc_key is None and badge is None:
log.info("Nothing to do for alert of type %s", n.type)
Expand All @@ -436,6 +436,8 @@ def _get_payload_full(self, n, log):

if loc_key and n.room_id:
payload["room_id"] = n.room_id
if loc_key and n.event_id:
payload["event_id"] = n.event_id

payload["aps"] = aps

Expand Down
7 changes: 4 additions & 3 deletions tests/test_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_payload_truncation(self):
method.return_value = testutils.make_async_magic_mock(
NotificationResult("notID", "200")
)
self.sygnal.pushkins[PUSHKIN_ID].MAX_JSON_BODY_SIZE = 200
self.sygnal.pushkins[PUSHKIN_ID].MAX_JSON_BODY_SIZE = 240

# Act
self._request(self._make_dummy_notification([DEVICE_EXAMPLE]))
Expand All @@ -67,7 +67,7 @@ def test_payload_truncation(self):
((notification_req,), _kwargs) = method.call_args
payload = notification_req.message

self.assertLessEqual(len(apnstruncate.json_encode(payload)), 200)
self.assertLessEqual(len(apnstruncate.json_encode(payload)), 240)

def test_payload_truncation_test_validity(self):
"""
Expand Down Expand Up @@ -113,6 +113,7 @@ def test_expected(self):
self.assertEqual(
{
"room_id": "!slw48wfj34rtnrf:example.com",
"event_id": "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs",
"aps": {
"alert": {
"loc-key": "MSG_FROM_USER_IN_ROOM_WITH_CONTENT",
Expand All @@ -123,7 +124,7 @@ def test_expected(self):
],
},
"badge": 3,
"content-available": 1,
"mutable-content": 1,
},
},
notification_req.message,
Expand Down
1 change: 1 addition & 0 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def _make_dummy_notification(self, devices):
"notification": {
"id": "$3957tyerfgewrf384",
"room_id": "!slw48wfj34rtnrf:example.com",
"event_id": "$qTOWWTEL48yPm3uT-gdNhFcoHxfKbZuqRVnnWWSkGBs",
"type": "m.room.message",
"sender": "@exampleuser:matrix.org",
"sender_display_name": "Major Tom",
Expand Down

0 comments on commit 9a1e3c8

Please sign in to comment.