commit
4cb7a286b9
@ -1,21 +1,106 @@
|
|||||||
package check
|
package check
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||||
|
"Open_IM/pkg/proto/group"
|
||||||
sdkws "Open_IM/pkg/proto/sdkws"
|
sdkws "Open_IM/pkg/proto/sdkws"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"google.golang.org/grpc"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GroupChecker struct{}
|
type GroupChecker struct {
|
||||||
|
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGroupChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *GroupChecker {
|
||||||
|
return &GroupChecker{
|
||||||
|
zk: zk,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupChecker) getConn() (*grpc.ClientConn, error) {
|
||||||
|
return g.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupChecker) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
||||||
|
cc, err := g.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := group.NewGroupClient(cc).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||||
|
GroupIDs: groupIDs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if complete {
|
||||||
|
if ids := utils.Single(groupIDs, utils.Slice(resp.GroupInfos, func(e *sdkws.GroupInfo) string {
|
||||||
|
return e.GroupID
|
||||||
|
})); len(ids) > 0 {
|
||||||
|
return nil, constant.ErrGroupIDNotFound.Wrap(strings.Join(ids, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.GroupInfos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupChecker) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
||||||
|
groups, err := g.GetGroupInfos(ctx, []string{groupID}, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return groups[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GroupChecker) GetGroupInfoMap(ctx context.Context, groupIDs []string, complete bool) (map[string]*sdkws.GroupInfo, error) {
|
||||||
|
groups, err := g.GetGroupInfos(ctx, groupIDs, complete)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.SliceToMap(groups, func(e *sdkws.GroupInfo) string {
|
||||||
|
return e.GroupID
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewGroupChecker() GroupChecker {
|
func (g *GroupChecker) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||||
return GroupChecker{}
|
cc, err := g.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := group.NewGroupClient(cc).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
||||||
|
GroupID: groupID,
|
||||||
|
Members: userIDs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if complete {
|
||||||
|
if ids := utils.Single(userIDs, utils.Slice(resp.Members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||||
|
return e.UserID
|
||||||
|
})); len(ids) > 0 {
|
||||||
|
return nil, constant.ErrNotInGroupYet.Wrap(strings.Join(ids, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.Members, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GroupChecker) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
func (g *GroupChecker) GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||||
return nil, errors.New("TODO:GetUserInfo")
|
members, err := g.GetGroupMemberInfos(ctx, groupID, []string{userID}, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return members[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (GroupChecker) GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
|
func (g *GroupChecker) GetGroupMemberInfoMap(ctx context.Context, groupID string, userIDs []string, complete bool) (map[string]*sdkws.GroupMemberFullInfo, error) {
|
||||||
return nil, errors.New("TODO:GetUserInfo")
|
members, err := g.GetGroupMemberInfos(ctx, groupID, userIDs, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||||
|
return e.UserID
|
||||||
|
}), nil
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,104 @@
|
|||||||
package check
|
package check
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||||
sdkws "Open_IM/pkg/proto/sdkws"
|
sdkws "Open_IM/pkg/proto/sdkws"
|
||||||
|
"Open_IM/pkg/proto/user"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"google.golang.org/grpc"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
//func GetUsersInfo(ctx context.Context, args ...interface{}) ([]*sdkws.UserInfo, error) {
|
//func GetUsersInfo(ctx context.Context, args ...interface{}) ([]*sdkws.UserInfo, error) {
|
||||||
// return nil, errors.New("TODO:GetUserInfo")
|
// return nil, errors.New("TODO:GetUserInfo")
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func NewUserCheck() UserCheck {
|
func NewUserCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *UserCheck {
|
||||||
return UserCheck{}
|
return &UserCheck{
|
||||||
|
zk: zk,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserCheck struct{}
|
type UserCheck struct {
|
||||||
|
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserCheck) getConn() (*grpc.ClientConn, error) {
|
||||||
|
return u.zk.GetConn(config.Config.RpcRegisterName.OpenImUserName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
|
||||||
|
cc, err := u.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := user.NewUserClient(cc).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||||
|
UserIDs: userIDs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if complete {
|
||||||
|
if ids := utils.Single(userIDs, utils.Slice(resp.UsersInfo, func(e *sdkws.UserInfo) string {
|
||||||
|
return e.UserID
|
||||||
|
})); len(ids) > 0 {
|
||||||
|
return nil, constant.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.UsersInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
|
func (u *UserCheck) GetUsersInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||||
return nil, errors.New("todo")
|
users, err := u.GetUsersInfos(ctx, []string{userID}, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return users[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
|
func (u *UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
|
||||||
return nil, errors.New("todo")
|
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||||
|
return e.UserID
|
||||||
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
func (u *UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
|
||||||
return nil, errors.New("todo")
|
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
|
||||||
|
return &sdkws.PublicUserInfo{
|
||||||
|
UserID: e.UserID,
|
||||||
|
Nickname: e.Nickname,
|
||||||
|
FaceURL: e.FaceURL,
|
||||||
|
Gender: e.Gender,
|
||||||
|
Ex: e.Ex,
|
||||||
|
}
|
||||||
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
|
func (u *UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||||
return nil, errors.New("todo")
|
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return users[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
|
func (u *UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
|
||||||
return nil, errors.New("todo")
|
users, err := u.GetPublicUserInfos(ctx, userIDs, complete)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||||
|
return e.UserID
|
||||||
|
}), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue