From da1bfa2e0b470fd646e702b796f9d7e9a82ffbd5 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 14 Jun 2023 14:52:20 +0800 Subject: [PATCH] im check --- domain/model/cp_m/cp_relation.go | 4 ++-- route/cp_r/cp_relation.go | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/domain/model/cp_m/cp_relation.go b/domain/model/cp_m/cp_relation.go index 9619c47..50fed84 100644 --- a/domain/model/cp_m/cp_relation.go +++ b/domain/model/cp_m/cp_relation.go @@ -149,9 +149,9 @@ func GetCpInvite(model *domain.Model, userId, userIdInvite uint64, status cp_e.C return res, nil } -func GetCpInviteById(model *domain.Model, id uint64, status cp_e.CpInviteStatus) (*CpInvite, error) { +func GetCpInviteById(model *domain.Model, id, userId uint64) (*CpInvite, error) { res := new(CpInvite) - err := model.DB().Model(CpInvite{}).Where(CpInvite{Id: id, Status: status}).First(&res).Error + err := model.DB().Model(CpInvite{}).Where(CpInvite{Id: id}).Where("user_id = ? or invite_userId = ?", userId, userId).First(&res).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil diff --git a/route/cp_r/cp_relation.go b/route/cp_r/cp_relation.go index 4e0af40..8743b04 100644 --- a/route/cp_r/cp_relation.go +++ b/route/cp_r/cp_relation.go @@ -479,15 +479,27 @@ func CheckCpImExpire(c *gin.Context) (*mycontext.MyContext, error) { } model := domain.CreateModelContext(myCtx) + var resId common.MsgIdType switch msgType { case 1: // 邀请的消息im检查是否过期 - cpRecord, err := cp_m.GetCpInviteById(model, msgId, cp_e.CpInvite) + cpRecord, err := cp_m.GetCpInviteById(model, msgId, userId) if err != nil { model.Log.Errorf("CheckCpImExpire userId:%d, msgType:%d, msgId:%d, err:%v", userId, msgType, msgId, err) return myCtx, err } if cpRecord == nil || cpRecord.Id == 0 { - return myCtx, myerr.ToLocal(msg.GetErrByLanguage(model, common.MSG_ID_ALREADY_EXPIRED, lang, comerr.AlreadyExpired)) + model.Log.Errorf("CheckCpImExpire userId:%d, msgType:%d, msgId:%d, err:%v", userId, msgType, msgId, bizerr.InvalidParameter) + return myCtx, bizerr.InvalidParameter + } + switch cpRecord.Status { + case cp_e.CpInvite: + if userId == cpRecord.UserId { // 发起人 + resId = common.MSG_ID_ALREADY_EXPIRED + } + case cp_e.CpInviteAccept, cp_e.CpInviteRefuse: + resId = common.MSG_ID_ALREADY_EXPIRED + case cp_e.CpInviteExpired: + resId = common.MSG_ID_ALREADY_EXPIRED } case 2: // 解除的消息im检查是否过期 cpCancel, err := cp_m.GetCpCancelById(model, msgId, cp_e.CpCancel) @@ -496,8 +508,22 @@ func CheckCpImExpire(c *gin.Context) (*mycontext.MyContext, error) { return myCtx, err } if cpCancel == nil || cpCancel.Id == 0 { - return myCtx, myerr.ToLocal(msg.GetErrByLanguage(model, common.MSG_ID_ALREADY_EXPIRED, lang, comerr.AlreadyExpired)) + model.Log.Errorf("CheckCpImExpire userId:%d, msgType:%d, msgId:%d, err:%v", userId, msgType, msgId, bizerr.InvalidParameter) + return myCtx, bizerr.InvalidParameter } + switch cpCancel.Status { + case cp_e.CpCancel: + if userId == cpCancel.UserId { // 发起人 + resId = common.MSG_ID_ALREADY_EXPIRED + } + case cp_e.CpCancelRevoke, cp_e.CpCancelAccept: + resId = common.MSG_ID_ALREADY_EXPIRED + case cp_e.CpCancelAcceptAuto: + resId = common.MSG_ID_ALREADY_EXPIRED + } + } + if resId > 0 { + return myCtx, myerr.ToLocal(msg.GetErrByLanguage(model, resId, lang, comerr.AlreadyExpired)) } resp.ResponseOk(c, cp_cv.CheckCpImRes{}) -- 2.22.0