parent
d3b2587743
commit
2676295a4c
@ -1,32 +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 api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/a2r"
|
||||
)
|
||||
|
||||
type StatisticsApi rpcclient.User
|
||||
|
||||
func NewStatisticsApi(client rpcclient.User) StatisticsApi {
|
||||
return StatisticsApi(client)
|
||||
}
|
||||
|
||||
func (s *StatisticsApi) UserRegister(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.UserRegisterCount, s.Client, c)
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
)
|
||||
|
||||
const StreamDeadlineTime = time.Second * 60 * 10
|
||||
|
||||
func (m *msgServer) handlerStreamMsg(ctx context.Context, msgData *sdkws.MsgData) error {
|
||||
now := time.Now()
|
||||
val := &model.StreamMsg{
|
||||
ClientMsgID: msgData.ClientMsgID,
|
||||
ConversationID: msgprocessor.GetConversationIDByMsg(msgData),
|
||||
UserID: msgData.SendID,
|
||||
CreateTime: now,
|
||||
DeadlineTime: now.Add(StreamDeadlineTime),
|
||||
}
|
||||
return m.StreamMsgDatabase.CreateStreamMsg(ctx, val)
|
||||
}
|
||||
|
||||
func (m *msgServer) getStreamMsg(ctx context.Context, clientMsgID string) (*model.StreamMsg, error) {
|
||||
res, err := m.StreamMsgDatabase.GetStreamMsg(ctx, clientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
now := time.Now()
|
||||
if !res.End && res.DeadlineTime.Before(now) {
|
||||
res.End = true
|
||||
res.DeadlineTime = now
|
||||
_ = m.StreamMsgDatabase.AppendStreamMsg(ctx, res.ClientMsgID, 0, nil, true, now)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) AppendStreamMsg(ctx context.Context, req *msg.AppendStreamMsgReq) (*msg.AppendStreamMsgResp, error) {
|
||||
res, err := m.getStreamMsg(ctx, req.ClientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.End {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("stream msg is end")
|
||||
}
|
||||
if len(res.Packets) < int(req.StartIndex) {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("start index is invalid")
|
||||
}
|
||||
if val := len(res.Packets) - int(req.StartIndex); val > 0 {
|
||||
exist := res.Packets[int(req.StartIndex):]
|
||||
for i, s := range exist {
|
||||
if len(req.Packets) == 0 {
|
||||
break
|
||||
}
|
||||
if s != req.Packets[i] {
|
||||
return nil, errs.ErrNoPermission.WrapMsg(fmt.Sprintf("packet %d has been written and is inconsistent", i))
|
||||
}
|
||||
req.StartIndex++
|
||||
req.Packets = req.Packets[1:]
|
||||
}
|
||||
}
|
||||
if len(req.Packets) == 0 && res.End == req.End {
|
||||
return &msg.AppendStreamMsgResp{}, nil
|
||||
}
|
||||
deadlineTime := time.Now().Add(StreamDeadlineTime)
|
||||
if err := m.StreamMsgDatabase.AppendStreamMsg(ctx, req.ClientMsgID, int(req.StartIndex), req.Packets, req.End, deadlineTime); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conversation, err := m.conversationClient.GetConversation(ctx, res.ConversationID, res.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tips := &sdkws.StreamMsgTips{
|
||||
ConversationID: res.ConversationID,
|
||||
ClientMsgID: res.ClientMsgID,
|
||||
StartIndex: req.StartIndex,
|
||||
Packets: req.Packets,
|
||||
End: req.End,
|
||||
}
|
||||
var (
|
||||
recvID string
|
||||
sessionType int32
|
||||
)
|
||||
if conversation.GroupID == "" {
|
||||
sessionType = constant.SingleChatType
|
||||
recvID = conversation.UserID
|
||||
} else {
|
||||
sessionType = constant.ReadGroupChatType
|
||||
recvID = conversation.GroupID
|
||||
}
|
||||
m.msgNotificationSender.StreamMsgNotification(ctx, res.UserID, recvID, sessionType, tips)
|
||||
return &msg.AppendStreamMsgResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) GetStreamMsg(ctx context.Context, req *msg.GetStreamMsgReq) (*msg.GetStreamMsgResp, error) {
|
||||
res, err := m.getStreamMsg(ctx, req.ClientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &msg.GetStreamMsgResp{
|
||||
ClientMsgID: res.ClientMsgID,
|
||||
ConversationID: res.ConversationID,
|
||||
UserID: res.UserID,
|
||||
Packets: res.Packets,
|
||||
End: res.End,
|
||||
CreateTime: res.CreateTime.UnixMilli(),
|
||||
DeadlineTime: res.DeadlineTime.UnixMilli(),
|
||||
}, nil
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -1,231 +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/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/discovery"
|
||||
"github.com/openimsdk/tools/system/program"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// User represents a structure holding connection details for the User RPC client.
|
||||
type User struct {
|
||||
conn grpc.ClientConnInterface
|
||||
Client user.UserClient
|
||||
Discov discovery.SvcDiscoveryRegistry
|
||||
MessageGateWayRpcName string
|
||||
imAdminUserID []string
|
||||
}
|
||||
|
||||
// NewUser initializes and returns a User instance based on the provided service discovery registry.
|
||||
func NewUser(discov discovery.SvcDiscoveryRegistry, rpcRegisterName, messageGateWayRpcName string,
|
||||
imAdminUserID []string) *User {
|
||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||
if err != nil {
|
||||
program.ExitWithError(err)
|
||||
}
|
||||
client := user.NewUserClient(conn)
|
||||
return &User{Discov: discov, Client: client,
|
||||
conn: conn,
|
||||
MessageGateWayRpcName: messageGateWayRpcName,
|
||||
imAdminUserID: imAdminUserID}
|
||||
}
|
||||
|
||||
// UserRpcClient represents the structure for a User RPC client.
|
||||
type UserRpcClient User
|
||||
|
||||
// NewUserRpcClientByUser initializes a UserRpcClient based on the provided User instance.
|
||||
func NewUserRpcClientByUser(user *User) *UserRpcClient {
|
||||
rpc := UserRpcClient(*user)
|
||||
return &rpc
|
||||
}
|
||||
|
||||
// NewUserRpcClient initializes a UserRpcClient based on the provided service discovery registry.
|
||||
func NewUserRpcClient(client discovery.SvcDiscoveryRegistry, rpcRegisterName string,
|
||||
imAdminUserID []string) UserRpcClient {
|
||||
return UserRpcClient(*NewUser(client, rpcRegisterName, "", imAdminUserID))
|
||||
}
|
||||
|
||||
// GetUsersInfo retrieves information for multiple users based on their user IDs.
|
||||
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return []*sdkws.UserInfo{}, nil
|
||||
}
|
||||
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||
UserIDs: userIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ids := datautil.Single(userIDs, datautil.Slice(resp.UsersInfo, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, servererrs.ErrUserIDNotFound.WrapMsg(strings.Join(ids, ","))
|
||||
}
|
||||
return resp.UsersInfo, nil
|
||||
}
|
||||
|
||||
// GetUserInfo retrieves information for a single user based on the provided user ID.
|
||||
func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfo(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
// GetUsersInfoMap retrieves a map of user information indexed by their user IDs.
|
||||
func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return datautil.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
// GetPublicUserInfos retrieves public information for multiple users based on their user IDs.
|
||||
func (u *UserRpcClient) GetPublicUserInfos(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
) ([]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return datautil.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
|
||||
return &sdkws.PublicUserInfo{
|
||||
UserID: e.UserID,
|
||||
Nickname: e.Nickname,
|
||||
FaceURL: e.FaceURL,
|
||||
Ex: e.Ex,
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
// GetPublicUserInfo retrieves public information for a single user based on the provided user ID.
|
||||
func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
// GetPublicUserInfoMap retrieves a map of public user information indexed by their user IDs.
|
||||
func (u *UserRpcClient) GetPublicUserInfoMap(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
) (map[string]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return datautil.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
// GetUserGlobalMsgRecvOpt retrieves the global message receive option for a user based on the provided user ID.
|
||||
func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
|
||||
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return resp.GlobalRecvMsgOpt, nil
|
||||
}
|
||||
|
||||
// Access verifies the access rights for the provided user ID.
|
||||
func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error {
|
||||
_, err := u.GetUserInfo(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return authverify.CheckAccessV3(ctx, ownerUserID, u.imAdminUserID)
|
||||
}
|
||||
|
||||
// GetAllUserID retrieves all user IDs with pagination options.
|
||||
func (u *UserRpcClient) GetAllUserID(ctx context.Context, pageNumber, showNumber int32) (*user.GetAllUserIDResp, error) {
|
||||
resp, err := u.Client.GetAllUserID(ctx, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetAllUserIDs retrieves all user IDs with pagination options.
|
||||
func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
|
||||
resp, err := u.Client.GetAllUserID(ctx, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.UserIDs, nil
|
||||
}
|
||||
|
||||
// SetUserStatus sets the status for a user based on the provided user ID, status, and platform ID.
|
||||
func (u *UserRpcClient) SetUserStatus(ctx context.Context, userID string, status int32, platformID int) error {
|
||||
_, err := u.Client.SetUserStatus(ctx, &user.SetUserStatusReq{
|
||||
UserID: userID,
|
||||
Status: status, PlatformID: int32(platformID),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (u *UserRpcClient) GetNotificationByID(ctx context.Context, userID string) error {
|
||||
_, err := u.Client.GetNotificationAccount(ctx, &user.GetNotificationAccountReq{
|
||||
UserID: userID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (u *UserRpcClient) GetUsersOnlinePlatform(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
resp, err := u.Client.GetUserStatus(ctx, &user.GetUserStatusReq{UserIDs: userIDs, UserID: u.imAdminUserID[0]})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.StatusList, nil
|
||||
}
|
||||
|
||||
func (u *UserRpcClient) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
||||
resp, err := u.GetUsersOnlinePlatform(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return resp[0].PlatformIDs, nil
|
||||
}
|
||||
|
||||
func (u *UserRpcClient) GetAllOnlineUsers(ctx context.Context, cursor uint64) (*user.GetAllOnlineUsersResp, error) {
|
||||
return u.Client.GetAllOnlineUsers(ctx, &user.GetAllOnlineUsersReq{Cursor: cursor})
|
||||
}
|
Loading…
Reference in new issue