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
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/fault_tolerant"
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"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)
|
||||
}
|
||||
|
||||
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) {
|
||||
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
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
|
||||
}
|
||||
|
||||
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) {
|
||||
nCtx := trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||
trace_log.SetRpcReqInfo(nCtx, utils.GetSelfFuncName(), req.String())
|
||||
resp := pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
defer trace_log.ShowLog(nCtx)
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
if err := CheckPermission(nCtx, req.GroupID, req.OpUserID); err != nil {
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
groupRequest := imdb.GroupRequest{}
|
||||
utils.CopyStructFields(&groupRequest, req)
|
||||
groupRequest.UserID = req.FromUserID
|
||||
groupRequest.HandleUserID = req.OpUserID
|
||||
groupRequest.HandledTime = time.Now()
|
||||
|
||||
err := imdb.UpdateGroupRequest(groupRequest)
|
||||
if err != 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
|
||||
if err := (&imdb.GroupRequest{}).Update(nCtx, []*imdb.GroupRequest{&groupRequest}); err != nil {
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
request, err := imdb.GetGroupRequestByGroupIDAndUserID(req.GroupID, req.FromUserID)
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(nCtx, req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.GroupID, req.FromUserID)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, 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
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
if req.HandleResult == constant.GroupResponseAgree {
|
||||
user, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.FromUserID)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
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.GroupID = req.GroupID
|
||||
@ -914,6 +927,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
member.Nickname = user.Nickname
|
||||
member.JoinSource = request.JoinSource
|
||||
member.InviterUserID = request.InviterUserID
|
||||
member.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &member, groupInfo.Ex)
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
|
||||
@ -930,92 +944,46 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
err = imdb.InsertIntoGroupMember(member)
|
||||
err = (&imdb.GroupMember{}).Create(nCtx, []*imdb.GroupMember{&member})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, 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())
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
etcdCacheConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdCacheConn == 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
|
||||
etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if err != nil {
|
||||
SetErrorForResp(err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
SetErr(nCtx, "DelGroupMemberIDListFromCache", err, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg, "groupID", req.GroupID)
|
||||
return &resp, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
SetErrCodeMsg(nCtx, "DelGroupMemberIDListFromCache", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, 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 {
|
||||
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 {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
trace_log.SetContextInfo(ctx, "DelJoinedGroupIDListFromCache", err, "groupID ", req.GroupID)
|
||||
}
|
||||
chat.GroupApplicationAcceptedNotification(req)
|
||||
chat.MemberEnterNotification(req)
|
||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||
chat.GroupApplicationRejectedNotification(req)
|
||||
} else {
|
||||
log.Error(req.OperationID, "HandleResult failed ", req.HandleResult)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
SetErr(nCtx, "", constant.ErrArgs, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc GroupApplicationResponse return ", pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}})
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
||||
|
@ -85,6 +85,10 @@ func ToAPIErrWithErr(err error) ErrInfo {
|
||||
return ErrDefaultOther
|
||||
}
|
||||
|
||||
func ToAPIErrWithErrCode(errCode int32) ErrInfo {
|
||||
|
||||
}
|
||||
|
||||
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
||||
err := &sdkws.CommonResp{
|
||||
ErrCode: info.ErrCode,
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -20,18 +19,18 @@ import (
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
||||
toInsertInfo.JoinTime = time.Now()
|
||||
if toInsertInfo.RoleLevel == 0 {
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
}
|
||||
toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
//func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
||||
// toInsertInfo.JoinTime = time.Now()
|
||||
// if toInsertInfo.RoleLevel == 0 {
|
||||
// toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
// }
|
||||
// toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func BatchInsertIntoGroupMember(toInsertInfoList []*GroupMember) error {
|
||||
for _, toInsertInfo := range toInsertInfoList {
|
||||
@ -124,101 +123,101 @@ func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
return number, nil
|
||||
}
|
||||
|
||||
func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
||||
omList, err := GetOwnerManagerByGroupID(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range omList {
|
||||
if v.RoleLevel == constant.GroupOwner {
|
||||
return &v, nil
|
||||
}
|
||||
}
|
||||
return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
|
||||
}
|
||||
|
||||
func IsExistGroupMember(groupID, userID string) bool {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if number != 1 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
||||
var memberList []GroupMember
|
||||
var err error
|
||||
if filter >= 0 {
|
||||
memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
||||
} else {
|
||||
memberList, err = GetGroupMemberListByGroupID(groupID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if begin >= int32(len(memberList)) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var end int32
|
||||
if begin+int32(maxNumber) < int32(len(memberList)) {
|
||||
end = begin + maxNumber
|
||||
} else {
|
||||
end = int32(len(memberList))
|
||||
}
|
||||
return memberList[begin:end], nil
|
||||
}
|
||||
|
||||
func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupIDList []string
|
||||
for _, v := range memberList {
|
||||
groupIDList = append(groupIDList, v.GroupID)
|
||||
}
|
||||
return groupIDList, nil
|
||||
}
|
||||
|
||||
func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, v := range groupMemberList {
|
||||
if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
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
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupMembers, nil
|
||||
}
|
||||
|
||||
func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
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 {
|
||||
return count, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
||||
}
|
||||
//func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
||||
// omList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// for _, v := range omList {
|
||||
// if v.RoleLevel == constant.GroupOwner {
|
||||
// return &v, nil
|
||||
// }
|
||||
// }
|
||||
// return nil, utils.Wrap(constant.ErrNoGroupOwner, "")
|
||||
//}
|
||||
//
|
||||
//func IsExistGroupMember(groupID, userID string) bool {
|
||||
// var number int64
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// if number != 1 {
|
||||
// return false
|
||||
// }
|
||||
// return true
|
||||
//}
|
||||
//
|
||||
//func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
|
||||
// var memberList []GroupMember
|
||||
// var err error
|
||||
// if filter >= 0 {
|
||||
// memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time
|
||||
// } else {
|
||||
// memberList, err = GetGroupMemberListByGroupID(groupID)
|
||||
// }
|
||||
//
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if begin >= int32(len(memberList)) {
|
||||
// return nil, nil
|
||||
// }
|
||||
//
|
||||
// var end int32
|
||||
// if begin+int32(maxNumber) < int32(len(memberList)) {
|
||||
// end = begin + maxNumber
|
||||
// } else {
|
||||
// end = int32(len(memberList))
|
||||
// }
|
||||
// return memberList[begin:end], nil
|
||||
//}
|
||||
//
|
||||
//func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var groupIDList []string
|
||||
// for _, v := range memberList {
|
||||
// groupIDList = append(groupIDList, v.GroupID)
|
||||
// }
|
||||
// return groupIDList, nil
|
||||
//}
|
||||
//
|
||||
//func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
// groupMemberList, err := GetOwnerManagerByGroupID(groupID)
|
||||
// if err != nil {
|
||||
// return false
|
||||
// }
|
||||
// for _, v := range groupMemberList {
|
||||
// if v.UserID == UserID && v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]GroupMember, error) {
|
||||
// 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
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupMembers, nil
|
||||
//}
|
||||
//
|
||||
//func GetGroupMembersCount(groupID, userName string) (int64, error) {
|
||||
// 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 {
|
||||
// return count, err
|
||||
// }
|
||||
// return count, nil
|
||||
//}
|
||||
//
|
||||
//func UpdateGroupMemberInfoDefaultZero(groupMemberInfo GroupMember, args map[string]interface{}) error {
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
||||
//}
|
||||
|
||||
//
|
||||
//func SelectGroupList(groupID string) ([]string, error) {
|
||||
|
@ -19,12 +19,12 @@ import (
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
if groupRequest.HandledTime.Unix() < 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
|
||||
}
|
||||
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
// if groupRequest.HandledTime.Unix() < 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
|
||||
//}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
@ -48,27 +48,27 @@ func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
var groupRequest GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &groupRequest, nil
|
||||
}
|
||||
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
// var groupRequest GroupRequest
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &groupRequest, nil
|
||||
//}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupRequestList, nil
|
||||
}
|
||||
//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
|
||||
//}
|
||||
//
|
||||
//func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return groupRequestList, nil
|
||||
//}
|
||||
|
||||
// received
|
||||
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())
|
||||
}
|
||||
|
||||
func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
if groupRequest.HandledTime.Unix() < 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
|
||||
}
|
||||
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
// if groupRequest.HandledTime.Unix() < 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
|
||||
//}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
|
@ -119,19 +119,19 @@ func (FriendRequest) TableName() string {
|
||||
// string Ex = 10;
|
||||
// int32 AppMangerLevel = 7; //if >0
|
||||
// } open_im_sdk.GroupMemberFullInfo(AppMangerLevel) > imdb.GroupMember
|
||||
type GroupMember struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:nickname;size:255"`
|
||||
FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
RoleLevel int32 `gorm:"column:role_level"`
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
//type GroupMember struct {
|
||||
// GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
// UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
// Nickname string `gorm:"column:nickname;size:255"`
|
||||
// FaceURL string `gorm:"column:user_group_face_url;size:255"`
|
||||
// RoleLevel int32 `gorm:"column:role_level"`
|
||||
// JoinTime time.Time `gorm:"column:join_time"`
|
||||
// JoinSource int32 `gorm:"column:join_source"`
|
||||
// InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
// MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
// Ex string `gorm:"column:ex;size:1024"`
|
||||
//}
|
||||
|
||||
// message GroupRequest{
|
||||
// string UserID = 1;
|
||||
|
@ -303,7 +303,7 @@ func DelAllGroupMembersInfoFromCache(groupID string) error {
|
||||
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) {
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user