diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 9d716922a..53f43b60d 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -2,6 +2,7 @@ package user import ( "context" + "time" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" @@ -159,12 +160,18 @@ func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPagi // ok func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) { resp = &pbuser.UserRegisterResp{} + if len(req.Users) == 0 { + return nil, errs.ErrArgs.Wrap("users is empty") + } if utils.DuplicateAny(req.Users, func(e *sdkws.UserInfo) string { return e.UserID }) { return nil, errs.ErrArgs.Wrap("userID repeated") } userIDs := make([]string, 0) - for _, v := range req.Users { - userIDs = append(userIDs, v.UserID) + for _, user := range req.Users { + if user.UserID == "" { + return nil, errs.ErrArgs.Wrap("userID is empty") + } + userIDs = append(userIDs, user.UserID) } exist, err := s.IsExist(ctx, userIDs) if err != nil { @@ -173,12 +180,25 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR if exist { return nil, errs.ErrRegisteredAlready.Wrap("userID registered already") } - users, err := (*convert.PBUser)(nil).PB2DB(req.Users) - if err != nil { - return nil, err + now := time.Now() + users := make([]*tablerelation.UserModel, 0, len(req.Users)) + for _, user := range req.Users { + users = append(users, &tablerelation.UserModel{ + UserID: user.UserID, + Nickname: user.Nickname, + FaceURL: user.FaceURL, + Gender: user.Gender, + AreaCode: user.AreaCode, + PhoneNumber: user.PhoneNumber, + Birth: time.UnixMilli(user.Birth), + Email: user.Email, + Ex: user.Ex, + CreateTime: now, + AppMangerLevel: user.AppMangerLevel, + GlobalRecvMsgOpt: user.GlobalRecvMsgOpt, + }) } - err = s.Create(ctx, users) - if err != nil { + if err := s.Create(ctx, users); err != nil { return nil, err } return resp, nil diff --git a/pkg/proto/sdkws/sdkws.pb.go b/pkg/proto/sdkws/sdkws.pb.go index 77b832a19..efb78e109 100644 --- a/pkg/proto/sdkws/sdkws.pb.go +++ b/pkg/proto/sdkws/sdkws.pb.go @@ -530,14 +530,14 @@ type UserInfo struct { Nickname string `protobuf:"bytes,2,opt,name=nickname,proto3" json:"nickname"` FaceURL string `protobuf:"bytes,3,opt,name=faceURL,proto3" json:"faceURL"` Gender int32 `protobuf:"varint,4,opt,name=gender,proto3" json:"gender"` - PhoneNumber string `protobuf:"bytes,5,opt,name=phoneNumber,proto3" json:"phoneNumber"` - Birth uint32 `protobuf:"varint,6,opt,name=birth,proto3" json:"birth"` - Email string `protobuf:"bytes,7,opt,name=email,proto3" json:"email"` - Ex string `protobuf:"bytes,8,opt,name=ex,proto3" json:"ex"` - CreateTime int64 `protobuf:"varint,9,opt,name=createTime,proto3" json:"createTime"` - AppMangerLevel int32 `protobuf:"varint,10,opt,name=appMangerLevel,proto3" json:"appMangerLevel"` - GlobalRecvMsgOpt int32 `protobuf:"varint,11,opt,name=globalRecvMsgOpt,proto3" json:"globalRecvMsgOpt"` - Birthday int64 `protobuf:"varint,13,opt,name=birthday,proto3" json:"birthday"` + AreaCode string `protobuf:"bytes,5,opt,name=areaCode,proto3" json:"areaCode"` + PhoneNumber string `protobuf:"bytes,6,opt,name=phoneNumber,proto3" json:"phoneNumber"` + Birth int64 `protobuf:"varint,7,opt,name=birth,proto3" json:"birth"` + Email string `protobuf:"bytes,8,opt,name=email,proto3" json:"email"` + Ex string `protobuf:"bytes,9,opt,name=ex,proto3" json:"ex"` + CreateTime int64 `protobuf:"varint,10,opt,name=createTime,proto3" json:"createTime"` + AppMangerLevel int32 `protobuf:"varint,11,opt,name=appMangerLevel,proto3" json:"appMangerLevel"` + GlobalRecvMsgOpt int32 `protobuf:"varint,12,opt,name=globalRecvMsgOpt,proto3" json:"globalRecvMsgOpt"` } func (x *UserInfo) Reset() { @@ -600,6 +600,13 @@ func (x *UserInfo) GetGender() int32 { return 0 } +func (x *UserInfo) GetAreaCode() string { + if x != nil { + return x.AreaCode + } + return "" +} + func (x *UserInfo) GetPhoneNumber() string { if x != nil { return x.PhoneNumber @@ -607,7 +614,7 @@ func (x *UserInfo) GetPhoneNumber() string { return "" } -func (x *UserInfo) GetBirth() uint32 { +func (x *UserInfo) GetBirth() int64 { if x != nil { return x.Birth } @@ -649,13 +656,6 @@ func (x *UserInfo) GetGlobalRecvMsgOpt() int32 { return 0 } -func (x *UserInfo) GetBirthday() int64 { - if x != nil { - return x.Birthday - } - return 0 -} - type FriendInfo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -5969,22 +5969,22 @@ var file_sdkws_sdkws_proto_rawDesc = []byte{ 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x66, 0x61, 0x63, 0x65, 0x55, 0x52, 0x4c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x66, 0x61, 0x63, 0x65, 0x55, 0x52, 0x4c, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x20, 0x0a, - 0x0b, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0b, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, - 0x14, 0x0a, 0x05, 0x62, 0x69, 0x72, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, - 0x62, 0x69, 0x72, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x65, - 0x78, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x63, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x61, - 0x70, 0x70, 0x4d, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x0a, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x0e, 0x61, 0x70, 0x70, 0x4d, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x4c, 0x65, - 0x76, 0x65, 0x6c, 0x12, 0x2a, 0x0a, 0x10, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x52, 0x65, 0x63, - 0x76, 0x4d, 0x73, 0x67, 0x4f, 0x70, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x67, - 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x76, 0x4d, 0x73, 0x67, 0x4f, 0x70, 0x74, 0x12, - 0x1a, 0x0a, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x18, 0x0d, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x08, 0x62, 0x69, 0x72, 0x74, 0x68, 0x64, 0x61, 0x79, 0x22, 0xfa, 0x01, 0x0a, 0x0a, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x1a, 0x0a, + 0x08, 0x61, 0x72, 0x65, 0x61, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x61, 0x72, 0x65, 0x61, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x68, 0x6f, + 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x62, + 0x69, 0x72, 0x74, 0x68, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x62, 0x69, 0x72, 0x74, + 0x68, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x65, 0x78, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x4d, 0x61, + 0x6e, 0x67, 0x65, 0x72, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x0e, 0x61, 0x70, 0x70, 0x4d, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, + 0x2a, 0x0a, 0x10, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x52, 0x65, 0x63, 0x76, 0x4d, 0x73, 0x67, + 0x4f, 0x70, 0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x67, 0x6c, 0x6f, 0x62, 0x61, + 0x6c, 0x52, 0x65, 0x63, 0x76, 0x4d, 0x73, 0x67, 0x4f, 0x70, 0x74, 0x22, 0xfa, 0x01, 0x0a, 0x0a, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, diff --git a/pkg/proto/sdkws/sdkws.proto b/pkg/proto/sdkws/sdkws.proto index 3cff988f4..6dc942ee7 100644 --- a/pkg/proto/sdkws/sdkws.proto +++ b/pkg/proto/sdkws/sdkws.proto @@ -66,14 +66,14 @@ message UserInfo{ string nickname = 2; string faceURL = 3; int32 gender = 4; - string phoneNumber = 5; - uint32 birth = 6; - string email = 7; - string ex = 8; - int64 createTime = 9; - int32 appMangerLevel = 10; - int32 globalRecvMsgOpt = 11; - int64 birthday = 13; + string areaCode = 5; + string phoneNumber = 6; + int64 birth = 7; + string email = 8; + string ex = 9; + int64 createTime = 10; + int32 appMangerLevel = 11; + int32 globalRecvMsgOpt = 12; } message FriendInfo{