Exemplo n.º 1
0
def comment_request_impl(args):
    try:
        author = user_from_token(args['token'])
        post = post_from_id(author, args['post_id'])
        comment = Comment(args['content'])
        post.comments.append(comment)
        author.comments.append(comment)
        post.add_hot(5, None)
        if args.has_key("picture") and args['picture'] is not None:
            output = s3_upload(args['picture'])
            url = 'https://{}.s3.amazonaws.com/{}'.format(os.environ['S3_BUCKET_NAME'], output)
            comment.pic = url
        db.session.commit()

        #send notification to author
        send_notification_for_user_commenting_on_post(device_token=post.user.device_token,
                                                        user_id=author.id,
                                                        user_pic=author.pic,
                                                            comment_id=comment.id,
                                                            nickname=author.nickname,
                                                            post_id=post.id,
                                                            platform=post.user.platform)

        return Response(True, "Comment Succeded", CommentSchema().dumps(comment).data).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()
Exemplo n.º 2
0
def comments_request_impl(args):
    try:
        user = user_from_token(args['token'])
        post = post_from_id(user ,args['post_id'])
        comments = comments_from_post_paginated(post, int(args['page']), int(args['limit']))
        return Response(True, "Comments Searched", CommentSchema(many=True).dumps(comments).data).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()
Exemplo n.º 3
0
def screenshot_post_request_impl(args):
    try:
        user = user_from_token(args['token'])
        post = post_from_id(user, args['post_id'])
        if post.user != user:
            post_screenshot_notification.delay(post, user)

        return Response(True, "Screenshot Sent", None).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()
Exemplo n.º 4
0
def delete_post_request_impl(args):
    try:
        deleter = user_from_token(args['token'])
        post = post_from_id(deleter, args['post_id'])
        if post.user.id != deleter.id:
            is_group_admin(deleter, post.group)
        post.active = False
        for comment in post.comments:
            comment.active = False
        db.session.commit()
        return Response(True, "Delete Succeded", None).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()
Exemplo n.º 5
0
def anon_action_request_impl(args):
    try:
        user = user_from_token(args['token'])
        post = post_from_id(user, args['post_id'])
        group = group_from_id(args['group_id'])
        status = int(args['status'])
        post.approved = status
        if status == UNDEFINED:
            raise CannotAssignValueException
        elif status == APPROVED:
            post_auth_approved_request_notification.delay(post)
        elif status == REMOVED:
            post_auth_removed_request_notification.delay(post)


        db.session.commit()
        return Response(True, "Action taken", PostSchema().dumps(post).data).output()
    except Exception as exception:
        return Response(False, str(exception), None).output()