Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/232/head
Gordon 3 years ago
commit 37596589a7

@ -287,6 +287,7 @@ func CreateGroup(c *gin.Context) {
req.OwnerUserID = params.OwnerUserID req.OwnerUserID = params.OwnerUserID
req.OperationID = params.OperationID req.OperationID = params.OperationID
log.NewInfo(req.OperationID, "CreateGroup args ", req.String()) log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)

@ -97,8 +97,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeCreateGroup failed") log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeCreateGroup failed")
} }
} }
//Time stamp + MD5 to generate group chat id
groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) groupId := req.GroupInfo.GroupID
if groupId == "" {
groupId = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
}
//to group //to group
groupInfo := db.Group{} groupInfo := db.Group{}
utils.CopyStructFields(&groupInfo, req.GroupInfo) utils.CopyStructFields(&groupInfo, req.GroupInfo)
@ -109,15 +112,19 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo) log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
} }
groupMember := db.GroupMember{}
us, err := imdb.GetUserByUserID(req.OwnerUserID) us := &db.User{}
if req.OwnerUserID == "" {
goto initMemberList
}
us, err = imdb.GetUserByUserID(req.OwnerUserID)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID) log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
} }
//to group member //to group member
groupMember := db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID} groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
utils.CopyStructFields(&groupMember, us) utils.CopyStructFields(&groupMember, us)
err = imdb.InsertIntoGroupMember(groupMember) err = imdb.InsertIntoGroupMember(groupMember)
if err != nil { if err != nil {
@ -125,10 +132,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
} }
err = db.DB.AddGroupMember(groupId, req.OwnerUserID) initMemberList:
if err != nil {
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, req.OwnerUserID)
}
var okUserIDList []string var okUserIDList []string
//to group member //to group member
for _, user := range req.InitMemberList { for _, user := range req.InitMemberList {
@ -148,20 +152,14 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
continue continue
} }
okUserIDList = append(okUserIDList, user.UserID) okUserIDList = append(okUserIDList, user.UserID)
// mongoDB method
//err = db.DB.AddGroupMember(groupId, user.UserID)
//if err != nil {
// log.NewError(req.OperationID, "add mongo group member failed, db.DB.AddGroupMember failed ", err.Error())
//}
} }
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}} resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
group, err := imdb.GetGroupInfoByGroupID(groupId) group, err := imdb.GetGroupInfoByGroupID(groupId)
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupId) log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg resp.ErrMsg = err.Error()
return resp, nil return resp, nil
} }
utils.CopyStructFields(resp.GroupInfo, group) utils.CopyStructFields(resp.GroupInfo, group)
@ -169,12 +167,15 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
if err != nil { if err != nil {
log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId) log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg resp.ErrMsg = err.Error()
return resp, nil return resp, nil
} }
if req.OwnerUserID != "" {
resp.GroupInfo.OwnerUserID = req.OwnerUserID resp.GroupInfo.OwnerUserID = req.OwnerUserID
okUserIDList = append(okUserIDList, req.OwnerUserID) okUserIDList = append(okUserIDList, req.OwnerUserID)
}
if len(okUserIDList) != 0 {
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{ addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
UserIDList: okUserIDList, UserIDList: okUserIDList,
GroupID: groupId, GroupID: groupId,
@ -195,6 +196,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String()) log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList) chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
return resp, nil return resp, nil
} else {
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
return resp, nil
}
} }
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) { func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {

@ -81,8 +81,8 @@ type GetGroupAllMemberResp struct {
} }
type CreateGroupReq struct { type CreateGroupReq struct {
MemberList []*GroupAddMemberInfo `json:"memberList" binding:"required"` MemberList []*GroupAddMemberInfo `json:"memberList"`
OwnerUserID string `json:"ownerUserID" binding:"required"` OwnerUserID string `json:"ownerUserID"`
GroupType int32 `json:"groupType"` GroupType int32 `json:"groupType"`
GroupName string `json:"groupName"` GroupName string `json:"groupName"`
Notification string `json:"notification"` Notification string `json:"notification"`
@ -90,6 +90,7 @@ type CreateGroupReq struct {
FaceURL string `json:"faceURL"` FaceURL string `json:"faceURL"`
Ex string `json:"ex"` Ex string `json:"ex"`
OperationID string `json:"operationID" binding:"required"` OperationID string `json:"operationID" binding:"required"`
GroupID string `json:"groupID"`
} }
type CreateGroupResp struct { type CreateGroupResp struct {
CommResp CommResp

Loading…
Cancel
Save