如下是我测试的截图
ceshi6和ceshi3是好友关系,一开始ceshi6是可以查看ceshi3的朋友圈的,发现删除ceshi6将ceshi3好友删除之后依然可以看到ceshi3的朋友圈。这次就是修复了这个问题
/app/controller/friend.js
// 删除好友
async destroy(){
const { ctx,app } = this;
let current_user_id = ctx.authUser.id;
ctx.validate({
friend_id:{
type:'int',
required:true,
desc:'好友id'
}
});
let {friend_id} = ctx.request.body;
await app.model.Friend.destroy({
where:{
user_id:current_user_id,
friend_id
}
});
app.model.Friend.destroy({
where:{
user_id:friend_id,
friend_id:current_user_id
}
});
this.deleteTimeLineMoment(friend_id,current_user_id);
this.deleteTimeLineMoment(current_user_id,friend_id);
return ctx.apiSuccess('ok');
}
// 删除 非好友的朋友圈时间轴记录
async deleteTimeLineMoment(friend_id,user_id){
const { app,ctx } = this;
let moments = await app.model.moments.findAll({
where:{
user_id:friend_id
},
attributes:['id']
});
moments = moments.map(item=>item.id);
await app.model.MomentTimeline.destroy({
where:{
user_id,
moment_id:moments
}
});
}
感谢大家观看,我们下次见