def __init__(self, hs, pusherdict): self.hs = hs self.store = self.hs.get_datastore() self.clock = self.hs.get_clock() self.state_handler = self.hs.get_state_handler() self.user_id = pusherdict['user_name'] self.app_id = pusherdict['app_id'] self.app_display_name = pusherdict['app_display_name'] self.device_display_name = pusherdict['device_display_name'] self.pushkey = pusherdict['pushkey'] self.pushkey_ts = pusherdict['ts'] self.data = pusherdict['data'] self.last_stream_ordering = pusherdict['last_stream_ordering'] self.backoff_delay = HttpPusher.INITIAL_BACKOFF_SEC self.failing_since = pusherdict['failing_since'] self.timed_call = None self._is_processing = False # This is the highest stream ordering we know it's safe to process. # When new events arrive, we'll be given a window of new events: we # should honour this rather than just looking for anything higher # because of potential out-of-order event serialisation. This starts # off as None though as we don't know any better. self.max_stream_ordering = None if 'data' not in pusherdict: raise PusherConfigException( "No 'data' key for HTTP pusher" ) self.data = pusherdict['data'] self.name = "%s/%s/%s" % ( pusherdict['user_name'], pusherdict['app_id'], pusherdict['pushkey'], ) if self.data is None: raise PusherConfigException( "data can not be null for HTTP pusher" ) if 'url' not in self.data: raise PusherConfigException( "'url' required in data for HTTP pusher" ) self.url = self.data['url'] self.http_client = hs.get_simple_http_client() self.data_minus_url = {} self.data_minus_url.update(self.data) del self.data_minus_url['url']
def __init__(self, hs: "HomeServer", pusher_config: PusherConfig): super().__init__(hs, pusher_config) self._storage_controllers = self.hs.get_storage_controllers() self.app_display_name = pusher_config.app_display_name self.device_display_name = pusher_config.device_display_name self.pushkey_ts = pusher_config.ts self.data = pusher_config.data self.backoff_delay = HttpPusher.INITIAL_BACKOFF_SEC self.failing_since = pusher_config.failing_since self.timed_call: Optional[IDelayedCall] = None self._is_processing = False self._group_unread_count_by_room = ( hs.config.push.push_group_unread_count_by_room) self._pusherpool = hs.get_pusherpool() self.data = pusher_config.data if self.data is None: raise PusherConfigException( "'data' key can not be null for HTTP pusher") self.name = "%s/%s/%s" % ( pusher_config.user_name, pusher_config.app_id, pusher_config.pushkey, ) # Validate that there's a URL and it is of the proper form. if "url" not in self.data: raise PusherConfigException( "'url' required in data for HTTP pusher") url = self.data["url"] if not isinstance(url, str): raise PusherConfigException("'url' must be a string") url_parts = urllib.parse.urlparse(url) # Note that the specification also says the scheme must be HTTPS, but # it isn't up to the homeserver to verify that. if url_parts.path != "/_matrix/push/v1/notify": raise PusherConfigException( "'url' must have a path of '/_matrix/push/v1/notify'") self.url = url self.http_client = hs.get_proxied_blacklisted_http_client() self.data_minus_url = {} self.data_minus_url.update(self.data) del self.data_minus_url["url"] self.badge_count_last_call: Optional[int] = None
def __init__(self, _hs, user_id, app_id, app_display_name, device_display_name, pushkey, pushkey_ts, data, last_token, last_success, failing_since): super(HttpPusher, self).__init__(_hs, user_id, app_id, app_display_name, device_display_name, pushkey, pushkey_ts, data, last_token, last_success, failing_since) if 'url' not in data: raise PusherConfigException( "'url' required in data for HTTP pusher") self.url = data['url'] self.http_client = _hs.get_simple_http_client() self.data_minus_url = {} self.data_minus_url.update(self.data) del self.data_minus_url['url']
def __init__(self, hs: "HomeServer", pusher_config: PusherConfig, mailer: Mailer): super().__init__(hs, pusher_config) self.mailer = mailer self.store = self.hs.get_datastore() self.email = pusher_config.pushkey self.timed_call: Optional[IDelayedCall] = None self.throttle_params: Dict[str, ThrottleParams] = {} self._inited = False self._is_processing = False # Make sure that the email is valid. try: validate_email(self.email) except ValueError: raise PusherConfigException("Invalid email")
def _create_pusher(self, pusherdict): if pusherdict['kind'] == 'http': return HttpPusher( self.hs, user_id=pusherdict['user_name'], app_id=pusherdict['app_id'], app_display_name=pusherdict['app_display_name'], device_display_name=pusherdict['device_display_name'], pushkey=pusherdict['pushkey'], pushkey_ts=pusherdict['ts'], data=pusherdict['data'], last_token=pusherdict['last_token'], last_success=pusherdict['last_success'], failing_since=pusherdict['failing_since']) else: raise PusherConfigException( "Unknown pusher type '%s' for user %s" % (pusherdict['kind'], pusherdict['user_name']))