Exemplo n.º 1
0
def prepare_new_offer_notification_email(user, offer):
    conversation = Conversation.objects.get_for_target(offer)

    reply_to_name = offer.user.display_name

    local_part = make_local_part(conversation, user)
    reply_to = formataddr(
        (reply_to_name, '{}@{}'.format(local_part,
                                       settings.EMAIL_REPLY_DOMAIN)))
    from_email = formataddr(
        (offer.user.display_name, settings.DEFAULT_FROM_EMAIL))

    unsubscribe_url = new_offer_unsubscribe_url(user, offer)

    return prepare_email(
        template='new_offer',
        from_email=from_email,
        user=user,
        tz=offer.group.timezone,
        reply_to=[reply_to],
        unsubscribe_url=unsubscribe_url,
        context={
            'user_name': offer.user.display_name,
            'offer_photo': offer_image_url(offer),
            'offer_name': offer.name,
            'offer_description': offer.description,
            'group': offer.group,
            'offer_url': offer_url(offer),
            'mute_url': unsubscribe_url,
            'new_offer_unsubscribe_url': unsubscribe_url,
        },
        stats_category='new_offer',
    )
Exemplo n.º 2
0
def prepare_offer_message_notification(user, messages):
    offer = target_from_messages(messages)
    with translation.override(language_for_user(user)):
        return prepare_message_notification(
            user,
            messages,
            group=offer.group,
            conversation_name=_('New message for offer %(offer_name)s in %(group_name)s') % {
                'offer_name': offer.name,
                'group_name': offer.group.name,
            },
            conversation_url=offer_url(offer),
            stats_category='offer_message'
        )
Exemplo n.º 3
0
def notify_new_offer_push_subscribers_with_language(offer, subscriptions, language):
    if not translation.check_for_language(language):
        language = 'en'

    with translation.override(language):
        # TODO: make a nicer title... like "New offer..." blahblhablah
        message_title = '🎁️ {} / {}'.format(offer.name, offer.user)

    notify_subscribers_by_device(
        subscriptions,
        click_action=frontend_urls.offer_url(offer),
        fcm_options={
            'message_title': message_title,
            'message_body': Truncator(offer.description).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': 'offer:{}'.format(offer.id),
        },
    )