Exemplo n.º 1
0
 async def new_message(self, chat_uuid, user, message_content):
     try:
         chat = MessageParticipants.objects.get(
             chat_uuid=chat_uuid
         )
     except MessageParticipants.DoesNotExist:
         chat = None
     receiver_user_ids = Participant.objects.filter(chat=chat).values_list('user', flat=True)
     receiver_users = User.objects.filter(id__in=receiver_user_ids)
     message = Message.objects.create(
         content=message_content, sender=user,
         message_participant=chat,
         sent_at=timezone.now()
     ) 
     chat.last_message_at = timezone.now()
     chat.save()
     notification = create_chat_message_notification(chat)
     for receiver in receiver_users: 
         if not receiver.id == user.id:
             MessageReceiver.objects.create(
                 receiver=receiver,
                 message=message
             )
             create_email_notification(receiver, chat, message_content, user, notification)
             create_user_notification(receiver, notification)
     return {
         "message": message,
         "receivers": receiver_users
     }          
Exemplo n.º 2
0
def create_project_comment_reply_notification(project, comment, sender):
    notification = Notification.objects.create(notification_type=3,
                                               project_comment=comment)
    comments_in_thread = Comment.objects.filter(
        Q(id=comment.parent_comment.id)
        | Q(parent_comment=comment.parent_comment.id)).distinct(
            'author_user').values('author_user')

    users_notification_sent = []

    for thread_comment in comments_in_thread:
        if not thread_comment['author_user'] == sender.id:
            user = User.objects.filter(id=thread_comment['author_user'])[0]
            create_user_notification(user, notification)
            send_out_live_notification(user.id)
            send_email_notification(user, "project_comment_reply", project,
                                    comment, sender, notification)
            users_notification_sent.append(user.id)

    project_team = ProjectMember.objects.filter(project=project).values('user')
    for member in project_team:
        if not member['user'] == sender.id and not member[
                'user'] in users_notification_sent:
            user = User.objects.filter(id=member['user'])[0]
            create_user_notification(user, notification)
            send_out_live_notification(user.id)
            send_email_notification(user, "project_comment_reply", project,
                                    comment, sender, notification)
    return notification
Exemplo n.º 3
0
 def post(self, request, chat_uuid):
     if 'message_content' not in request.data or not chat_uuid:
         return NotFound('Required parameter missing')
     user = request.user
     try:
         chat = MessageParticipants.objects.get(chat_uuid=chat_uuid)
         Participant.objects.get(user=user, chat=chat, is_active=True)
     except Participant.DoesNotExist:
         raise NotFound('You are not a participant of this chat.')
     if chat:
         receiver_user_ids = Participant.objects.filter(
             chat=chat, is_active=True).values_list('user', flat=True)
         receiver_users = User.objects.filter(id__in=receiver_user_ids)
         message = Message.objects.create(
             content=request.data['message_content'],
             sender=user,
             message_participant=chat,
             sent_at=timezone.now())
         chat.last_message_at = timezone.now()
         chat.save()
         notification = create_chat_message_notification(chat)
         for receiver in receiver_users:
             if not receiver.id == user.id:
                 MessageReceiver.objects.create(receiver=receiver,
                                                message=message)
                 create_email_notification(receiver, chat,
                                           request.data['message_content'],
                                           user, notification)
                 create_user_notification(receiver, notification)
     return Response({'message': 'Message sent'},
                     status=status.HTTP_201_CREATED)
Exemplo n.º 4
0
def create_project_follower_notification(project_follower):
    notification = Notification.objects.create(
        notification_type=4, project_follower=project_follower)
    project_team = ProjectMember.objects.filter(
        project=project_follower.project).values('user')
    for member in project_team:
        if not member['user'] == project_follower.user.id:
            user = User.objects.filter(id=member['user'])[0]
            create_user_notification(user, notification)
            send_project_follower_email(user, project_follower, notification)
Exemplo n.º 5
0
def create_project_comment_notification(project, comment, sender):
    notification = Notification.objects.create(notification_type=2,
                                               project_comment=comment)
    project_team = ProjectMember.objects.filter(project=project).values('user')
    for member in project_team:
        if not member['user'] == sender.id:
            user = User.objects.filter(id=member['user'])[0]
            create_user_notification(user, notification)
            send_out_live_notification(user.id)
            send_email_notification(user, "project_comment", project, comment,
                                    sender, notification)
    return notification
Exemplo n.º 6
0
def create_project_follower_notification(project_follower):
    notification = Notification.objects.create(
        notification_type=4, project_follower=project_follower)
    project_team = ProjectMember.objects.filter(
        project=project_follower.project).values('user')
    for member in project_team:
        if not member['user'] == project_follower.user.id:
            user = User.objects.filter(id=member['user'])[0]
            should_send_email_notification = check_send_email_notification(
                user)
            create_user_notification(user, notification)
            send_out_live_notification(user.id)
            email_settings = UserProfile.objects.filter(
                user=user).values('email_on_new_project_follower')[0]
            if should_send_email_notification:
                if email_settings['email_on_reply_to_your_comment'] == True:
                    send_project_follower_email(user, project_follower)
                    EmailNotification.objects.create(user=user,
                                                     created_at=datetime.now(),
                                                     notification=notification)
Exemplo n.º 7
0
 async def new_message(self, chat_uuid, user, message_content):
     try:
         message_participant = MessageParticipants.objects.get(
             chat_uuid=chat_uuid
         )
     except MessageParticipants.DoesNotExist:
         message_participant = None
     receivers = message_participant.participants.all().exclude(id=user.id)
     message = Message.objects.create(
         content=message_content, sender=user,
         message_participant=message_participant,
         sent_at=timezone.now()
     ) 
     message_participant.last_message_at = timezone.now()
     message_participant.save()
     notification = create_chat_message_notification(message_participant)
     for receiver in receivers: 
         MessageReceiver.objects.create(
             receiver=receiver,
             message=message
         )
         create_user_notification(receiver, notification)
     return message          
Exemplo n.º 8
0
def create_idea_join_notification(idea, idea_supporter, chat_uuid):
    notification = Notification.objects.create(
        notification_type = Notification.PERSON_JOINED_IDEA,
        idea_supporter = idea_supporter
    )
    try:
        all_supporters = IdeaSupporter.objects.filter(idea=idea_supporter.idea).exclude(user=idea.user)
        # send notification to the idea's creator as well        
        users_to_be_notified = [idea.user]
        for supporter in all_supporters:
            if not supporter.user.id == idea.user.id and not supporter.user.id == idea_supporter.user.id:
                users_to_be_notified.append(supporter.user)
        for user in users_to_be_notified:
            create_user_notification(user, notification)
            send_out_live_notification(user.id)
            send_idea_join_email(
                user=user, 
                joining_user=idea_supporter.user, 
                idea=idea, 
                chat_uuid=chat_uuid,
                notification=notification
            )
    except IdeaSupporter.DoesNotExist:
        print("This is the only supporter!")