8000 Fix `GcmPushkin` to handle app ID globs correctly, introduced in 0.5.0 by squahtx · Pull Request #270 · matrix-org/sygnal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix GcmPushkin to handle app ID globs correctly, introduced in 0.5.0 #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 6, 2021
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/270.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in 0.5.0 where GCM pushes would always fail when configured to handle an app ID glob.
12 changes: 9 additions & 3 deletions sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,19 @@ async def _dispatch_notification_unlimited(
) -> List[str]:
log = NotificationLoggerAdapter(logger, {"request_id": context.request_id})

# `_dispatch_notification_unlimited` gets called once for each device in the
# `Notification` with a matching app ID. We do something a little dirty and
# perform all of our dispatches the first time we get called for a
# `Notification` and do nothing for the rest of the times we get called.
pushkeys = [
device.pushkey for device in n.devices if device.app_id == self.name
device.pushkey for device in n.devices if self.handles_appid(device.app_id)
]
# Resolve canonical IDs for all pushkeys
# `pushkeys` ought to never be empty here. At the very least it should contain
# `device`'s pushkey.

if pushkeys[0] != device.pushkey:
# Only send notifications once, to all devices at once.
# We've already been asked to dispatch for this `Notification` and have
# previously sent out the notification to all devices.
return []

# The pushkey is kind of secret because you can use it to send push
Expand Down
6 changes: 6 additions & 0 deletions sygnal/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import abc
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, TypeVar, overload

from matrix_common.regex import glob_to_regex
from opentracing import Span
from prometheus_client import Counter

Expand Down Expand Up @@ -112,6 +113,7 @@ def __init__(self, notif):
class Pushkin(abc.ABC):
def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]):
self.name = name
self.appid_pattern = glob_to_regex(name, ignore_case=False)
self.cfg = config
self.sygnal = sygnal

Expand All @@ -135,6 +137,10 @@ def get_config(
)
return self.cfg[key]

def handles_appid(self, appid: str) -> bool:
"""Checks whether the pushkin is responsible for the given app ID"""
return self.name == appid or self.appid_pattern.match(appid) is not None

@abc.abstractmethod
async def dispatch_notification(
self, n: Notification, device: Device, context: "NotificationContext"
Expand Down
0