Xinwei Xiong(cubxxw-openim) 166ddb1e34 style: add format
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
2023-07-10 18:13:29 +08:00

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
}