天天看點

uni-app 151修複删除好友朋友圈記錄問題

如下是我測試的截圖
uni-app 151修複删除好友朋友圈記錄問題

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
          }
      });
  }