@@ -111,7 +111,6 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig):
111
111
self .device_display_name = pusher_config .device_display_name
112
112
self .device_id = pusher_config .device_id
113
113
self .pushkey_ts = pusher_config .ts
114
- self .data = pusher_config .data
115
114
self .backoff_delay = HttpPusher .INITIAL_BACKOFF_SEC
116
115
self .failing_since = pusher_config .failing_since
117
116
self .timed_call : Optional [IDelayedCall ] = None
@@ -123,9 +122,9 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig):
123
122
124
123
self .push_jitter_delay_ms = hs .config .push .push_jitter_delay_ms
125
124
126
- self .data = pusher_config .data
127
- if self .data is None :
125
+ if pusher_config .data is None :
128
126
raise PusherConfigException ("'data' key can not be null for HTTP pusher" )
127
+ self .data = pusher_config .data
129
128
130
129
# Check if badge counts should be disabled for this push gateway
131
130
self .disable_badge_count = self .hs .config .experimental .msc4076_enabled and bool (
@@ -138,26 +137,29 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig):
138
137
pusher_config .pushkey ,
139
138
)
140
139
141
- # Validate that there's a URL and it is of the proper form.
142
- if "url" not in self .data :
143
- raise PusherConfigException ("'url' required in data for HTTP pusher" )
144
-
145
- url = self .data ["url" ]
146
- if not isinstance (url , str ):
147
- raise PusherConfigException ("'url' must be a string" )
148
- url_parts = urllib .parse .urlparse (url )
149
- # Note that the specification also says the scheme must be HTTPS, but
150
- # it isn't up to the homeserver to verify that.
151
- if url_parts .path != "/_matrix/push/v1/notify" :
152
- raise PusherConfigException (
153
- "'url' must have a path of '/_matrix/push/v1/notify'"
154
- )
140
+ self .url = ""
141
+ if pusher_config .kind == "http" :
142
+ # Validate that there's a URL and it is of the proper form.
143
+ if "url" not in self .data :
144
+ raise PusherConfigException ("'url' required in data for HTTP pusher" )
145
+
146
+ url = self .data ["url" ]
147
+ if not isinstance (url , str ):
148
+ raise PusherConfigException ("'url' must be a string" )
149
+ url_parts = urllib .parse .urlparse (url )
150
+ # Note that the specification also says the scheme must be HTTPS, but
151
+ # it isn't up to the homeserver to verify that.
152
+ if url_parts .path != "/_matrix/push/v1/notify" :
153
+ raise PusherConfigException (
154
+ "'url' must have a path of '/_matrix/push/v1/notify'"
155
+ )
156
+ self .url = url
157
+
158
+ self .data_minus_url = {}
159
+ self .data_minus_url .update (self .data )
160
+ del self .data_minus_url ["url" ]
155
161
156
- self .url = url
157
162
self .http_client = hs .get_proxied_blocklisted_http_client ()
158
- self .data_minus_url = {}
159
- self .data_minus_url .update (self .data )
160
- del self .data_minus_url ["url" ]
161
163
self .badge_count_last_call : Optional [int ] = None
162
164
163
165
def on_started (self , should_check_for_notifs : bool ) -> None :
@@ -188,7 +190,10 @@ async def _update_badge(self) -> None:
188
190
)
189
191
if self .badge_count_last_call is None or self .badge_count_last_call != badge :
190
192
self .badge_count_last_call = badge
191
- await self ._send_badge (badge )
193
+ if await self .send_badge (badge ):
194
+ http_badges_processed_counter .inc ()
195
+ else :
196
+ http_badges_failed_counter .inc ()
192
197
193
198
def on_timer (self ) -> None :
194
199
self ._start_processing ()
@@ -510,7 +515,7 @@ async def dispatch_push_event(
510
515
511
516
return res
512
517
513
- async def _send_badge (self , badge : int ) -> None :
518
+ async def send_badge (self , badge : int ) -> bool :
514
519
"""
515
520
Args:
516
521
badge: number of unread messages
@@ -534,9 +539,9 @@ async def _send_badge(self, badge: int) -> None:
534
539
}
535
540
try :
536
541
await self .http_client .post_json_get_json (self .url , d )
537
- http_badges_processed_counter . inc ()
542
+ return True
538
543
except Exception as e :
539
544
logger .warning (
540
545
"Failed to send badge count to %s: %s %s" , self .name , type (e ), e
541
546
)
542
- http_badges_failed_counter . inc ()
547
+ return False
0 commit comments