コード例 #1
0
def sendEditStatusNotification(status):
    pushNotification, isCreated = PushNotifications.objects.get_or_create(status=status,
                                                                          pushNotificationType=PushNotifications.PUSH_NOTIF_STATUS_CHANGED,
                                                                          sendingUser=status.user)

    pushNotification.receivingUsers.add(*status.attending.all().exclude(pk=status.user.pk))
    pushNotification.cache()
    handlePushNotification.delay(pushNotification.id)
コード例 #2
0
def sendStatusMessageNotification(message):
    pushNotification, isCreated = PushNotifications.objects.get_or_create(message=message,
                                                                          pushNotificationType=PushNotifications.PUSH_NOTIF_STATUS_MESSAGE,
                                                                          sendingUser=message.user)
    if isCreated:
        pushNotification.receivingUsers.add(*message.status.attending.all().exclude(pk=message.user.pk))
        pushNotification.cache()
        handlePushNotification.delay(pushNotification.id)
コード例 #3
0
def sendChatNotifications(message):
    pushNotification, isCreated = PushNotifications.objects.get_or_create(chatMessage=message,
                                                                          pushNotificationType=PushNotifications.PUSH_NOTIF_CHAT,
                                                                          sendingUser=message.user)
    if isCreated:
        pushNotification.receivingUsers.add(*message.conversation.members.all().exclude(pk=message.user.pk))
        pushNotification.cache()
        handlePushNotification.delay(pushNotification.id)
コード例 #4
0
def sendAttendingStatusPushNotification(status, attendingUser):

    pushNotification, created = PushNotifications.objects.get_or_create(status=status,
                                                         pushNotificationType=PushNotifications.PUSH_NOTIF_STATUS_MEMBERS_ADDED,
                                                         sendingUser=attendingUser)
    if created:
        pushNotification.receivingUsers.add(status.user)
        pushNotification.cache()
        handlePushNotification.delay(pushNotification.id)
コード例 #5
0
def sendInvitedToStatusNotification(status, invitingUser, invitedUsers):
    for user in invitedUsers:
        sendNotification = False
        try:
            pushNotification = PushNotifications.objects.get(status=status,
                                                             pushNotificationType=PushNotifications.PUSH_NOTIF_INVITED,
                                                             receivingUsers=user, sendingUser=invitingUser)
            timeDifference = pushNotification.date - datetime.datetime.now()
            if timeDifference.total_seconds() < 30 * 60:
                pushNotification.date = datetime.datetime.now()
                sendNotification = True

        except PushNotifications.DoesNotExist:
            pushNotification = PushNotifications.objects.create(sendingUser=invitingUser,
                                                                pushNotificationType=PushNotifications.PUSH_NOTIF_INVITED,
                                                                status=status)
            pushNotification.receivingUsers.add(user)
            sendNotification = True

        if sendNotification:
            pushNotification.cache()
            handlePushNotification.delay(pushNotification.id)
コード例 #6
0
def sendFavoritesStatusPushNotification(status):
    favoriteGroupsWithThisUser = Group.objects.filter(name=Group.FAVORITES_GROUP_NAME, members=status.user)

    usersWithFavGroups = list()
    for group in favoriteGroupsWithThisUser:
        if group.user.favoritesNotifications and group.user not in usersWithFavGroups:
            usersWithFavGroups.append(group.user)

    usersToNotify = list()
    for user in usersWithFavGroups:
        if isStatusVisibleToUser(status, user):
            usersToNotify.append(user)

    pushNotification, isCreated = PushNotifications.objects.get_or_create(status=status,
                                                                          pushNotificationType=PushNotifications.PUSH_NOTIF_FAVORITES,
                                                                          sendingUser=status.user)
    if isCreated:
        pushNotification.receivingUsers.add(*usersToNotify)
        pushNotification.cache()
        handlePushNotification.delay(pushNotification.id)

    return usersToNotify