如下是我測試的截圖
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5iMxADN0IGZhN2N2gTNxkDNzYzXyQzM1UTM0EzLcBTMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
ceshi6和ceshi3是好友關系,一開始ceshi6是可以檢視ceshi3的朋友圈的,發現删除ceshi6将ceshi3好友删除之後依然可以看到ceshi3的朋友圈。這次就是修複了這個問題
// 删除好友
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
}
});
}