Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7765.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Send push notifications with a high or low priority depending upon whether they may generate user-observable effects.
17 changes: 14 additions & 3 deletions synapse/push/httppusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from twisted.internet import defer
from twisted.internet.error import AlreadyCalled, AlreadyCancelled

from synapse.api.constants import EventTypes
from synapse.logging import opentracing
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.push import PusherConfigException
Expand Down Expand Up @@ -305,12 +306,23 @@ def _process_one(self, push_action):

@defer.inlineCallbacks
def _build_notification_dict(self, event, tweaks, badge):
priority = "low"
if (
event.type == EventTypes.Encrypted
or tweaks.get("highlight")
or tweaks.get("sound")
):
# HACK send our push as high priority only if it generates a sound, highlight
# or may do so (i.e. is encrypted so has unknown effects).
priority = "high"

if self.data.get("format") == "event_id_only":
d = {
"notification": {
"event_id": event.event_id,
"room_id": event.room_id,
"counts": {"unread": badge},
"prio": priority,
"devices": [
{
"app_id": self.app_id,
Expand All @@ -334,9 +346,8 @@ def _build_notification_dict(self, event, tweaks, badge):
"room_id": event.room_id,
"type": event.type,
"sender": event.user_id,
"counts": { # -- we don't mark messages as read yet so
# we have no way of knowing
# Just set the badge to 1 until we have read receipts
"prio": priority,
"counts": {
"unread": badge,
# 'missed_calls': 2
},
Expand Down
Loading