test-errcode
withchao 2 years ago
commit d4b125d010

@ -5,6 +5,7 @@ import (
"Open_IM/pkg/common/db/table/relation" "Open_IM/pkg/common/db/table/relation"
discoveryRegistry "Open_IM/pkg/discoveryregistry" discoveryRegistry "Open_IM/pkg/discoveryregistry"
sdk "Open_IM/pkg/proto/sdkws" sdk "Open_IM/pkg/proto/sdkws"
utils2 "Open_IM/pkg/utils"
"context" "context"
utils "github.com/OpenIMSDK/open_utils" utils "github.com/OpenIMSDK/open_utils"
"time" "time"
@ -38,13 +39,18 @@ func (*PBFriend) PB2DB(friends []*sdk.FriendInfo) (DBFriends []*relation.FriendM
return return
} }
func (*DBFriend) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, friends []*relation.FriendModel) (PBFriends []*sdk.FriendInfo, err error) { func (db *DBFriend) DB2PB(ctx context.Context, friends []*relation.FriendModel) (PBFriends []*sdk.FriendInfo, err error) {
for _, v := range friends { userIDs := utils2.Slice(friends, func(e *relation.FriendModel) string { return e.FriendUserID })
u, err := NewDBFriend(v, zk).Convert(ctx) users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
PBFriends = append(PBFriends, u) for _, v := range friends {
pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
utils.CopyStructFields(pbFriend, users[v.OwnerUserID])
utils.CopyStructFields(pbFriend.FriendUser, users[v.FriendUserID])
pbFriend.CreateTime = v.CreateTime.Unix()
pbFriend.FriendUser.CreateTime = v.CreateTime.Unix()
} }
return return
} }
@ -99,13 +105,26 @@ func (*PBFriendRequest) PB2DB(friendRequests []*sdk.FriendRequest) (DBFriendRequ
return return
} }
func (*DBFriendRequest) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, friendRequests []*relation.FriendRequestModel) (PBFriendRequests []*sdk.FriendRequest, err error) { func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation.FriendRequestModel) (PBFriendRequests []*sdk.FriendRequest, err error) {
for _, v := range friendRequests { userIDs := make([]string, 0)
u, err := NewDBFriendRequest(v, zk).Convert(ctx) if len(friendRequests) > 0 {
userIDs = append(userIDs, friendRequests[0].FromUserID)
}
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
PBFriendRequests = append(PBFriendRequests, u) for _, v := range friendRequests {
pbFriendRequest := &sdk.FriendRequest{}
pbFriendRequest.FromNickname = users[v.FromUserID].Nickname
pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL
pbFriendRequest.FromGender = users[v.FromUserID].Gender
pbFriendRequest.ToNickname = users[v.ToUserID].Nickname
pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL
pbFriendRequest.ToGender = users[v.ToUserID].Gender
pbFriendRequest.CreateTime = db.CreateTime.Unix()
pbFriendRequest.HandleTime = db.HandleTime.Unix()
PBFriendRequests = append(PBFriendRequests, pbFriendRequest)
} }
return return
} }
@ -155,13 +174,25 @@ func (*PBBlack) PB2DB(blacks []*sdk.BlackInfo) (DBBlacks []*relation.BlackModel,
return return
} }
func (*DBBlack) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, blacks []*relation.BlackModel) (PBBlacks []*sdk.BlackInfo, err error) { func (db *DBBlack) DB2PB(ctx context.Context, blacks []*relation.BlackModel) (PBBlacks []*sdk.BlackInfo, err error) {
userIDs := make([]string, 0)
for _, v := range blacks { for _, v := range blacks {
u, err := NewDBBlack(v, zk).Convert(ctx) userIDs = append(userIDs, v.BlockUserID)
}
if len(blacks) > 0 {
userIDs = append(userIDs, blacks[0].OwnerUserID)
}
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
if err != nil { if err != nil {
return nil, err return nil, err
} }
PBBlacks = append(PBBlacks, u)
for _, v := range blacks {
pbBlack := &sdk.BlackInfo{}
utils.CopyStructFields(pbBlack, users[v.OwnerUserID])
utils.CopyStructFields(pbBlack.BlackUserInfo, users[v.BlockUserID])
PBBlacks = append(PBBlacks, pbBlack)
} }
return return
} }
@ -181,7 +212,7 @@ func NewPBBlack(blackInfo *sdk.BlackInfo) *PBBlack {
func (pb *PBBlack) Convert() (*relation.BlackModel, error) { func (pb *PBBlack) Convert() (*relation.BlackModel, error) {
dbBlack := &relation.BlackModel{} dbBlack := &relation.BlackModel{}
dbBlack.BlockUserID = pb.BlackUserInfo.UserID dbBlack.BlockUserID = pb.BlackUserInfo.UserID
dbBlack.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime)) dbBlack.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
return dbBlack, nil return dbBlack, nil
} }
func (db *DBBlack) Convert(ctx context.Context) (*sdk.BlackInfo, error) { func (db *DBBlack) Convert(ctx context.Context) (*sdk.BlackInfo, error) {
@ -213,16 +244,16 @@ func (*PBGroup) PB2DB(groups []*sdk.GroupInfo) (DBGroups []*relation.GroupModel,
return return
} }
func (db *DBGroup) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, groups []*relation.GroupModel) (PBGroups []*sdk.GroupInfo, err error) { //func (db *DBGroup) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, groups []*relation.GroupModel) (PBGroups []*sdk.GroupInfo, err error) {
for _, v := range groups { // for _, v := range groups {
u, err := NewDBGroup(v, zk).Convert(ctx) // u, err := NewDBGroup(v, zk).Convert(ctx)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroups = append(PBGroups, u) // PBGroups = append(PBGroups, u)
} // }
return // return
} //}
func NewDBGroup(groupModel *relation.GroupModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBGroup { func NewDBGroup(groupModel *relation.GroupModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBGroup {
return &DBGroup{GroupModel: groupModel, groupCheck: check.NewGroupChecker(zk)} return &DBGroup{GroupModel: groupModel, groupCheck: check.NewGroupChecker(zk)}
@ -279,16 +310,16 @@ func (*PBGroupMember) PB2DB(groupMembers []*sdk.GroupMemberFullInfo) (DBGroupMem
return return
} }
func (*DBGroupMember) DB2PB(ctx context.Context, groupMembers []*relation.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) { //func (*DBGroupMember) DB2PB(ctx context.Context, groupMembers []*relation.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) {
for _, v := range groupMembers { // for _, v := range groupMembers {
u, err := NewDBGroupMember(v).Convert(ctx) // u, err := NewDBGroupMember(v).Convert(ctx)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroupMembers = append(PBGroupMembers, u) // PBGroupMembers = append(PBGroupMembers, u)
} // }
return // return
} //}
func NewDBGroupMember(groupMember *relation.GroupMemberModel) *DBGroupMember { func NewDBGroupMember(groupMember *relation.GroupMemberModel) *DBGroupMember {
return &DBGroupMember{GroupMemberModel: groupMember} return &DBGroupMember{GroupMemberModel: groupMember}
@ -345,16 +376,16 @@ func (*PBGroupRequest) PB2DB(groupRequests []*sdk.GroupRequest) (DBGroupRequests
return return
} }
func (*DBGroupRequest) DB2PB(groupRequests []*relation.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) { //func (*DBGroupRequest) DB2PB(groupRequests []*relation.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) {
for _, v := range groupRequests { // for _, v := range groupRequests {
u, err := NewDBGroupRequest(v).Convert() // u, err := NewDBGroupRequest(v).Convert()
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
PBGroupRequests = append(PBGroupRequests, u) // PBGroupRequests = append(PBGroupRequests, u)
} // }
return // return
} //}
func NewDBGroupRequest(groupRequest *relation.GroupRequestModel) *DBGroupRequest { func NewDBGroupRequest(groupRequest *relation.GroupRequestModel) *DBGroupRequest {
return &DBGroupRequest{GroupRequestModel: groupRequest} return &DBGroupRequest{GroupRequestModel: groupRequest}

@ -18,7 +18,7 @@ func (s *friendServer) GetPaginationBlacks(ctx context.Context, req *pbFriend.Ge
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Blacks, err = (*convert.DBBlack)(nil).DB2PB(blacks) resp.Blacks, err = (*convert.NewDBBlack(nil, s.RegisterCenter)).DB2PB(ctx, blacks)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -217,7 +217,7 @@ func (s *friendServer) GetDesignatedFriends(ctx context.Context, req *pbFriend.G
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(ctx, s.RegisterCenter, friends) resp.FriendsInfo, err = (*convert.NewDBFriend(nil, s.RegisterCenter)).DB2PB(ctx, friends)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -235,7 +235,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbF
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendRequests, err = (*convert.DBFriendRequest)(nil).DB2PB(ctx, s.RegisterCenter, friendRequests) resp.FriendRequests, err = (*convert.NewDBFriendRequest(nil, s.RegisterCenter)).DB2PB(ctx, friendRequests)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -253,7 +253,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendRequests, err = (*convert.DBFriendRequest)(nil).DB2PB(ctx, s.RegisterCenter, friendRequests) resp.FriendRequests, err = (*convert.NewDBFriendRequest(nil, s.RegisterCenter)).DB2PB(ctx, friendRequests)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -281,7 +281,7 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbFriend.G
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(ctx, s.RegisterCenter, friends); err != nil { if resp.FriendsInfo, err = (*convert.NewDBFriend(nil, s.RegisterCenter)).DB2PB(ctx, friends); err != nil {
return nil, err return nil, err
} }
return resp, nil return resp, nil

Loading…
Cancel
Save