uni-app 144评论朋友圈api开发

Posted 2019ab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uni-app 144评论朋友圈api开发相关的知识,希望对你有一定的参考价值。

app/controller/commet.js

// 朋友圈评论
    async comment() 
        const  ctx, app  = this;
        let current_user_id = ctx.authUser.id;

        ctx.validate(
            id: 
                type: "int",
                required: true,
                desc: "朋友圈id"
            ,
            content: 
                type: "string",
                required: true,
                desc: "评论内容"
            ,
            reply_id: 
                type: "int",
                required: true,
                defValue: 0,
                desc: "回复id"
            
        );

        let  id, content, reply_id  = ctx.request.body;

        let MomentTimeline = await app.model.MomentTimeline.findOne(
            where: 
                user_id: current_user_id,
                moment_id: id
            ,
            include: [
                model: app.model.Moment,
                attributes: ['user_id'],
                include: [
                    model: app.model.MomentLike,
                    attributes: ['user_id']
                ]
            ]
        );

        if (!MomentTimeline) 
            return ctx.apiFail('朋友圈消息不存在');
        

        let comment = await app.model.MomentComment.create(
            user_id: current_user_id,
            moment_id: id,
            content,
            reply_id
        );

        ctx.apiSuccess(comment);

        let message = 
            avatar: ctx.authUser.avatar,
            user_id: current_user_id,
            type: "comment"
        
        // 通知作者
        if (MomentTimeline.moment.user_id && MomentTimeline.moment.user_id !== current_user_id) 
            ctx.sendAndSaveMessage(MomentTimeline.moment.user_id, message, 'moment');
        
        // 通知相关人
        MomentTimeline.moment.moment_likes.forEach(item => 
            if (item.user_id !== current_user_id) 
                ctx.sendAndSaveMessage(item.user_id, message, 'moment');
            
        );

感谢大家观看,我们下次见

以上是关于uni-app 144评论朋友圈api开发的主要内容,如果未能解决你的问题,请参考以下文章

uni-app 146朋友圈列表api开发

uni-app 139发布朋友圈api开发

uni-app 140发布朋友圈api开发

uni-app 142点赞朋友圈api开发

uni-app 147我的朋友圈列表api开发

uni-app 143点赞朋友圈api开发