diff --git a/internal/logic/app/group_app.go b/internal/logic/app/group_app.go index f47aa8f..41f9fec 100644 --- a/internal/logic/app/group_app.go +++ b/internal/logic/app/group_app.go @@ -4,9 +4,11 @@ import ( "context" "database/sql" "errors" + "gim/internal/business/comm/utils" "gim/internal/logic/domain/group/model" "gim/internal/logic/domain/group/repo" "gim/pkg/db" + "gim/pkg/grpclib" "gim/pkg/pb" ) @@ -16,8 +18,12 @@ var GroupApp = new(groupApp) // CreateGroup 创建群组 func (*groupApp) CreateGroup(ctx context.Context, userId int64, in *pb.CreateGroupReq) (int64, error) { - group := model.CreateGroup(userId, in) - err := repo.GroupRepo.Save(group) + masterId, err := grpclib.GetCtxMasterId(ctx) + if err != nil { + return 0, err + } + group := model.CreateGroup(userId, utils.StrToInt64(masterId), in) + err = repo.GroupRepo.Save(group) if err != nil { return 0, err } diff --git a/internal/logic/domain/group/model/group.go b/internal/logic/domain/group/model/group.go index 4a7adeb..b0f8da3 100644 --- a/internal/logic/domain/group/model/group.go +++ b/internal/logic/domain/group/model/group.go @@ -31,6 +31,7 @@ type Group struct { Introduction string // 群简介 UserNum int32 // 群组人数 IsAllMemberBanned int32 // 是否全员禁言(1:是 2:否) + MasterId int64 // 站长id Extra string // 附加字段 CreateTime time.Time // 创建时间 UpdateTime time.Time // 更新时间 @@ -81,12 +82,13 @@ func (g *Group) ToProto() *pb.Group { } } -func CreateGroup(userId int64, in *pb.CreateGroupReq) *Group { +func CreateGroup(userId, masterId int64, in *pb.CreateGroupReq) *Group { now := time.Now() group := &Group{ Name: in.Name, AvatarUrl: in.AvatarUrl, Introduction: in.Introduction, + MasterId: masterId, Extra: in.Extra, Members: make([]GroupUser, 0, len(in.MemberIds)+1), CreateTime: now,