mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-09 04:21:08 +08:00
Error code standardization
This commit is contained in:
parent
847860a0c7
commit
4147c68f6d
@ -1,6 +1,7 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/internal/rpc/fault_tolerant"
|
||||||
chat "Open_IM/internal/rpc/msg"
|
chat "Open_IM/internal/rpc/msg"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
@ -803,6 +804,18 @@ func SetErr(ctx context.Context, funcName string, err error, errCode *int32, err
|
|||||||
trace_log.SetContextInfo(ctx, funcName, err, args)
|
trace_log.SetContextInfo(ctx, funcName, err, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetErrCodeMsg(ctx context.Context, funcName string, errCodeFrom int32, errMsgFrom string, errCode *int32, errMsg *string, args ...interface{}) {
|
||||||
|
*errCode = errCodeFrom
|
||||||
|
*errMsg = errMsgFrom
|
||||||
|
trace_log.SetContextInfo(ctx, funcName, constant.ToAPIErrWithErrCode(errCodeFrom), args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetErrorForResp(err error, errCode *int32, errMsg *string) {
|
||||||
|
errInfo := constant.ToAPIErrWithErr(err)
|
||||||
|
*errCode = errInfo.ErrCode
|
||||||
|
*errMsg = errInfo.ErrMsg
|
||||||
|
}
|
||||||
|
|
||||||
func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
||||||
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
|
trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
|
||||||
@ -867,43 +880,43 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAppManagerAndGroupAdmin(string) {
|
func CheckPermission(ctx context.Context, groupID string, userID string) error {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
||||||
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
|
trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
|
||||||
|
resp := pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}}
|
||||||
defer trace_log.ShowLog(nCtx)
|
defer trace_log.ShowLog(nCtx)
|
||||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
if err := CheckPermission(nCtx, req.GroupID, req.OpUserID); err != nil {
|
||||||
log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID)
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
groupRequest := imdb.GroupRequest{}
|
groupRequest := imdb.GroupRequest{}
|
||||||
utils.CopyStructFields(&groupRequest, req)
|
utils.CopyStructFields(&groupRequest, req)
|
||||||
groupRequest.UserID = req.FromUserID
|
groupRequest.UserID = req.FromUserID
|
||||||
groupRequest.HandleUserID = req.OpUserID
|
groupRequest.HandleUserID = req.OpUserID
|
||||||
groupRequest.HandledTime = time.Now()
|
groupRequest.HandledTime = time.Now()
|
||||||
|
if err := (&imdb.GroupRequest{}).Update(nCtx, []*imdb.GroupRequest{&groupRequest}); err != nil {
|
||||||
err := imdb.UpdateGroupRequest(groupRequest)
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
if err != nil {
|
return &resp, nil
|
||||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), groupRequest)
|
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
||||||
}
|
}
|
||||||
request, err := imdb.GetGroupRequestByGroupIDAndUserID(req.GroupID, req.FromUserID)
|
groupInfo, err := rocksCache.GetGroupInfoFromCache(nCtx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.GroupID, req.FromUserID)
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
|
||||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, "GetGroupInfoFromCache failed ", err.Error(), req.GroupID, req.FromUserID)
|
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
||||||
}
|
}
|
||||||
if req.HandleResult == constant.GroupResponseAgree {
|
if req.HandleResult == constant.GroupResponseAgree {
|
||||||
user, err := imdb.GetUserByUserID(req.FromUserID)
|
user, err := imdb.GetUserByUserID(req.FromUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.FromUserID)
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return &resp, nil
|
||||||
|
}
|
||||||
|
request, err := (&imdb.GroupRequest{}).Take(nCtx, req.GroupID, req.FromUserID)
|
||||||
|
if err != nil {
|
||||||
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
|
return &resp, nil
|
||||||
}
|
}
|
||||||
member := imdb.GroupMember{}
|
member := imdb.GroupMember{}
|
||||||
member.GroupID = req.GroupID
|
member.GroupID = req.GroupID
|
||||||
@ -914,6 +927,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
|||||||
member.Nickname = user.Nickname
|
member.Nickname = user.Nickname
|
||||||
member.JoinSource = request.JoinSource
|
member.JoinSource = request.JoinSource
|
||||||
member.InviterUserID = request.InviterUserID
|
member.InviterUserID = request.InviterUserID
|
||||||
|
member.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||||
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &member, groupInfo.Ex)
|
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &member, groupInfo.Ex)
|
||||||
if callbackResp.ErrCode != 0 {
|
if callbackResp.ErrCode != 0 {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
|
||||||
@ -930,92 +944,46 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
err = imdb.InsertIntoGroupMember(member)
|
err = (&imdb.GroupMember{}).Create(nCtx, []*imdb.GroupMember{&member})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member)
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
|
||||||
var sessionType int
|
|
||||||
if groupInfo.GroupType == constant.NormalGroup {
|
|
||||||
sessionType = constant.GroupChatType
|
|
||||||
} else {
|
|
||||||
sessionType = constant.SuperGroupChatType
|
|
||||||
}
|
|
||||||
var reqPb pbUser.SetConversationReq
|
|
||||||
reqPb.OperationID = req.OperationID
|
|
||||||
var c pbConversation.Conversation
|
|
||||||
conversation, err := imdb.GetConversation(req.FromUserID, utils.GetConversationIDBySessionType(req.GroupID, sessionType))
|
|
||||||
if err != nil {
|
|
||||||
c.OwnerUserID = req.FromUserID
|
|
||||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, sessionType)
|
|
||||||
c.ConversationType = int32(sessionType)
|
|
||||||
c.GroupID = req.GroupID
|
|
||||||
c.IsNotInGroup = false
|
|
||||||
c.UpdateUnreadCountTime = utils.GetCurrentTimestampByMill()
|
|
||||||
} else {
|
|
||||||
c.OwnerUserID = conversation.OwnerUserID
|
|
||||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, sessionType)
|
|
||||||
c.RecvMsgOpt = conversation.RecvMsgOpt
|
|
||||||
c.ConversationType = int32(sessionType)
|
|
||||||
c.GroupID = req.GroupID
|
|
||||||
c.IsPinned = conversation.IsPinned
|
|
||||||
c.AttachedInfo = conversation.AttachedInfo
|
|
||||||
c.IsPrivateChat = conversation.IsPrivateChat
|
|
||||||
c.GroupAtType = conversation.GroupAtType
|
|
||||||
c.IsNotInGroup = false
|
|
||||||
c.Ex = conversation.Ex
|
|
||||||
}
|
|
||||||
reqPb.Conversation = &c
|
|
||||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
|
||||||
if etcdConn == nil {
|
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
||||||
log.NewError(req.OperationID, errMsg)
|
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
|
||||||
client := pbUser.NewUserClient(etcdConn)
|
|
||||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
|
||||||
if err != nil {
|
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
|
||||||
} else {
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
etcdCacheConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||||
if etcdCacheConn == nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
log.NewError(req.OperationID, errMsg)
|
return &resp, nil
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
}
|
||||||
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
||||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
|
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
SetErr(nCtx, "DelGroupMemberIDListFromCache", err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg, "groupID", req.GroupID)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
if cacheResp.CommonResp.ErrCode != 0 {
|
if cacheResp.CommonResp.ErrCode != 0 {
|
||||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
SetErrCodeMsg(nCtx, "DelGroupMemberIDListFromCache", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
|
trace_log.SetContextInfo(ctx, "DelGroupMemberListHashFromCache", err, "groupID ", req.GroupID)
|
||||||
}
|
}
|
||||||
if err := rocksCache.DelJoinedGroupIDListFromCache(req.FromUserID); err != nil {
|
if err := rocksCache.DelJoinedGroupIDListFromCache(req.FromUserID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.FromUserID, err.Error())
|
trace_log.SetContextInfo(ctx, "DelJoinedGroupIDListFromCache", err, "userID ", req.FromUserID)
|
||||||
}
|
}
|
||||||
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
|
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
trace_log.SetContextInfo(ctx, "DelJoinedGroupIDListFromCache", err, "groupID ", req.GroupID)
|
||||||
}
|
}
|
||||||
chat.GroupApplicationAcceptedNotification(req)
|
chat.GroupApplicationAcceptedNotification(req)
|
||||||
chat.MemberEnterNotification(req)
|
chat.MemberEnterNotification(req)
|
||||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||||
chat.GroupApplicationRejectedNotification(req)
|
chat.GroupApplicationRejectedNotification(req)
|
||||||
} else {
|
} else {
|
||||||
log.Error(req.OperationID, "HandleResult failed ", req.HandleResult)
|
SetErr(nCtx, "", constant.ErrArgs, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewInfo(req.OperationID, "rpc GroupApplicationResponse return ", pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}})
|
return &resp, nil
|
||||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
||||||
|
@ -85,6 +85,10 @@ func ToAPIErrWithErr(err error) ErrInfo {
|
|||||||
return ErrDefaultOther
|
return ErrDefaultOther
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToAPIErrWithErrCode(errCode int32) ErrInfo {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
||||||
err := &sdkws.CommonResp{
|
err := &sdkws.CommonResp{
|
||||||
ErrCode: info.ErrCode,
|
ErrCode: info.ErrCode,
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,18 +19,18 @@ import (
|
|||||||
// Ex string `gorm:"column:ex"`
|
// Ex string `gorm:"column:ex"`
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
//func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
||||||
toInsertInfo.JoinTime = time.Now()
|
// toInsertInfo.JoinTime = time.Now()
|
||||||
if toInsertInfo.RoleLevel == 0 {
|
// if toInsertInfo.RoleLevel == 0 {
|
||||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||||
}
|
// }
|
||||||
toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
return nil
|
// return nil
|
||||||
}
|
//}
|
||||||
|
|
||||||
func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error {
|
func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error {
|
||||||
for _, toInsertInfo := range toInsertInfoList {
|
for _, toInsertInfo := range toInsertInfoList {
|
||||||
@ -124,101 +123,101 @@ func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
|||||||
return number, nil
|
return number, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
//func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
||||||
omList, err := GetOwnerManagerByGroupID(groupID)
|
// omList, err := GetOwnerManagerByGroupID(groupID)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
for _, v := range omList {
|
// for _, v := range omList {
|
||||||
if v.RoleLevel == constant.GroupOwner {
|
// if v.RoleLevel == constant.GroupOwner {
|
||||||
return &v, nil
|
// return &v, nil
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
|
// return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func IsExistGroupMember(groupID, userID string) bool {
|
//func IsExistGroupMember(groupID, userID string) bool {
|
||||||
var number int64
|
// var number int64
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
if number != 1 {
|
// if number != 1 {
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
return true
|
// return true
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
//func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
||||||
var memberList []GroupMember
|
// var memberList []GroupMember
|
||||||
var err error
|
// var err error
|
||||||
if filter >= 0 {
|
// if filter >= 0 {
|
||||||
memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
// memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
||||||
} else {
|
// } else {
|
||||||
memberList, err = GetGroupMemberListByGroupID(groupID)
|
// memberList, err = GetGroupMemberListByGroupID(groupID)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
if begin >= int32(len(memberList)) {
|
// if begin >= int32(len(memberList)) {
|
||||||
return nil, nil
|
// return nil, nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
var end int32
|
// var end int32
|
||||||
if begin+int32(maxNumber) < int32(len(memberList)) {
|
// if begin+int32(maxNumber) < int32(len(memberList)) {
|
||||||
end = begin + maxNumber
|
// end = begin + maxNumber
|
||||||
} else {
|
// } else {
|
||||||
end = int32(len(memberList))
|
// end = int32(len(memberList))
|
||||||
}
|
// }
|
||||||
return memberList[begin:end], nil
|
// return memberList[begin:end], nil
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||||
memberList, err := GetGroupMemberListByUserID(userID)
|
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
var groupIDList []string
|
// var groupIDList []string
|
||||||
for _, v := range memberList {
|
// for _, v := range memberList {
|
||||||
groupIDList = append(groupIDList, v.GroupID)
|
// groupIDList = append(groupIDList, v.GroupID)
|
||||||
}
|
// }
|
||||||
return groupIDList, nil
|
// return groupIDList, nil
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
//func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||||
groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
// groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
for _, v := range groupMemberList {
|
// for _, v := range groupMemberList {
|
||||||
if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
// if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false
|
// return false
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||||
var groupMembers []GroupMember
|
// var groupMembers []GroupMember
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
return groupMembers, nil
|
// return groupMembers, nil
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||||
var count int64
|
// var count int64
|
||||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
// if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||||
return count, err
|
// return count, err
|
||||||
}
|
// }
|
||||||
return count, nil
|
// return count, nil
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
//func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||||
return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
// return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
||||||
}
|
//}
|
||||||
|
|
||||||
//
|
//
|
||||||
//func SelectGroupList(groupID string) ([]string, error) {
|
//func SelectGroupList(groupID string) ([]string, error) {
|
||||||
|
@ -19,12 +19,12 @@ import (
|
|||||||
// Ex string `gorm:"column:ex"`
|
// Ex string `gorm:"column:ex"`
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func UpdateGroupRequest(groupRequest GroupRequest) error {
|
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||||
if groupRequest.HandledTime.Unix() < 0 {
|
// if groupRequest.HandledTime.Unix() < 0 {
|
||||||
groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||||
}
|
// }
|
||||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||||
}
|
//}
|
||||||
|
|
||||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||||
@ -48,27 +48,27 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||||
var groupRequest GroupRequest
|
// var groupRequest GroupRequest
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
return &groupRequest, nil
|
// return &groupRequest, nil
|
||||||
}
|
//}
|
||||||
|
|
||||||
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
//func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
//func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
||||||
var groupRequestList []GroupRequest
|
// var groupRequestList []GroupRequest
|
||||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
return groupRequestList, nil
|
// return groupRequestList, nil
|
||||||
}
|
//}
|
||||||
|
|
||||||
// received
|
// received
|
||||||
func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||||
|
@ -70,12 +70,12 @@ func (*GroupRequest) Take(ctx context.Context, groupID string, userID string) (g
|
|||||||
return groupRequest, utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
return groupRequest, utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateGroupRequest(groupRequest GroupRequest) error {
|
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||||
if groupRequest.HandledTime.Unix() < 0 {
|
// if groupRequest.HandledTime.Unix() < 0 {
|
||||||
groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||||
}
|
// }
|
||||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||||
}
|
//}
|
||||||
|
|
||||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||||
|
@ -119,19 +119,19 @@ func (FriendRequest) TableName() string {
|
|||||||
// string Ex = 10;
|
// string Ex = 10;
|
||||||
// int32 AppMangerLevel = 7; //if >0
|
// int32 AppMangerLevel = 7; //if >0
|
||||||
// } open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember
|
// } open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember
|
||||||
type GroupMember struct {
|
//type GroupMember struct {
|
||||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||||
Nickname string `gorm:"column:nickname;size:255"`
|
// Nickname string `gorm:"column:nickname;size:255"`
|
||||||
FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
// FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||||
RoleLevel int32 `gorm:"column:role_level"`
|
// RoleLevel int32 `gorm:"column:role_level"`
|
||||||
JoinTime time.Time `gorm:"column:join_time"`
|
// JoinTime time.Time `gorm:"column:join_time"`
|
||||||
JoinSource int32 `gorm:"column:join_source"`
|
// JoinSource int32 `gorm:"column:join_source"`
|
||||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
// OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
// MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
// Ex string `gorm:"column:ex;size:1024"`
|
||||||
}
|
//}
|
||||||
|
|
||||||
// message GroupRequest{
|
// message GroupRequest{
|
||||||
// string UserID = 1;
|
// string UserID = 1;
|
||||||
|
@ -303,7 +303,7 @@ func DelAllGroupMembersInfoFromCache(groupID string) error {
|
|||||||
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupInfoFromCache(groupID string) (*imdb.Group, error) {
|
func GetGroupInfoFromCache(ctx context.Context, groupID string) (*imdb.Group, error) {
|
||||||
getGroupInfo := func() (string, error) {
|
getGroupInfo := func() (string, error) {
|
||||||
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user