test-errcode
wangchuxiao 2 years ago
parent 7fc279a329
commit 87e61046cb

@ -166,9 +166,12 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
if err := callbackBeforeCreateGroup(ctx, req); err != nil { if err := callbackBeforeCreateGroup(ctx, req); err != nil {
return nil, err return nil, err
} }
groupInfo, err := (&cp.PBGroup{req.GroupInfo}).Convert() groupInfo := (&cp.PBGroup{GroupInfo: req.GroupInfo}).Convert()
groupInfo.GroupID = genGroupID(ctx, req.GroupInfo.GroupID) groupInfo.GroupID = genGroupID(ctx, req.GroupInfo.GroupID)
if req.GroupInfo.GroupType != constant.SuperGroup { if req.GroupInfo.GroupType != constant.SuperGroup {
if err := s.GroupInterface.CreateGroup(ctx, []*relation.Group{groupInfo}); err != nil {
return nil, err
}
var groupMembers []*relation.GroupMember var groupMembers []*relation.GroupMember
joinGroup := func(userID string, roleLevel int32) error { joinGroup := func(userID string, roleLevel int32) error {
groupMember := &relation.GroupMember{GroupID: groupInfo.GroupID, RoleLevel: roleLevel, OperatorUserID: tools.OpUserID(ctx), JoinSource: constant.JoinByInvitation, InviterUserID: tools.OpUserID(ctx)} groupMember := &relation.GroupMember{GroupID: groupInfo.GroupID, RoleLevel: roleLevel, OperatorUserID: tools.OpUserID(ctx), JoinSource: constant.JoinByInvitation, InviterUserID: tools.OpUserID(ctx)}
@ -195,22 +198,16 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
return nil, err return nil, err
} }
} }
if err := (*relation.GroupMember)(nil).Create(ctx, groupMembers); err != nil {
return nil, err
}
} else { } else {
if err := db.DB.CreateSuperGroup(groupId, userIDs, len(userIDs)); err != nil { if err := s.GroupInterface.CreateSuperGroup(ctx, groupInfo.GroupID, userIDs, len(userIDs)); err != nil {
return nil, err return nil, err
} }
} }
if err := (*relation.Group)(nil).Create(ctx, []*relation.Group{&groupInfo}); err != nil {
return nil, err
}
utils.CopyStructFields(resp.GroupInfo, groupInfo) utils.CopyStructFields(resp.GroupInfo, groupInfo)
resp.GroupInfo.MemberCount = uint32(len(userIDs)) resp.GroupInfo.MemberCount = uint32(len(userIDs))
if req.GroupInfo.GroupType != constant.SuperGroup { if req.GroupInfo.GroupType != constant.SuperGroup {
chat.GroupCreatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), groupId, userIDs) chat.GroupCreatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), groupInfo.GroupID, userIDs)
} else { } else {
for _, userID := range userIDs { for _, userID := range userIDs {
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil { if err := rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil {

@ -1,7 +1,7 @@
package utils package utils
import ( import (
imdb "Open_IM/pkg/common/db/mysql" "Open_IM/pkg/common/db/relation"
sdk "Open_IM/pkg/proto/sdk_ws" sdk "Open_IM/pkg/proto/sdk_ws"
utils2 "Open_IM/pkg/utils" utils2 "Open_IM/pkg/utils"
utils "github.com/OpenIMSDK/open_utils" utils "github.com/OpenIMSDK/open_utils"
@ -20,7 +20,7 @@ func getNumberOfGroupMember(groupID string) (int32, error) {
} }
type DBFriend struct { type DBFriend struct {
*imdb.Friend *relation.Friend
} }
type PBFriend struct { type PBFriend struct {
@ -41,8 +41,8 @@ func (db *DBFriend) convert() (*sdk.FriendInfo, error) {
return pbFriend, nil return pbFriend, nil
} }
func (pb *PBFriend) Convert() (*imdb.Friend, error) { func (pb *PBFriend) Convert() (*relation.Friend, error) {
dbFriend := &imdb.Friend{} dbFriend := &relation.Friend{}
utils2.CopyStructFields(dbFriend, pb) utils2.CopyStructFields(dbFriend, pb)
dbFriend.FriendUserID = pb.FriendUser.UserID dbFriend.FriendUserID = pb.FriendUser.UserID
dbFriend.CreateTime = utils2.UnixSecondToTime(int64(pb.CreateTime)) dbFriend.CreateTime = utils2.UnixSecondToTime(int64(pb.CreateTime))
@ -50,15 +50,15 @@ func (pb *PBFriend) Convert() (*imdb.Friend, error) {
} }
type DBFriendRequest struct { type DBFriendRequest struct {
*imdb.FriendRequest *relation.FriendRequest
} }
type PBFriendRequest struct { type PBFriendRequest struct {
*sdk.FriendRequest *sdk.FriendRequest
} }
func (pb *PBFriendRequest) Convert() (*imdb.FriendRequest, error) { func (pb *PBFriendRequest) Convert() (*relation.FriendRequest, error) {
dbFriendRequest := &imdb.FriendRequest{} dbFriendRequest := &relation.FriendRequest{}
utils.CopyStructFields(dbFriendRequest, pb) utils.CopyStructFields(dbFriendRequest, pb)
dbFriendRequest.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime)) dbFriendRequest.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
dbFriendRequest.HandleTime = utils.UnixSecondToTime(int64(pb.HandleTime)) dbFriendRequest.HandleTime = utils.UnixSecondToTime(int64(pb.HandleTime))
@ -87,15 +87,15 @@ func (db *DBFriendRequest) Convert() (*sdk.FriendRequest, error) {
} }
type DBBlack struct { type DBBlack struct {
*imdb.Black *relation.Black
} }
type PBBlack struct { type PBBlack struct {
*sdk.BlackInfo *sdk.BlackInfo
} }
func (pb *PBBlack) Convert() (*imdb.Black, error) { func (pb *PBBlack) Convert() (*relation.Black, error) {
dbBlack := &imdb.Black{} dbBlack := &relation.Black{}
dbBlack.BlockUserID = pb.BlackUserInfo.UserID dbBlack.BlockUserID = pb.BlackUserInfo.UserID
dbBlack.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime)) dbBlack.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
return dbBlack, nil return dbBlack, nil
@ -113,17 +113,17 @@ func (db *DBBlack) Convert() (*sdk.BlackInfo, error) {
} }
type DBGroup struct { type DBGroup struct {
*imdb.Group *relation.Group
} }
type PBGroup struct { type PBGroup struct {
*sdk.GroupInfo *sdk.GroupInfo
} }
func (pb *PBGroup) Convert() (*imdb.Group, error) { func (pb *PBGroup) Convert() *relation.Group {
dst := &imdb.Group{} dst := &relation.Group{}
utils.CopyStructFields(dst, pb) _ = utils.CopyStructFields(dst, pb)
return dst, nil return dst
} }
func (db *DBGroup) Convert() (*sdk.GroupInfo, error) { func (db *DBGroup) Convert() (*sdk.GroupInfo, error) {
dst := &sdk.GroupInfo{} dst := &sdk.GroupInfo{}
@ -148,15 +148,15 @@ func (db *DBGroup) Convert() (*sdk.GroupInfo, error) {
} }
type DBGroupMember struct { type DBGroupMember struct {
*imdb.GroupMember *relation.GroupMember
} }
type PBGroupMember struct { type PBGroupMember struct {
*sdk.GroupMemberFullInfo *sdk.GroupMemberFullInfo
} }
func (pb *PBGroupMember) Convert() (*imdb.GroupMember, error) { func (pb *PBGroupMember) Convert() (*relation.GroupMember, error) {
dst := &imdb.GroupMember{} dst := &relation.GroupMember{}
utils.CopyStructFields(dst, pb) utils.CopyStructFields(dst, pb)
dst.JoinTime = utils.UnixSecondToTime(int64(pb.JoinTime)) dst.JoinTime = utils.UnixSecondToTime(int64(pb.JoinTime))
dst.MuteEndTime = utils.UnixSecondToTime(int64(pb.MuteEndTime)) dst.MuteEndTime = utils.UnixSecondToTime(int64(pb.MuteEndTime))
@ -184,15 +184,15 @@ func (db *DBGroupMember) Convert() (*sdk.GroupMemberFullInfo, error) {
} }
type DBGroupRequest struct { type DBGroupRequest struct {
*imdb.GroupRequest *relation.GroupRequest
} }
type PBGroupRequest struct { type PBGroupRequest struct {
*sdk.GroupRequest *sdk.GroupRequest
} }
func (pb *PBGroupRequest) Convert() (*imdb.GroupRequest, error) { func (pb *PBGroupRequest) Convert() (*relation.GroupRequest, error) {
dst := &imdb.GroupRequest{} dst := &relation.GroupRequest{}
utils.CopyStructFields(dst, pb) utils.CopyStructFields(dst, pb)
dst.ReqTime = utils.UnixSecondToTime(int64(pb.ReqTime)) dst.ReqTime = utils.UnixSecondToTime(int64(pb.ReqTime))
dst.HandledTime = utils.UnixSecondToTime(int64(pb.HandleTime)) dst.HandledTime = utils.UnixSecondToTime(int64(pb.HandleTime))
@ -207,15 +207,15 @@ func (db *DBGroupRequest) Convert() (*sdk.GroupRequest, error) {
} }
type DBUser struct { type DBUser struct {
*imdb.User *relation.User
} }
type PBUser struct { type PBUser struct {
*sdk.UserInfo *sdk.UserInfo
} }
func (pb *PBUser) Convert() (*imdb.User, error) { func (pb *PBUser) Convert() (*relation.User, error) {
dst := &imdb.User{} dst := &relation.User{}
utils.CopyStructFields(dst, pb) utils.CopyStructFields(dst, pb)
dst.Birth = utils.UnixSecondToTime(pb.Birthday) dst.Birth = utils.UnixSecondToTime(pb.Birthday)
dst.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime)) dst.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))

@ -19,6 +19,7 @@ type GroupInterface interface {
TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error) TakeGroupByID(ctx context.Context, groupID string) (group *relation.Group, err error)
//mongo //mongo
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error
GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) GetSuperGroupByID(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
} }
@ -51,12 +52,17 @@ func (g *GroupController) GetSuperGroupByID(ctx context.Context, groupID string)
return g.database.GetSuperGroup(ctx, groupID) return g.database.GetSuperGroup(ctx, groupID)
} }
func (g *GroupController) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error {
return g.database.CreateSuperGroup(ctx, groupID, initMemberIDList, memberNumCount)
}
type DataBase interface { type DataBase interface {
Find(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error) Find(ctx context.Context, groupIDs []string) (groups []*relation.Group, err error)
Create(ctx context.Context, groups []*relation.Group) error Create(ctx context.Context, groups []*relation.Group) error
Delete(ctx context.Context, groupIDs []string) error Delete(ctx context.Context, groupIDs []string) error
Take(ctx context.Context, groupID string) (group *relation.Group, err error) Take(ctx context.Context, groupID string) (group *relation.Group, err error)
GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error)
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error
} }
type GroupDataBase struct { type GroupDataBase struct {
@ -120,6 +126,10 @@ func (g *GroupDataBase) Update(ctx context.Context, groups []*relation.Group) er
}) })
} }
func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string, memberNumCount int) error {
g.mongoDB.CreateSuperGroup(ctx, groupID, initMemberIDList, memberNumCount)
}
func (g *GroupDataBase) GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) { func (g *GroupDataBase) GetSuperGroup(ctx context.Context, groupID string) (superGroup *unrelation.SuperGroup, err error) {
return g.mongoDB.GetSuperGroup(ctx, groupID) return g.mongoDB.GetSuperGroup(ctx, groupID)
} }

Loading…
Cancel
Save