mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 03:26:57 +08:00
1
This commit is contained in:
parent
a2c4bccdb6
commit
bec4a89f7b
@ -165,25 +165,14 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
if req.OwnerUserID == "" {
|
if req.OwnerUserID == "" {
|
||||||
return nil, constant.ErrArgs.Wrap("no group owner")
|
return nil, constant.ErrArgs.Wrap("no group owner")
|
||||||
}
|
}
|
||||||
var userIDs []string
|
userIDs := append(append(req.InitMembers, req.AdminUserIDs...), req.OwnerUserID)
|
||||||
for _, userID := range req.InitMembers {
|
if utils.Duplicate(userIDs) {
|
||||||
userIDs = append(userIDs, userID)
|
|
||||||
}
|
|
||||||
for _, userID := range req.AdminUserIDs {
|
|
||||||
userIDs = append(userIDs, userID)
|
|
||||||
}
|
|
||||||
userIDs = append(userIDs, req.OwnerUserID)
|
|
||||||
if utils.IsDuplicateID(userIDs) {
|
|
||||||
return nil, constant.ErrArgs.Wrap("group member repeated")
|
return nil, constant.ErrArgs.Wrap("group member repeated")
|
||||||
}
|
}
|
||||||
users, err := getUsersInfo(ctx, userIDs)
|
userMap, err := getUserMap(ctx, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
userMap := make(map[string]*open_im_sdk.UserInfo)
|
|
||||||
for i, user := range users {
|
|
||||||
userMap[user.UserID] = users[i]
|
|
||||||
}
|
|
||||||
for _, userID := range userIDs {
|
for _, userID := range userIDs {
|
||||||
if userMap[userID] == nil {
|
if userMap[userID] == nil {
|
||||||
return nil, constant.ErrUserIDNotFound.Wrap(userID)
|
return nil, constant.ErrUserIDNotFound.Wrap(userID)
|
||||||
@ -254,10 +243,9 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
|||||||
if len(groups) == 0 {
|
if len(groups) == 0 {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
var groupIDs []string
|
groupIDs := utils.Slice(groups, func(e *relation2.GroupModel) string {
|
||||||
for _, group := range groups {
|
return e.GroupID
|
||||||
groupIDs = append(groupIDs, group.GroupID)
|
})
|
||||||
}
|
|
||||||
groupMemberNum, err := s.GroupInterface.GetGroupMemberNum(ctx, groupIDs)
|
groupMemberNum, err := s.GroupInterface.GetGroupMemberNum(ctx, groupIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -12,7 +12,7 @@ type GroupModel struct {
|
|||||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
CreateTime time.Time `gorm:"column:create_time;index:create_time;autoCreateTime"`
|
||||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||||
Status int32 `gorm:"column:status"`
|
Status int32 `gorm:"column:status"`
|
||||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||||
|
@ -144,6 +144,14 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Slice[E any, T any](es []E, fn func(e E) T) []T {
|
||||||
|
v := make([]T, len(es))
|
||||||
|
for i := 0; i < len(es); i++ {
|
||||||
|
v = append(v, fn(es[i]))
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// SliceSet slice to map[E]struct{}
|
// SliceSet slice to map[E]struct{}
|
||||||
func SliceSet[E comparable](es []E) map[E]struct{} {
|
func SliceSet[E comparable](es []E) map[E]struct{} {
|
||||||
return SliceSetAny(es, func(e E) E {
|
return SliceSetAny(es, func(e E) E {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user