Ejemplo n.º 1
0
    def mutate(self, info, post_id):
        errors = list()
        redirect = False
        room = None
        profile = info.context.user.active_profile
        match = None

        try:
            match = Post.objects.get(id=post_id)
            match.liked_by.add(profile)
            profile.favorite_posts.add(match)
            match.save()
            new_like.send(sender=None, profile=match.profile)
        except ObjectDoesNotExist:
            errors.append('Match with specified ID does not exists.')

        receiver_profile = match.profile
        receiver_liked_by = receiver_profile.who_liked_matches
        sender_liked_by = profile.who_liked_matches

        if receiver_profile in sender_liked_by and profile in receiver_liked_by and not Room.exists(receiver_profile.id, profile.id, match.id):
            room = Room.objects.create(post=match)
            room.users.add(profile)
            room.users.add(receiver_profile)
            room.save()
            redirect = True
            posts_matched.send(sender=match.__class__, matched_post=match)
        elif Room.exists(receiver_profile.id, profile.id, match.id):
            room = Room.get_by_users(receiver_profile.id, profile.id)

        return LikePostMutation(errors=errors, room=room, redirect=redirect)
Ejemplo n.º 2
0
    def resolve_has_room(self, info):
        profile = info.context.user.active_profile
        receiver_profile = self.profile
        if Room.exists(profile.id, receiver_profile.id, self.id):
            return True

        return False
Ejemplo n.º 3
0
    def mutate(self, info, room_input):
        room = None
        errors = list()
        post_id = room_input['post_id']

        post = Post.objects.get(id=post_id)
        sender = info.context.user.active_profile
        receiver = post.profile

        if Room.exists(sender.id, receiver.id, post_id):
            errors.append('Room for this post already exists.')
            return CreateRoomMutation(room=room, errors=errors)

        room = Room.objects.create(post_id=post_id)

        room.users.add(receiver)
        room.users.add(sender)
        room.save()

        new_listing_response.send(sender=None, profile=receiver)

        return CreateRoomMutation(room=room, errors=errors)