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)
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)
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)
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)
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)
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