parent
7c7a99f801
commit
77386cd897
@ -1,74 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/auth"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewAuth(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Auth {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
client := auth.NewAuthClient(conn)
|
|
||||||
return &Auth{discov: discov, conn: conn, Client: client}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Auth struct {
|
|
||||||
conn grpc.ClientConnInterface
|
|
||||||
Client auth.AuthClient
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) ParseToken(ctx context.Context, token string) (*auth.ParseTokenResp, error) {
|
|
||||||
req := auth.ParseTokenReq{
|
|
||||||
Token: token,
|
|
||||||
}
|
|
||||||
resp, err := a.Client.ParseToken(ctx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) InvalidateToken(ctx context.Context, preservedToken, userID string, platformID int) (*auth.InvalidateTokenResp, error) {
|
|
||||||
req := auth.InvalidateTokenReq{
|
|
||||||
PreservedToken: preservedToken,
|
|
||||||
UserID: userID,
|
|
||||||
PlatformID: int32(platformID),
|
|
||||||
}
|
|
||||||
resp, err := a.Client.InvalidateToken(ctx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *Auth) KickTokens(ctx context.Context, tokens []string) (*auth.KickTokensResp, error) {
|
|
||||||
req := auth.KickTokensReq{
|
|
||||||
Tokens: tokens,
|
|
||||||
}
|
|
||||||
resp, err := a.Client.KickTokens(ctx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
@ -1,161 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
pbconversation "github.com/openimsdk/protocol/conversation"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/errs"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Conversation struct {
|
|
||||||
Client pbconversation.ConversationClient
|
|
||||||
conn grpc.ClientConnInterface
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConversation(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Conversation {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
client := pbconversation.NewConversationClient(conn)
|
|
||||||
return &Conversation{discov: discov, conn: conn, Client: client}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConversationRpcClient Conversation
|
|
||||||
|
|
||||||
func NewConversationRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) ConversationRpcClient {
|
|
||||||
return ConversationRpcClient(*NewConversation(discov, rpcRegisterName))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
|
|
||||||
var req pbconversation.GetConversationReq
|
|
||||||
req.OwnerUserID = userID
|
|
||||||
req.ConversationID = conversationID
|
|
||||||
conversation, err := c.Client.GetConversation(ctx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return conversation.GetConversation().RecvMsgOpt, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID,
|
|
||||||
conversationID string, conversationType int32) error {
|
|
||||||
_, err := c.Client.CreateSingleChatConversations(ctx,
|
|
||||||
&pbconversation.CreateSingleChatConversationsReq{
|
|
||||||
RecvID: recvID, SendID: sendID, ConversationID: conversationID,
|
|
||||||
ConversationType: conversationType,
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
|
|
||||||
_, err := c.Client.CreateGroupChatConversations(ctx, &pbconversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error {
|
|
||||||
_, err := c.Client.SetConversationMaxSeq(ctx, &pbconversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) SetConversationMinSeq(ctx context.Context, ownerUserIDs []string, conversationID string, minSeq int64) error {
|
|
||||||
_, err := c.Client.SetConversationMinSeq(ctx, &pbconversation.SetConversationMinSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MinSeq: minSeq})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbconversation.ConversationReq) error {
|
|
||||||
_, err := c.Client.SetConversations(ctx, &pbconversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) UpdateConversation(ctx context.Context, conversation *pbconversation.UpdateConversationReq) error {
|
|
||||||
_, err := c.Client.UpdateConversation(ctx, conversation)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
|
||||||
resp, err := c.Client.GetConversationIDs(ctx, &pbconversation.GetConversationIDsReq{UserID: ownerUserID})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.ConversationIDs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbconversation.Conversation, error) {
|
|
||||||
resp, err := c.Client.GetConversation(ctx, &pbconversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Conversation, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbconversation.Conversation, error) {
|
|
||||||
if len(conversationIDs) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbconversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(resp.Conversations) == 0 {
|
|
||||||
return nil, errs.ErrRecordNotFound.WrapMsg(fmt.Sprintf("conversationIDs: %v not found", conversationIDs))
|
|
||||||
}
|
|
||||||
return resp.Conversations, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversationOfflinePushUserIDs(ctx context.Context, conversationID string, userIDs []string) ([]string, error) {
|
|
||||||
resp, err := c.Client.GetConversationOfflinePushUserIDs(ctx, &pbconversation.GetConversationOfflinePushUserIDsReq{ConversationID: conversationID, UserIDs: userIDs})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.UserIDs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbconversation.Conversation, error) {
|
|
||||||
if len(conversationIDs) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
resp, err := c.Client.GetConversations(
|
|
||||||
ctx,
|
|
||||||
&pbconversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Conversations, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversationNotReceiveMessageUserIDs(ctx context.Context, conversationID string) ([]string, error) {
|
|
||||||
resp, err := c.Client.GetConversationNotReceiveMessageUserIDs(ctx, &pbconversation.GetConversationNotReceiveMessageUserIDsReq{ConversationID: conversationID})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.UserIDs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConversationRpcClient) GetConversationsNeedClearMsg(ctx context.Context) ([]*pbconversation.Conversation, error) {
|
|
||||||
resp, err := c.Client.GetConversationsNeedClearMsg(ctx, &pbconversation.GetConversationsNeedClearMsgReq{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Conversations, nil
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/relation"
|
|
||||||
sdkws "github.com/openimsdk/protocol/sdkws"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Friend struct {
|
|
||||||
conn grpc.ClientConnInterface
|
|
||||||
Client relation.FriendClient
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFriend(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Friend {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
client := relation.NewFriendClient(conn)
|
|
||||||
return &Friend{discov: discov, conn: conn, Client: client}
|
|
||||||
}
|
|
||||||
|
|
||||||
type FriendRpcClient Friend
|
|
||||||
|
|
||||||
func NewFriendRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) FriendRpcClient {
|
|
||||||
return FriendRpcClient(*NewFriend(discov, rpcRegisterName))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendRpcClient) GetFriendsInfo(
|
|
||||||
ctx context.Context,
|
|
||||||
ownerUserID, relationUserID string,
|
|
||||||
) (resp *sdkws.FriendInfo, err error) {
|
|
||||||
r, err := f.Client.GetDesignatedFriends(
|
|
||||||
ctx,
|
|
||||||
&relation.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{relationUserID}},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
resp = r.FriendsInfo[0]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// possibleFriendUserID Is PossibleFriendUserId's relations.
|
|
||||||
func (f *FriendRpcClient) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
|
|
||||||
resp, err := f.Client.IsFriend(ctx, &relation.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID})
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return resp.InUser1Friends, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendRpcClient) GetFriendIDs(ctx context.Context, ownerUserID string) (relationIDs []string, err error) {
|
|
||||||
req := relation.GetFriendIDsReq{UserID: ownerUserID}
|
|
||||||
resp, err := f.Client.GetFriendIDs(ctx, &req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.FriendIDs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendRpcClient) IsBlack(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
|
||||||
r, err := f.Client.IsBlack(ctx, &relation.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return r.InUser2Blacks, nil
|
|
||||||
}
|
|
@ -1,205 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
|
||||||
"github.com/openimsdk/protocol/group"
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Group struct {
|
|
||||||
Client group.GroupClient
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGroup(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Group {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
client := group.NewGroupClient(conn)
|
|
||||||
return &Group{discov: discov, Client: client}
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupRpcClient Group
|
|
||||||
|
|
||||||
func NewGroupRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) GroupRpcClient {
|
|
||||||
return GroupRpcClient(*NewGroup(discov, rpcRegisterName))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
|
||||||
GroupIDs: groupIDs,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if complete {
|
|
||||||
if ids := datautil.Single(groupIDs, datautil.Slice(resp.GroupInfos, func(e *sdkws.GroupInfo) string {
|
|
||||||
return e.GroupID
|
|
||||||
})); len(ids) > 0 {
|
|
||||||
return nil, servererrs.ErrGroupIDNotFound.WrapMsg(strings.Join(ids, ","))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp.GroupInfos, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) 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 *GroupRpcClient) 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 datautil.SliceToMap(groups, func(e *sdkws.GroupInfo) string {
|
|
||||||
return e.GroupID
|
|
||||||
}), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberInfos(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
userIDs []string,
|
|
||||||
complete bool,
|
|
||||||
) ([]*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
UserIDs: userIDs,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if complete {
|
|
||||||
if ids := datautil.Single(userIDs, datautil.Slice(resp.Members, func(e *sdkws.GroupMemberFullInfo) string {
|
|
||||||
return e.UserID
|
|
||||||
})); len(ids) > 0 {
|
|
||||||
return nil, servererrs.ErrNotInGroupYet.WrapMsg(strings.Join(ids, ","))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp.Members, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberInfo(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
userID string,
|
|
||||||
) (*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
members, err := g.GetGroupMemberInfos(ctx, groupID, []string{userID}, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return members[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberInfoMap(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
userIDs []string,
|
|
||||||
complete bool,
|
|
||||||
) (map[string]*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
members, err := g.GetGroupMemberInfos(ctx, groupID, userIDs, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return datautil.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
|
||||||
return e.UserID
|
|
||||||
}), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetOwnerAndAdminInfos(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
) ([]*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Members, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
RoleLevels: []int32{constant.GroupOwner},
|
|
||||||
})
|
|
||||||
return resp.Members[0], err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
|
|
||||||
resp, err := g.Client.GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.UserIDs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupInfoCache(ctx, &group.GetGroupInfoCacheReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.GroupInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberCache(ctx context.Context, groupID string, groupMemberID string) (*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupMemberCache(ctx, &group.GetGroupMemberCacheReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
GroupMemberID: groupMemberID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Member, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error {
|
|
||||||
_, err := g.Client.DismissGroup(ctx, &group.DismissGroupReq{
|
|
||||||
GroupID: groupID,
|
|
||||||
DeleteMember: true,
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *GroupRpcClient) NotificationUserInfoUpdate(ctx context.Context, userID string) error {
|
|
||||||
_, err := g.Client.NotificationUserInfoUpdate(ctx, &group.NotificationUserInfoUpdateReq{
|
|
||||||
UserID: userID,
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
@ -0,0 +1,60 @@
|
|||||||
|
package rpcclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
pbauth "github.com/openimsdk/protocol/auth"
|
||||||
|
pbconversation "github.com/openimsdk/protocol/conversation"
|
||||||
|
pbgroup "github.com/openimsdk/protocol/group"
|
||||||
|
pbmsg "github.com/openimsdk/protocol/msg"
|
||||||
|
pbmsggateway "github.com/openimsdk/protocol/msggateway"
|
||||||
|
pbpush "github.com/openimsdk/protocol/push"
|
||||||
|
pbrelation "github.com/openimsdk/protocol/relation"
|
||||||
|
pbthird "github.com/openimsdk/protocol/third"
|
||||||
|
pbuser "github.com/openimsdk/protocol/user"
|
||||||
|
"github.com/openimsdk/tools/discovery"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitRpcCaller(discov discovery.SvcDiscoveryRegistry, service config.RpcService) error {
|
||||||
|
initConn := func(discov discovery.SvcDiscoveryRegistry, name string, initFunc func(conn *grpc.ClientConn)) error {
|
||||||
|
conn, err := discov.GetConn(context.Background(), name)
|
||||||
|
if err != nil {
|
||||||
|
program.ExitWithError(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
initFunc(conn)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Auth, pbauth.InitAuth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Conversation, pbconversation.InitConversation); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Group, pbgroup.InitGroup); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Msg, pbmsg.InitMsg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.MessageGateway, pbmsggateway.InitMsgGateway); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Push, pbpush.InitPushMsgService); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Friend, pbrelation.InitFriend); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.Third, pbthird.InitThird); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := initConn(discov, service.User, pbuser.InitUser); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/push"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Push struct {
|
|
||||||
conn grpc.ClientConnInterface
|
|
||||||
Client push.PushMsgServiceClient
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPush(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Push {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
return &Push{
|
|
||||||
discov: discov,
|
|
||||||
conn: conn,
|
|
||||||
Client: push.NewPushMsgServiceClient(conn),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type PushRpcClient Push
|
|
||||||
|
|
||||||
func NewPushRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) PushRpcClient {
|
|
||||||
return PushRpcClient(*NewPush(discov, rpcRegisterName))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PushRpcClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
|
|
||||||
return p.Client.DelUserPushToken(ctx, req)
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package rpcclient
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/third"
|
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Third struct {
|
|
||||||
conn grpc.ClientConnInterface
|
|
||||||
Client third.ThirdClient
|
|
||||||
discov discovery.SvcDiscoveryRegistry
|
|
||||||
GrafanaUrl string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewThird(discov discovery.SvcDiscoveryRegistry, rpcRegisterName, grafanaUrl string) *Third {
|
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
client := third.NewThirdClient(conn)
|
|
||||||
if err != nil {
|
|
||||||
program.ExitWithError(err)
|
|
||||||
}
|
|
||||||
return &Third{discov: discov, Client: client, conn: conn, GrafanaUrl: grafanaUrl}
|
|
||||||
}
|
|
||||||
func (t *Third) DeleteOutdatedData(ctx context.Context, expires int64) error {
|
|
||||||
_, err := t.Client.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{ExpireTime: expires})
|
|
||||||
return err
|
|
||||||
}
|
|
Loading…
Reference in new issue