예제 #1
0
def notify_message_push_subscribers_with_language(message, subscriptions,
                                                  language):
    conversation = message.conversation

    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        message_title = get_message_title(message, language)

    if message.is_thread_reply():
        click_action = frontend_urls.thread_url(message.thread)
    else:
        click_action = frontend_urls.conversation_url(conversation,
                                                      message.author)

    notify_subscribers_by_device(
        subscriptions,
        click_action=click_action,
        fcm_options={
            'message_title': message_title,
            'message_body': Truncator(message.content).chars(num=1000),
            # this causes each notification for a given conversation to replace previous notifications
            # fancier would be to make the new notifications show a summary not just the latest message
            'tag': 'conversation:{}'.format(conversation.id),
        })
예제 #2
0
def notify_message_push_subscribers_with_language(message, subscriptions,
                                                  language):
    conversation = message.conversation

    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        message_title = get_message_title(message, language)

    if message.is_thread_reply():
        click_action = frontend_urls.thread_url(message.thread)
    else:
        click_action = frontend_urls.conversation_url(conversation,
                                                      message.author)

    fcm_options = {
        'message_title': message_title,
        'message_body': Truncator(message.content).chars(num=1000),
        # this causes each notification for a given conversation to replace previous notifications
        # fancier would be to make the new notifications show a summary not just the latest message
        'tag': 'conversation:{}'.format(conversation.id)
    }

    android_subscriptions = [
        s for s in subscriptions
        if s.platform == PushSubscriptionPlatform.ANDROID.value
    ]
    web_subscriptions = [
        s for s in subscriptions
        if s.platform == PushSubscriptionPlatform.WEB.value
    ]

    notify_subscribers(
        subscriptions=android_subscriptions,
        fcm_options={
            **fcm_options,
            # according to https://github.com/fechanique/cordova-plugin-fcm#send-notification-payload-example-rest-api
            'click_action':
            'FCM_PLUGIN_ACTIVITY',
            'data_message': {
                # we send the route as data - the frontend takes care of the actual routing
                'karrot_route': str(furl(click_action).fragment),
            },
        })

    notify_subscribers(subscriptions=web_subscriptions,
                       fcm_options={
                           **fcm_options,
                           'message_icon': frontend_urls.logo_url(),
                           'click_action': click_action,
                       })