mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 20:11:14 +08:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package convert
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
|
sdk "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
|
)
|
|
|
|
func BlackDB2Pb(
|
|
ctx context.Context,
|
|
blackDBs []*relation.BlackModel,
|
|
f func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
|
) (blackPbs []*sdk.BlackInfo, err error) {
|
|
var userIDs []string
|
|
for _, blackDB := range blackDBs {
|
|
userIDs = append(userIDs, blackDB.BlockUserID)
|
|
}
|
|
userInfos, err := f(ctx, userIDs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, blackDB := range blackDBs {
|
|
blackPb := &sdk.BlackInfo{
|
|
OwnerUserID: blackDB.OwnerUserID,
|
|
CreateTime: blackDB.CreateTime.Unix(),
|
|
AddSource: blackDB.AddSource,
|
|
Ex: blackDB.Ex,
|
|
OperatorUserID: blackDB.OperatorUserID,
|
|
BlackUserInfo: &sdkws.PublicUserInfo{
|
|
UserID: userInfos[blackDB.BlockUserID].UserID,
|
|
Nickname: userInfos[blackDB.BlockUserID].Nickname,
|
|
FaceURL: userInfos[blackDB.BlockUserID].FaceURL,
|
|
Ex: userInfos[blackDB.BlockUserID].Ex,
|
|
},
|
|
}
|
|
blackPbs = append(blackPbs, blackPb)
|
|
}
|
|
return blackPbs, nil
|
|
}
|