Esempio n. 1
0
def send_post_reaction_push_notification(post_reaction):
    post_creator = post_reaction.post.creator

    post_id = post_reaction.post_id
    notification_group = 'post_%s' % post_id

    if post_creator.has_reaction_notifications_enabled_for_post_with_id(post_id=post_reaction.post_id):
        post_reactor = post_reaction.reactor

        one_signal_notification = onesignal_sdk.Notification(post_body={
            "contents": {"en": _('@%(post_reactor_username)s reacted to your post.') % {
                'post_reactor_username': post_reactor.username
            }}
        })

        NotificationPostReactionSerializer = _get_push_notifications_serializers().NotificationPostReactionSerializer

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.POST_REACTION,
            'payload': NotificationPostReactionSerializer(post_reaction).data
        }

        one_signal_notification.set_parameter('data', notification_data)
        one_signal_notification.set_parameter('!thread_id', notification_group)
        one_signal_notification.set_parameter('android_group', notification_group)

        _send_notification_to_user(notification=one_signal_notification, user=post_creator)
Esempio n. 2
0
def send_community_invite_push_notification(community_invite):
    invited_user = community_invite.invited_user

    if invited_user.has_community_invite_notifications_enabled():
        invite_creator = community_invite.creator
        community = community_invite.community

        one_signal_notification = onesignal_sdk.Notification(
            post_body={"en": _('@%(invite_creator)s has invited you to join /c/%(community_name)s.') % {
                'invite_creator': invite_creator.username,
                'community_name': community.name,
            }})

        NotificationCommunityInviteSerializer = _get_push_notifications_serializers().NotificationCommunityInviteSerializer

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.COMMUNITY_INVITE,
            'payload': NotificationCommunityInviteSerializer(community_invite).data
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification, user=invited_user)
Esempio n. 3
0
def send_follow_push_notification(followed_user, following_user):
    if followed_user.has_follow_notifications_enabled():
        one_signal_notification = onesignal_sdk.Notification(
            post_body={
                "contents": {
                    "en":
                    _('@%(following_user_username)s started following you') % {
                        'following_user_username': following_user.username
                    }
                }
            })

        FollowNotificationSerializer = _get_push_notifications_serializers(
        ).FollowNotificationSerializer

        Notification = get_notification_model()

        notification_data = {
            'type':
            Notification.FOLLOW,
            'payload':
            FollowNotificationSerializer({
                'following_user': following_user
            }).data
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification,
                                   user=followed_user)
Esempio n. 4
0
def send_post_comment_push_notification_with_message(post_comment, message,
                                                     target_user):
    Notification = get_notification_model()
    NotificationPostCommentSerializer = _get_push_notifications_serializers(
    ).NotificationPostCommentSerializer

    post = post_comment.post

    notification_payload = NotificationPostCommentSerializer(post_comment).data
    notification_group = 'post_%s' % post.id

    one_signal_notification = onesignal_sdk.Notification(
        post_body={"contents": message})

    notification_data = {
        'type': Notification.POST_COMMENT,
        'payload': notification_payload
    }

    one_signal_notification.set_parameter('data', notification_data)
    one_signal_notification.set_parameter('!thread_id', notification_group)
    one_signal_notification.set_parameter('android_group', notification_group)

    _send_notification_to_user(notification=one_signal_notification,
                               user=target_user)
Esempio n. 5
0
def send_connection_request_push_notification(connection_requester,
                                              connection_requested_for):
    if connection_requested_for.has_connection_request_notifications_enabled():
        one_signal_notification = onesignal_sdk.Notification(
            post_body={
                "en":
                _('@%(connection_requester_username)s wants to connect with you.'
                  ) % {
                      'connection_requester_username':
                      connection_requester.username
                  }
            })

        ConnectionRequestNotificationSerializer = _get_push_notifications_serializers(
        ).ConnectionRequestNotificationSerializer

        Notification = get_notification_model()

        notification_data = {
            'type':
            Notification.CONNECTION_REQUEST,
            'payload':
            ConnectionRequestNotificationSerializer({
                'connection_requester':
                connection_requester
            }).data
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(
            user=connection_requested_for,
            notification=one_signal_notification,
        )
Esempio n. 6
0
def send_community_invite_push_notification(community_invite):
    invited_user = community_invite.invited_user

    if invited_user.has_community_invite_notifications_enabled():
        invite_creator = community_invite.creator
        community = community_invite.community
        target_user_language_code = get_notification_language_code_for_target_user(
            invited_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={
                    "en":
                    _('%(invite_creator_name)s · @%(invite_creator_username)s has invited you to join /c/%(community_name)s.'
                      ) % {
                          'invite_creator_username': invite_creator.username,
                          'invite_creator_name': invite_creator.profile.name,
                          'community_name': community.name,
                      }
                })

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.COMMUNITY_INVITE,
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification,
                                   user=invited_user)
Esempio n. 7
0
def send_connection_request_push_notification(connection_requester,
                                              connection_requested_for):
    if connection_requested_for.has_connection_request_notifications_enabled():
        target_user_language_code = get_notification_language_code_for_target_user(
            connection_requested_for)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={
                    "contents": {
                        "en":
                        _('%(connection_requester_name)s · @%(connection_requester_username)s wants to connect with you.'
                          ) % {
                              'connection_requester_username':
                              connection_requester.username,
                              'connection_requester_name':
                              connection_requester.profile.name,
                          }
                    }
                })

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.CONNECTION_REQUEST,
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(user=connection_requested_for,
                                   notification=one_signal_notification)
Esempio n. 8
0
def send_follow_request_push_notification(follow_request):
    follow_requester = follow_request.creator
    follow_request_target_user = follow_request.target_user

    if follow_request_target_user.has_follow_request_notifications_enabled():
        target_user_language_code = get_notification_language_code_for_target_user(follow_request_target_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={"contents": {"en": _(
                    '%(follow_requester_name)s · @%(follow_requester_username)s wants to follow you.') % {
                                                  'follow_requester_username': follow_requester.username,
                                                  'follow_requester_name': follow_requester.profile.name,
                                              }}})

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.FOLLOW_REQUEST,
        }

        notification_group = NOTIFICATION_GROUP_MEDIUM_PRIORITY

        one_signal_notification.set_parameter('data', notification_data)
        one_signal_notification.set_parameter('!thread_id', notification_group)
        one_signal_notification.set_parameter('android_group', notification_group)

        _send_notification_to_user(user=follow_request_target_user, notification=one_signal_notification)
Esempio n. 9
0
def send_community_invite_push_notification(community_invite):
    invited_user = community_invite.invited_user

    if invited_user.has_community_invite_notifications_enabled():
        invite_creator = community_invite.creator
        community = community_invite.community
        target_user_language_code = get_notification_language_code_for_target_user(invited_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={"contents": {"en": _(
                    '%(invite_creator_name)s · @%(invite_creator_username)s has invited you to join c/%(community_name)s.') % {
                                                  'invite_creator_username': invite_creator.username,
                                                  'invite_creator_name': invite_creator.profile.name,
                                                  'community_name': community.name,
                                              }}})

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.COMMUNITY_INVITE,
        }

        notification_group = NOTIFICATION_GROUP_MEDIUM_PRIORITY

        one_signal_notification.set_parameter('data', notification_data)
        one_signal_notification.set_parameter('!thread_id', notification_group)
        one_signal_notification.set_parameter('android_group', notification_group)

        _send_notification_to_user(notification=one_signal_notification, user=invited_user)
Esempio n. 10
0
def send_community_new_post_push_notification(community_notifications_subscription):
    community_name = community_notifications_subscription.community.name
    target_user = community_notifications_subscription.subscriber

    if target_user.has_community_new_post_notifications_enabled():
        target_user_language_code = get_notification_language_code_for_target_user(target_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={"contents": {"en": _('A new post was posted in c/%(community_name)s.') % {
                    'community_name': community_name,
                }}})

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.COMMUNITY_NEW_POST,
        }

        notification_group = NOTIFICATION_GROUP_HIGH_PRIORITY

        one_signal_notification.set_parameter('data', notification_data)
        one_signal_notification.set_parameter('!thread_id', notification_group)
        one_signal_notification.set_parameter('android_group', notification_group)

        _send_notification_to_user(notification=one_signal_notification, user=target_user)
Esempio n. 11
0
def send_post_reaction_push_notification(post_reaction):
    post_creator = post_reaction.post.creator

    notification_group = NOTIFICATION_GROUP_LOW_PRIORITY

    if post_creator.has_reaction_notifications_enabled_for_post_with_id(post_id=post_reaction.post_id):
        post_reactor = post_reaction.reactor
        target_user_language_code = get_notification_language_code_for_target_user(post_creator)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(post_body={
                "contents": {"en": _('%(post_reactor_name)s · @%(post_reactor_username)s reacted to your post.') % {
                    'post_reactor_username': post_reactor.username,
                    'post_reactor_name': post_reactor.profile.name,

                }}
            })

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.POST_REACTION,
        }

        one_signal_notification.set_parameter('data', notification_data)
        one_signal_notification.set_parameter('!thread_id', notification_group)
        one_signal_notification.set_parameter('android_group', notification_group)

        _send_notification_to_user(notification=one_signal_notification, user=post_creator)
Esempio n. 12
0
def send_post_user_mention_push_notification(post_user_mention):
    mentioned_user = post_user_mention.user

    if not mentioned_user.has_post_mention_notifications_enabled():
        return

    notification_group = NOTIFICATION_GROUP_MEDIUM_PRIORITY

    mentioner = post_user_mention.post.creator

    target_user_language_code = get_notification_language_code_for_target_user(mentioned_user)
    with translation.override(target_user_language_code):
        one_signal_notification = onesignal_sdk.Notification(post_body={
            "contents": {
                "en": _(
                    '%(mentioner_name)s · @%(mentioner_username)s mentioned you in a post.') % {
                          'mentioner_name': mentioner.profile.name,
                          'mentioner_username': mentioner.username,
                      }}
        })

    Notification = get_notification_model()
    notification_data = {
        'type': Notification.POST_USER_MENTION,
    }
    one_signal_notification.set_parameter('data', notification_data)
    one_signal_notification.set_parameter('!thread_id', notification_group)
    one_signal_notification.set_parameter('android_group', notification_group)
    _send_notification_to_user(notification=one_signal_notification, user=mentioned_user)
Esempio n. 13
0
def send_follow_push_notification(followed_user, following_user):
    if followed_user.has_follow_notifications_enabled():
        target_user_language_code = get_notification_language_code_for_target_user(
            followed_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={
                    "contents": {
                        "en":
                        _('%(following_user_name)s · @%(following_user_username)s started following you'
                          ) %
                        {
                            'following_user_name': following_user.profile.name,
                            'following_user_username': following_user.username,
                        }
                    }
                })

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.FOLLOW,
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification,
                                   user=followed_user)
Esempio n. 14
0
def send_post_comment_reaction_push_notification(post_comment_reaction):
    post_comment_commenter = post_comment_reaction.post_comment.commenter

    post_comment_id = post_comment_reaction.post_comment_id
    notification_group = 'post_comment_%s' % post_comment_id

    post_comment_reactor = post_comment_reaction.reactor
    target_user_language_code = get_notification_language_code_for_target_user(
        post_comment_commenter)
    with translation.override(target_user_language_code):
        one_signal_notification = onesignal_sdk.Notification(
            post_body={
                "contents": {
                    "en":
                    _('%(post_comment_reactor_name)s · @%(post_comment_reactor_username)s reacted to your comment.'
                      ) % {
                          'post_comment_reactor_name':
                          post_comment_reactor.profile.name,
                          'post_comment_reactor_username':
                          post_comment_reactor.username,
                      }
                }
            })
    Notification = get_notification_model()
    notification_data = {
        'type': Notification.POST_COMMENT_REACTION,
    }
    one_signal_notification.set_parameter('data', notification_data)
    one_signal_notification.set_parameter('!thread_id', notification_group)
    one_signal_notification.set_parameter('android_group', notification_group)
    _send_notification_to_user(notification=one_signal_notification,
                               user=post_comment_commenter)
Esempio n. 15
0
def send_post_comment_push_notification_with_message(post_comment, message, target_user):
    Notification = get_notification_model()

    notification_group = NOTIFICATION_GROUP_LOW_PRIORITY

    one_signal_notification = onesignal_sdk.Notification(post_body={
        "contents": message
    })

    notification_data = {
        'type': Notification.POST_COMMENT,
    }

    one_signal_notification.set_parameter('data', notification_data)
    one_signal_notification.set_parameter('!thread_id', notification_group)
    one_signal_notification.set_parameter('android_group', notification_group)

    _send_notification_to_user(notification=one_signal_notification, user=target_user)
Esempio n. 16
0
def send_user_new_post_push_notification(user_notifications_subscription, post):
    post_creator_name = user_notifications_subscription.user.profile.name
    post_creator_username = user_notifications_subscription.user.username
    target_user = user_notifications_subscription.subscriber

    if target_user.has_user_new_post_notifications_enabled():
        target_user_language_code = get_notification_language_code_for_target_user(target_user)
        with translation.override(target_user_language_code):
            one_signal_notification = onesignal_sdk.Notification(
                post_body={"contents": {"en": _('%(post_creator_name)s · @%(post_creator_username)s posted something.') % {
                    'post_creator_username': post_creator_username,
                    'post_creator_name': post_creator_name,
                }}})

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.USER_NEW_POST,
        }
        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification, user=target_user)
Esempio n. 17
0
def send_post_comment_push_notification(post_comment):
    post_creator = post_comment.post.creator

    if post_creator.has_comment_notifications_enabled_for_post_with_id(post_id=post_comment.post_id):
        post_commenter = post_comment.commenter

        one_signal_notification = onesignal_sdk.Notification(
            contents={"en": _('@%(post_commenter_username)s commented on your post.') % {
                'post_commenter_username': post_commenter.username
            }})

        NotificationPostCommentSerializer = _get_push_notifications_serializers().NotificationPostCommentSerializer

        Notification = get_notification_model()

        notification_data = {
            'type': Notification.POST_COMMENT,
            'payload': NotificationPostCommentSerializer(post_comment).data
        }

        one_signal_notification.set_parameter('data', notification_data)

        _send_notification_to_user(notification=one_signal_notification, user=post_creator)