Commit 6753832f authored by hujiebin's avatar hujiebin

Merge branch 'feature/3.9.0' of...

Merge branch 'feature/3.9.0' of http://47.107.153.111:8081/gitlab/chenweijian/hilo-user into feature/3.9.0
parents 729c0d4f b1c86307
......@@ -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
......@@ -209,9 +209,9 @@ func GetCpCancel(model *domain.Model, userIds []uint64, status cp_e.CpCancelStat
return res, nil
}
func GetCpCancelById(model *domain.Model, id uint64, status cp_e.CpCancelStatus) (*CpCancel, error) {
func GetCpCancelById(model *domain.Model, id, userId uint64) (*CpCancel, error) {
res := new(CpCancel)
err := model.DB().Model(CpCancel{}).Where("status = ? and id = ?", status, id).First(&res).Error
err := model.DB().Model(CpCancel{}).Where("id = ? and (user_id = ? or rec_user_id = ?)", id, userId, userId).First(&res).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
......
......@@ -479,25 +479,51 @@ 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)
cpCancel, err := cp_m.GetCpCancelById(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 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{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment