|
|
@ -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) {
|
|
|
|
|
|
|
|
userIDs := utils2.Slice(friends, func(e *relation.FriendModel) string { return e.FriendUserID })
|
|
|
|
|
|
|
|
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, v := range friends {
|
|
|
|
for _, v := range friends {
|
|
|
|
u, err := NewDBFriend(v, zk).Convert(ctx)
|
|
|
|
pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
|
|
|
if err != nil {
|
|
|
|
utils.CopyStructFields(pbFriend, users[v.OwnerUserID])
|
|
|
|
return nil, err
|
|
|
|
utils.CopyStructFields(pbFriend.FriendUser, users[v.FriendUserID])
|
|
|
|
}
|
|
|
|
pbFriend.CreateTime = v.CreateTime.Unix()
|
|
|
|
PBFriends = append(PBFriends, u)
|
|
|
|
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) {
|
|
|
|
|
|
|
|
userIDs := make([]string, 0)
|
|
|
|
|
|
|
|
if len(friendRequests) > 0 {
|
|
|
|
|
|
|
|
userIDs = append(userIDs, friendRequests[0].FromUserID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, v := range friendRequests {
|
|
|
|
for _, v := range friendRequests {
|
|
|
|
u, err := NewDBFriendRequest(v, zk).Convert(ctx)
|
|
|
|
pbFriendRequest := &sdk.FriendRequest{}
|
|
|
|
if err != nil {
|
|
|
|
pbFriendRequest.FromNickname = users[v.FromUserID].Nickname
|
|
|
|
return nil, err
|
|
|
|
pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL
|
|
|
|
}
|
|
|
|
pbFriendRequest.FromGender = users[v.FromUserID].Gender
|
|
|
|
PBFriendRequests = append(PBFriendRequests, u)
|
|
|
|
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 err != nil {
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
if len(blacks) > 0 {
|
|
|
|
}
|
|
|
|
userIDs = append(userIDs, blacks[0].OwnerUserID)
|
|
|
|
PBBlacks = append(PBBlacks, u)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|