From 5ccc9f344d2813c67b03f9b78090422e1ffbf773 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 5 Jul 2022 10:55:58 +0100 Subject: [PATCH] Add TTL support for FCM notifications --- sygnal/gcmpushkin.py | 3 +++ sygnal/notifications.py | 1 + 2 files changed, 4 insertions(+) diff --git a/sygnal/gcmpushkin.py b/sygnal/gcmpushkin.py index 955f8d0f..c5979e03 100644 --- a/sygnal/gcmpushkin.py +++ b/sygnal/gcmpushkin.py @@ -366,6 +366,9 @@ async def _dispatch_notification_unlimited( body["data"] = data body["priority"] = "normal" if n.prio == "low" else "high" + if n.ttl is not None: + body["time_to_live"] = n.ttl + for retry_number in range(0, MAX_TRIES): if len(pushkeys) == 1: body["to"] = pushkeys[0] diff --git a/sygnal/notifications.py b/sygnal/notifications.py index 872f6577..99ad8f6c 100644 --- a/sygnal/notifications.py +++ b/sygnal/notifications.py @@ -98,6 +98,7 @@ def __init__(self, notif): self.user_is_target: Optional[bool] = notif.get("user_is_target") self.type: Optional[str] = notif.get("type") self.sender: Optional[str] = notif.get("sender") + self.ttl: Optional[int] = notif.get("ttl") if "devices" not in notif or not isinstance(notif["devices"], list): raise InvalidNotificationException("Expected list in 'devices' key")