Exemplo n.º 1
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)
Exemplo n.º 2
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)