コード例 #1
0
 def send_match_video(cls, match):
     """
     Sends match_video and event_match_video notifications
     If the match is current, MatchVideoNotification is sent.
     Otherwise, EventMatchVideoNotification is sent
     """
     match_users = set(PushHelper.get_users_subscribed_to_match(match, NotificationType.MATCH_VIDEO))
     event_users = set(PushHelper.get_users_subscribed_to_event(match.event.get(), NotificationType.MATCH_VIDEO))
     users = match_users.union(event_users)
     if match.within_seconds(60*10):
         user_keys = PushHelper.get_client_ids_for_users(users)
         MatchVideoNotification(match).send(user_keys)
     else:
         user_keys = PushHelper.get_client_ids_for_users(users)
         EventMatchVideoNotification(match).send(user_keys)
コード例 #2
0
    def send_upcoming_match_notification(cls, match, event):
        users = PushHelper.get_users_subscribed_to_match(match, NotificationType.UPCOMING_MATCH)
        keys = PushHelper.get_client_ids_for_users(users)

        if match.set_number == 1 and match.match_number == 1:
            # First match of a new type, send level starting notifications
            start_users = PushHelper.get_users_subscribed_to_match(match, NotificationType.LEVEL_STARTING)
            start_keys = PushHelper.get_client_ids_for_users(start_users)
            level_start = CompLevelStartingNotification(match, event)
            level_start.send(start_keys)

        # Send upcoming match notification
        notification = UpcomingMatchNotification(match, event)
        notification.send(keys)
        match.push_sent = True  # Make sure we don't send updates for this match again
        match.put()
コード例 #3
0
    def send_schedule_update(cls, event):
        users = Subscription.users_subscribed_to_event(
            event, NotificationType.SCHEDULE_UPDATED)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = ScheduleUpdatedNotification(event)
        notification.send(keys)
コード例 #4
0
    def send_award_update(cls, event):
        users = PushHelper.get_users_subscribed_to_event(
            event, NotificationType.AWARDS)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = AwardsUpdatedNotification(event)
        notification.send(keys)
コード例 #5
0
    def send_match_score_update(cls, match):
        users = PushHelper.get_users_subscribed_to_match(
            match, NotificationType.MATCH_SCORE)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = MatchScoreNotification(match)
        notification.send(keys)
コード例 #6
0
    def send_subscription_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users(
            [user_id], os_types=[ClientType.OS_ANDROID])

        notification = UpdateSubscriptionsNotification(user_id,
                                                       sending_device_key)
        notification.send(clients)
コード例 #7
0
    def send_alliance_update(cls, event):
        users = PushHelper.get_users_subscribed_for_alliances(
            event, NotificationType.ALLIANCE_SELECTION)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = AllianceSelectionNotification(event)
        notification.send(keys)
コード例 #8
0
    def send_award_update(cls, event):
        users = Subscription.users_subscribed_to_event(event,
                                                       NotificationType.AWARDS)
        keys = PushHelper.get_client_ids_for_users(
            users, os_types=[ClientType.OS_ANDROID])

        notification = AwardsUpdatedNotification(event)
        notification.send(keys)
コード例 #9
0
    def get(self, type):
        self._require_registration('/account/')
        user_id = self.user_bundle.account.key.id()

        logging.info("Sending for {}".format(type))
        try:
            type = int(type)
        except ValueError:
            # Not passed a valid int, just stop here
            logging.info("Invalid number passed")
            self.redirect('/apidocs/webhooks')
            return

        event = Event.get_by_id('2014necmp')
        match = Match.get_by_id('2014necmp_f1m1')
        district = District.get_by_id('2014ne')

        if type == NotificationType.UPCOMING_MATCH:
            notification = UpcomingMatchNotification(match, event)
        elif type == NotificationType.MATCH_SCORE:
            notification = MatchScoreNotification(match)
        elif type == NotificationType.LEVEL_STARTING:
            notification = CompLevelStartingNotification(match, event)
        elif type == NotificationType.ALLIANCE_SELECTION:
            notification = AllianceSelectionNotification(event)
        elif type == NotificationType.AWARDS:
            notification = AwardsUpdatedNotification(event)
        elif type == NotificationType.MEDIA_POSTED:
            # Not implemented yet
            pass
        elif type == NotificationType.DISTRICT_POINTS_UPDATED:
            notification = DistrictPointsUpdatedNotification(district)
        elif type == NotificationType.SCHEDULE_UPDATED:
            notification = ScheduleUpdatedNotification(event, match)
        elif type == NotificationType.FINAL_RESULTS:
            # Not implemented yet
            pass
        elif type == NotificationType.MATCH_VIDEO:
            notification = MatchVideoNotification(match)
        elif type == NotificationType.EVENT_MATCH_VIDEO:
            notification = EventMatchVideoNotification(match)
        else:
            # Not passed a valid int, return
            self.redirect('/apidocs/webhooks')
            return

        keys = PushHelper.get_client_ids_for_users([user_id])
        logging.info("Keys: {}".format(keys))
        if notification:
            # This page should not push notifications to the firebase queue
            # Nor should its notifications be tracked in analytics
            notification.send(keys, push_firebase=False, track_call=False)

        self.redirect('/apidocs/webhooks')
コード例 #10
0
    def get(self, type):
        self._require_registration('/account/')
        user_id = self.user_bundle.account.key.id()

        logging.info("Sending for {}".format(type))
        try:
            type = int(type)
        except ValueError:
            # Not passed a valid int, just stop here
            logging.info("Invalid number passed")
            self.redirect('/apidocs/webhooks')
            return

        event = Event.get_by_id('2014necmp')
        match = Match.get_by_id('2014necmp_f1m1')
        district = District.get_by_id('2014ne')

        if type == NotificationType.UPCOMING_MATCH:
            notification = UpcomingMatchNotification(match, event)
        elif type == NotificationType.MATCH_SCORE:
            notification = MatchScoreNotification(match)
        elif type == NotificationType.LEVEL_STARTING:
            notification = CompLevelStartingNotification(match, event)
        elif type == NotificationType.ALLIANCE_SELECTION:
            notification = AllianceSelectionNotification(event)
        elif type == NotificationType.AWARDS:
            notification = AwardsUpdatedNotification(event)
        elif type == NotificationType.MEDIA_POSTED:
            # Not implemented yet
            pass
        elif type == NotificationType.DISTRICT_POINTS_UPDATED:
            notification = DistrictPointsUpdatedNotification(district)
        elif type == NotificationType.SCHEDULE_UPDATED:
            notification = ScheduleUpdatedNotification(event, match)
        elif type == NotificationType.FINAL_RESULTS:
            # Not implemented yet
            pass
        elif type == NotificationType.MATCH_VIDEO:
            notification = MatchVideoNotification(match)
        elif type == NotificationType.EVENT_MATCH_VIDEO:
            notification = EventMatchVideoNotification(match)
        else:
            # Not passed a valid int, return
            self.redirect('/apidocs/webhooks')
            return

        keys = PushHelper.get_client_ids_for_users([user_id])
        logging.info("Keys: {}".format(keys))
        if notification:
            # This page should not push notifications to the firebase queue
            # Nor should its notifications be tracked in analytics
            notification.send(keys, push_firebase=False, track_call=False)

        self.redirect('/apidocs/webhooks')
コード例 #11
0
    def send_match_score_update(cls, match):
        users = PushHelper.get_users_subscribed_to_match(match, NotificationType.MATCH_SCORE)
        gcm_keys = PushHelper.get_client_ids_for_users(ClientType.names[ClientType.OS_ANDROID], users)

        if len(gcm_keys) == 0:
            return

        notification = MatchScoreNotification(match)
        message = notification.build(ClientType.OS_ANDROID, {ClientType.OS_ANDROID: gcm_keys})
        gcm_connection = GCMConnection()
        gcm_connection.notify_device(message)
コード例 #12
0
    def send_subscription_update(cls, user_id, sending_device_key):

        clients = PushHelper.get_client_ids_for_users("android", [user_id])
        if sending_device_key in clients:
            clients.remove(sending_device_key)
        if len(clients) == 0:
            return

        notification = UpdateSubscriptionsNotification(user_id)
        message = notification.build(ClientType.OS_ANDROID, {ClientType.OS_ANDROID: clients})
        gcm_connection = GCMConnection()
        gcm_connection.notify_device(message)
コード例 #13
0
    def send_upcoming_match_notification(cls, match, event):
        users = PushHelper.get_users_subscribed_to_match(
            match, NotificationType.UPCOMING_MATCH)
        keys = PushHelper.get_client_ids_for_users(
            users, os_types=[ClientType.OS_ANDROID])

        if match.set_number == 1 and match.match_number == 1:
            # First match of a new type, send level starting notifications
            start_users = PushHelper.get_users_subscribed_to_match(
                match, NotificationType.LEVEL_STARTING)
            start_keys = PushHelper.get_client_ids_for_users(
                start_users, os_types=[ClientType.OS_ANDROID])
            level_start = CompLevelStartingNotification(match, event)
            level_start.send(start_keys)

        # Send upcoming match notification
        notification = UpcomingMatchNotification(match, event)
        notification.send(keys)
        match.push_sent = True  # Make sure we don't send updates for this match again
        match.dirty = True
        from helpers.match_manipulator import MatchManipulator
        MatchManipulator.createOrUpdate(match)
コード例 #14
0
    def broadcast(cls, client_types, title, message, url=None, app_version=None):
        from models.notifications.broadcast import BroadcastNotification
        notification = BroadcastNotification(title, message, url, app_version)

        # Send to FCM clients
        fcm_client_types = [ct for ct in client_types if ct in ClientType.FCM_CLIENTS]
        if fcm_client_types:
            clients = MobileClient.query(MobileClient.client_type.IN(fcm_client_types)).fetch()
            if clients:
                deferred.defer(
                    cls._send_fcm,
                    clients,
                    notification,
                    _queue="push-notifications",
                    _url='/_ah/queue/deferred_notification_send'
                )

        # Send to webhooks
        if ClientType.WEBHOOK in client_types:
            clients = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch()
            if clients:
                deferred.defer(
                    cls._send_webhook,
                    clients,
                    notification,
                    _queue="push-notifications",
                    _url='/_ah/queue/deferred_notification_send'
                )

        if ClientType.OS_ANDROID in client_types:
            from helpers.push_helper import PushHelper
            users = PushHelper.get_all_mobile_clients([ClientType.OS_ANDROID])
            keys = PushHelper.get_client_ids_for_users(users)

            from notifications.broadcast import BroadcastNotification
            notification = BroadcastNotification(title, message, url, app_version)
            notification.send(keys)
コード例 #15
0
    def send_subscription_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users([user_id])

        notification = UpdateSubscriptionsNotification(user_id, sending_device_key)
        notification.send(clients)
コード例 #16
0
    def send_favorite_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users([user_id])

        notification = UpdateFavoritesNotification(user_id, sending_device_key)
        notification.send(clients)
コード例 #17
0
    def send_match_score_update(cls, match):
        users = PushHelper.get_users_subscribed_to_match(match, NotificationType.MATCH_SCORE)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = MatchScoreNotification(match)
        notification.send(keys)
コード例 #18
0
    def send_broadcast(cls, client_types, title, message, url, app_version=''):
        users = PushHelper.get_all_mobile_clients(client_types)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = BroadcastNotification(title, message, url, app_version)
        notification.send(keys)
コード例 #19
0
    def send_award_update(cls, event):
        users = PushHelper.get_users_subscribed_to_event(event, NotificationType.AWARDS)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = AwardsUpdatedNotification(event)
        notification.send(keys)
コード例 #20
0
    def send_alliance_update(cls, event):
        users = PushHelper.get_users_subscribed_for_alliances(event, NotificationType.ALLIANCE_SELECTION)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = AllianceSelectionNotification(event)
        notification.send(keys)
コード例 #21
0
    def send_schedule_update(cls, event):
        users = PushHelper.get_users_subscribed_to_event(event, NotificationType.SCHEDULE_UPDATED)
        keys = PushHelper.get_client_ids_for_users(users)

        notification = ScheduleUpdatedNotification(event)
        notification.send(keys)
コード例 #22
0
    def post(self, type):
        self._require_registration('/account/')
        event_key = self.request.get('event_key')
        match_key = self.request.get('match_key')
        district_key = self.request.get('district_key')
        user_id = self.user_bundle.account.key.id()

        logging.info("Sending for {}".format(type))
        try:
            type = int(type)
        except ValueError:
            # Not passed a valid int, just stop here
            logging.info("Invalid number passed")
            return

        event = None

        if type != NotificationType.DISTRICT_POINTS_UPDATED:
            if event_key == "":
                logging.info("No event key")
                self.response.out.write("No event key specified!")
                return

            event = Event.get_by_id(event_key)

            if event is None:
                logging.info("Invalid event key passed")
                self.response.out.write("Invalid event key!")
                return

        if type == NotificationType.UPCOMING_MATCH:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = UpcomingMatchNotification(match, event)
        elif type == NotificationType.MATCH_SCORE:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = MatchScoreNotification(match)
        elif type == NotificationType.LEVEL_STARTING:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = CompLevelStartingNotification(match, event)
        elif type == NotificationType.ALLIANCE_SELECTION:
            notification = AllianceSelectionNotification(event)
        elif type == NotificationType.AWARDS:
            notification = AwardsUpdatedNotification(event)
        elif type == NotificationType.MEDIA_POSTED:
            # Not implemented yet
            pass
        elif type == NotificationType.DISTRICT_POINTS_UPDATED:
            if district_key == "":
                logging.info("No district key")
                self.response.out.write("No district key specified!")
                return

            district = District.get_by_id(district_key)

            if district is None:
                logging.info("Invalid district key passed")
                self.response.out.write("Invalid district key!")
                return
            notification = DistrictPointsUpdatedNotification(district)
        elif type == NotificationType.SCHEDULE_UPDATED:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = ScheduleUpdatedNotification(event, match)
        elif type == NotificationType.FINAL_RESULTS:
            # Not implemented yet
            pass
        elif type == NotificationType.MATCH_VIDEO:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = MatchVideoNotification(match)
        elif type == NotificationType.EVENT_MATCH_VIDEO:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = EventMatchVideoNotification(match)
        else:
            # Not passed a valid int, return
            return

        keys = PushHelper.get_client_ids_for_users([user_id])
        logging.info("Keys: {}".format(keys))
        if notification:
            # This page should not push notifications to the firebase queue
            # Nor should its notifications be tracked in analytics
            notification.send(keys, push_firebase=False, track_call=False)

        self.response.out.write("ok")
コード例 #23
0
    def post(self, type):
        self._require_registration('/account/')
        event_key = self.request.get('event_key')
        match_key = self.request.get('match_key')
        district_key = self.request.get('district_key')
        user_id = self.user_bundle.account.key.id()

        logging.info("Sending for {}".format(type))
        try:
            type = int(type)
        except ValueError:
            # Not passed a valid int, just stop here
            logging.info("Invalid number passed")
            return

        event = None

        if type != NotificationType.DISTRICT_POINTS_UPDATED:
            if event_key == "":
                logging.info("No event key")
                self.response.out.write("No event key specified!")
                return

            event = Event.get_by_id(event_key)

            if event is None:
                logging.info("Invalid event key passed")
                self.response.out.write("Invalid event key!")
                return

        if type == NotificationType.UPCOMING_MATCH:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = UpcomingMatchNotification(match, event)
        elif type == NotificationType.MATCH_SCORE:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = MatchScoreNotification(match)
        elif type == NotificationType.LEVEL_STARTING:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = CompLevelStartingNotification(match, event)
        elif type == NotificationType.ALLIANCE_SELECTION:
            notification = AllianceSelectionNotification(event)
        elif type == NotificationType.AWARDS:
            notification = AwardsUpdatedNotification(event)
        elif type == NotificationType.MEDIA_POSTED:
            # Not implemented yet
            pass
        elif type == NotificationType.DISTRICT_POINTS_UPDATED:
            if district_key == "":
                logging.info("No district key")
                self.response.out.write("No district key specified!")
                return

            district = District.get_by_id(district_key)

            if district is None:
                logging.info("Invalid district key passed")
                self.response.out.write("Invalid district key!")
                return
            notification = DistrictPointsUpdatedNotification(district)
        elif type == NotificationType.SCHEDULE_UPDATED:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = ScheduleUpdatedNotification(event, match)
        elif type == NotificationType.FINAL_RESULTS:
            # Not implemented yet
            pass
        elif type == NotificationType.MATCH_VIDEO:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = MatchVideoNotification(match)
        elif type == NotificationType.EVENT_MATCH_VIDEO:
            if match_key == "":
                logging.info("No match key")
                self.response.out.write("No match key specified!")
                return

            match = Match.get_by_id(match_key)

            if match is None:
                logging.info("Invalid match key passed")
                self.response.out.write("Invalid match key!")
                return

            notification = EventMatchVideoNotification(match)
        else:
            # Not passed a valid int, return
            return

        keys = PushHelper.get_client_ids_for_users([user_id])
        logging.info("Keys: {}".format(keys))
        if notification:
            # This page should not push notifications to the firebase queue
            # Nor should its notifications be tracked in analytics
            notification.send(keys, push_firebase=False, track_call=False)

        self.response.out.write("ok")