You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/rpcclient/check/friend.go

64 lines
1.8 KiB

package check
import (
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"google.golang.org/grpc"
)
type FriendChecker struct {
zk discoveryRegistry.SvcDiscoveryRegistry
}
func NewFriendChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *FriendChecker {
return &FriendChecker{
zk: zk,
}
}
func (f *FriendChecker) GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (resp *sdkws.FriendInfo, err error) {
cc, err := f.getConn()
if err != nil {
return nil, err
}
r, err := friend.NewFriendClient(cc).GetDesignatedFriends(ctx, &friend.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
if err != nil {
return nil, err
}
resp = r.FriendsInfo[0]
return
}
func (f *FriendChecker) getConn() (*grpc.ClientConn, error) {
return f.zk.GetConn(config.Config.RpcRegisterName.OpenImFriendName)
}
// possibleFriendUserID是否在userID的好友中
func (f *FriendChecker) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
cc, err := f.getConn()
if err != nil {
return false, err
}
resp, err := friend.NewFriendClient(cc).IsFriend(ctx, &friend.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID})
if err != nil {
return false, err
}
return resp.InUser1Friends, nil
}
2 years ago
func (f *FriendChecker) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) {
cc, err := f.getConn()
if err != nil {
return nil, err
}
2 years ago
req := friend.GetFriendIDsReq{UserID: ownerUserID}
resp, err := friend.NewFriendClient(cc).GetFriendIDs(ctx, &req)
if err != nil {
return nil, err
}
2 years ago
return resp.FriendIDs, err
}