commit
5cc018df7d
@ -1,31 +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/protocol/user"
|
||||
"github.com/openimsdk/tools/a2r"
|
||||
)
|
||||
|
||||
type StatisticsApi struct{}
|
||||
|
||||
func NewStatisticsApi() StatisticsApi {
|
||||
return StatisticsApi{}
|
||||
}
|
||||
|
||||
func (s *StatisticsApi) UserRegister(c *gin.Context) {
|
||||
a2r.CallV2(c, user.UserRegisterCountCaller.Invoke)
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
kdisc "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister"
|
||||
pbconversation "github.com/openimsdk/protocol/conversation"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/third"
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
"github.com/openimsdk/tools/mw"
|
||||
"github.com/robfig/cron/v3"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
conf := &config.Discovery{
|
||||
Enable: config.ETCD,
|
||||
Etcd: config.Etcd{
|
||||
RootDirectory: "openim",
|
||||
Address: []string{"localhost:12379"},
|
||||
},
|
||||
}
|
||||
client, err := kdisc.NewDiscoveryRegister(conf, "source")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
ctx := mcontext.SetOpUserID(context.Background(), "imAdmin")
|
||||
msgConn, err := client.GetConn(ctx, "msg-rpc-service")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
thirdConn, err := client.GetConn(ctx, "third-rpc-service")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
conversationConn, err := client.GetConn(ctx, "conversation-rpc-service")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
srv := &cronServer{
|
||||
ctx: ctx,
|
||||
config: &CronTaskConfig{
|
||||
CronTask: config.CronTask{
|
||||
RetainChatRecords: 1,
|
||||
FileExpireTime: 1,
|
||||
DeleteObjectType: []string{"msg-picture", "msg-file", "msg-voice", "msg-video", "msg-video-snapshot", "sdklog", ""},
|
||||
},
|
||||
},
|
||||
cron: cron.New(),
|
||||
msgClient: msg.NewMsgClient(msgConn),
|
||||
conversationClient: pbconversation.NewConversationClient(conversationConn),
|
||||
thirdClient: third.NewThirdClient(thirdConn),
|
||||
}
|
||||
srv.deleteMsg()
|
||||
//srv.clearS3()
|
||||
//srv.clearUserMsg()
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *cronServer) deleteMsg() {
|
||||
now := time.Now()
|
||||
deltime := now.Add(-time.Hour * 24 * time.Duration(c.config.CronTask.RetainChatRecords))
|
||||
operationID := fmt.Sprintf("cron_msg_%d_%d", os.Getpid(), deltime.UnixMilli())
|
||||
ctx := mcontext.SetOperationID(c.ctx, operationID)
|
||||
log.ZDebug(ctx, "Destruct chat records", "deltime", deltime, "timestamp", deltime.UnixMilli())
|
||||
const (
|
||||
deleteCount = 10000
|
||||
deleteLimit = 50
|
||||
)
|
||||
var count int
|
||||
for i := 1; i <= deleteCount; i++ {
|
||||
ctx := mcontext.SetOperationID(c.ctx, fmt.Sprintf("%s_%d", operationID, i))
|
||||
resp, err := c.msgClient.DestructMsgs(ctx, &msg.DestructMsgsReq{Timestamp: deltime.UnixMilli(), Limit: deleteLimit})
|
||||
if err != nil {
|
||||
log.ZError(ctx, "cron destruct chat records failed", err)
|
||||
break
|
||||
}
|
||||
count += int(resp.Count)
|
||||
if resp.Count < deleteLimit {
|
||||
break
|
||||
}
|
||||
}
|
||||
log.ZDebug(ctx, "cron destruct chat records end", "deltime", deltime, "cont", time.Since(now), "count", count)
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/protocol/third"
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *cronServer) clearS3() {
|
||||
start := time.Now()
|
||||
deleteTime := start.Add(-time.Hour * 24 * time.Duration(c.config.CronTask.FileExpireTime))
|
||||
operationID := fmt.Sprintf("cron_s3_%d_%d", os.Getpid(), deleteTime.UnixMilli())
|
||||
ctx := mcontext.SetOperationID(c.ctx, operationID)
|
||||
log.ZDebug(ctx, "deleteoutDatedData", "deletetime", deleteTime, "timestamp", deleteTime.UnixMilli())
|
||||
const (
|
||||
deleteCount = 10000
|
||||
deleteLimit = 100
|
||||
)
|
||||
|
||||
var count int
|
||||
for i := 1; i <= deleteCount; i++ {
|
||||
resp, err := c.thirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{ExpireTime: deleteTime.UnixMilli(), ObjectGroup: c.config.CronTask.DeleteObjectType, Limit: deleteLimit})
|
||||
if err != nil {
|
||||
log.ZError(ctx, "cron deleteoutDatedData failed", err)
|
||||
return
|
||||
}
|
||||
count += int(resp.Count)
|
||||
if resp.Count < deleteLimit {
|
||||
break
|
||||
}
|
||||
}
|
||||
log.ZDebug(ctx, "cron deleteoutDatedData success", "deltime", deleteTime, "cont", time.Since(start), "count", count)
|
||||
}
|
||||
|
||||
// var req *third.DeleteOutdatedDataReq
|
||||
// count1, err := ExtractField(ctx, c.thirdClient.DeleteOutdatedData, req, (*third.DeleteOutdatedDataResp).GetCount)
|
||||
//
|
||||
// c.thirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{})
|
||||
// msggateway.GetUsersOnlineStatusCaller.Invoke(ctx, &msggateway.GetUsersOnlineStatusReq{})
|
||||
//
|
||||
// var cli ThirdClient
|
||||
//
|
||||
// c111, err := cli.DeleteOutdatedData(ctx, 100)
|
||||
//
|
||||
// cli.ThirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{})
|
||||
//
|
||||
// cli.AuthSign(ctx, &third.AuthSignReq{})
|
||||
//
|
||||
// cli.SetAppBadge()
|
||||
//
|
||||
//}
|
||||
//
|
||||
//func extractField[A, B, C any](ctx context.Context, fn func(ctx context.Context, req *A, opts ...grpc.CallOption) (*B, error), req *A, get func(*B) C) (C, error) {
|
||||
// resp, err := fn(ctx, req)
|
||||
// if err != nil {
|
||||
// var c C
|
||||
// return c, err
|
||||
// }
|
||||
// return get(resp), nil
|
||||
//}
|
||||
//
|
||||
//func ignore(_ any, err error) error {
|
||||
// return err
|
||||
//}
|
||||
//
|
||||
//type ThirdClient struct {
|
||||
// third.ThirdClient
|
||||
//}
|
||||
//
|
||||
//func (c *ThirdClient) DeleteOutdatedData(ctx context.Context, expireTime int64) (int32, error) {
|
||||
// return extractField(ctx, c.ThirdClient.DeleteOutdatedData, &third.DeleteOutdatedDataReq{ExpireTime: expireTime}, (*third.DeleteOutdatedDataResp).GetCount)
|
||||
//}
|
||||
//
|
||||
//func (c *ThirdClient) DeleteOutdatedData1(ctx context.Context, expireTime int64) error {
|
||||
// return ignore(c.ThirdClient.DeleteOutdatedData(ctx, &third.DeleteOutdatedDataReq{ExpireTime: expireTime}))
|
||||
//}
|
@ -0,0 +1,34 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
pbconversation "github.com/openimsdk/protocol/conversation"
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *cronServer) clearUserMsg() {
|
||||
now := time.Now()
|
||||
operationID := fmt.Sprintf("cron_user_msg_%d_%d", os.Getpid(), now.UnixMilli())
|
||||
ctx := mcontext.SetOperationID(c.ctx, operationID)
|
||||
log.ZDebug(ctx, "clear user msg cron start")
|
||||
const (
|
||||
deleteCount = 10000
|
||||
deleteLimit = 100
|
||||
)
|
||||
var count int
|
||||
for i := 1; i <= deleteCount; i++ {
|
||||
resp, err := c.conversationClient.ClearUserConversationMsg(ctx, &pbconversation.ClearUserConversationMsgReq{Timestamp: now.UnixMilli(), Limit: deleteLimit})
|
||||
if err != nil {
|
||||
log.ZError(ctx, "ClearUserConversationMsg failed.", err)
|
||||
return
|
||||
}
|
||||
count += int(resp.Count)
|
||||
if resp.Count < deleteLimit {
|
||||
break
|
||||
}
|
||||
}
|
||||
log.ZDebug(ctx, "clear user msg cron task completed", "cont", time.Since(now), "count", count)
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// Copyright © 2024 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 "github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
@ -1,15 +0,0 @@
|
||||
// Copyright © 2024 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 grouphash // import "github.com/openimsdk/open-im-server/v3/pkg/rpcclient/grouphash"
|
@ -1,60 +0,0 @@
|
||||
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,15 +0,0 @@
|
||||
// Copyright © 2024 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 notification // import "github.com/openimsdk/open-im-server/v3/pkg/rpcclient/notification"
|
@ -1,109 +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/sdkws"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
)
|
||||
|
||||
// GetUsersInfo retrieves information for multiple users based on their user IDs.
|
||||
func GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return []*sdkws.UserInfo{}, nil
|
||||
}
|
||||
resp, err := user.GetDesignateUsersCaller.Invoke(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 GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
users, err := 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 GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := 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 GetPublicUserInfos(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
) ([]*sdkws.PublicUserInfo, error) {
|
||||
users, err := 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 GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
users, err := 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 GetPublicUserInfoMap(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
) (map[string]*sdkws.PublicUserInfo, error) {
|
||||
users, err := GetPublicUserInfos(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return datautil.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/auth"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewAuthClient(cc grpc.ClientConnInterface) *AuthClient {
|
||||
return &AuthClient{auth.NewAuthClient(cc)}
|
||||
}
|
||||
|
||||
type AuthClient struct {
|
||||
auth.AuthClient
|
||||
}
|
||||
|
||||
func (x *AuthClient) KickTokens(ctx context.Context, tokens []string) error {
|
||||
if len(tokens) == 0 {
|
||||
return nil
|
||||
}
|
||||
return ignoreResp(x.AuthClient.KickTokens(ctx, &auth.KickTokensReq{Tokens: tokens}))
|
||||
}
|
||||
|
||||
func (x *AuthClient) InvalidateToken(ctx context.Context, req *auth.InvalidateTokenReq) error {
|
||||
return ignoreResp(x.AuthClient.InvalidateToken(ctx, req))
|
||||
}
|
||||
|
||||
func (x *AuthClient) ParseToken(ctx context.Context, token string) (*auth.ParseTokenResp, error) {
|
||||
return x.AuthClient.ParseToken(ctx, &auth.ParseTokenReq{Token: token})
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/conversation"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewConversationClient(cc grpc.ClientConnInterface) *ConversationClient {
|
||||
return &ConversationClient{conversation.NewConversationClient(cc)}
|
||||
}
|
||||
|
||||
type ConversationClient struct {
|
||||
conversation.ConversationClient
|
||||
}
|
||||
|
||||
func (x *ConversationClient) SetConversationMaxSeq(ctx context.Context, conversationID string, ownerUserIDs []string, maxSeq int64) error {
|
||||
if len(ownerUserIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &conversation.SetConversationMaxSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MaxSeq: maxSeq}
|
||||
return ignoreResp(x.ConversationClient.SetConversationMaxSeq(ctx, req))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) SetConversations(ctx context.Context, ownerUserIDs []string, info *conversation.ConversationReq) error {
|
||||
if len(ownerUserIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &conversation.SetConversationsReq{UserIDs: ownerUserIDs, Conversation: info}
|
||||
return ignoreResp(x.ConversationClient.SetConversations(ctx, req))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversationsByConversationIDs(ctx context.Context, conversationIDs []string) ([]*conversation.Conversation, error) {
|
||||
if len(conversationIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &conversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs}
|
||||
return extractField(ctx, x.ConversationClient.GetConversationsByConversationID, req, (*conversation.GetConversationsByConversationIDResp).GetConversations)
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversationsByConversationID(ctx context.Context, conversationID string) (*conversation.Conversation, error) {
|
||||
return firstValue(x.GetConversationsByConversationIDs(ctx, []string{conversationID}))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) SetConversationMinSeq(ctx context.Context, conversationID string, ownerUserIDs []string, minSeq int64) error {
|
||||
if len(ownerUserIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &conversation.SetConversationMinSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MinSeq: minSeq}
|
||||
return ignoreResp(x.ConversationClient.SetConversationMinSeq(ctx, req))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversation(ctx context.Context, conversationID string, ownerUserID string) (*conversation.Conversation, error) {
|
||||
req := &conversation.GetConversationReq{ConversationID: conversationID, OwnerUserID: ownerUserID}
|
||||
return extractField(ctx, x.ConversationClient.GetConversation, req, (*conversation.GetConversationResp).GetConversation)
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversations(ctx context.Context, conversationIDs []string, ownerUserID string) ([]*conversation.Conversation, error) {
|
||||
if len(conversationIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &conversation.GetConversationsReq{ConversationIDs: conversationIDs, OwnerUserID: ownerUserID}
|
||||
return extractField(ctx, x.ConversationClient.GetConversations, req, (*conversation.GetConversationsResp).GetConversations)
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
req := &conversation.GetConversationIDsReq{UserID: ownerUserID}
|
||||
return extractField(ctx, x.ConversationClient.GetConversationIDs, req, (*conversation.GetConversationIDsResp).GetConversationIDs)
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetPinnedConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
||||
req := &conversation.GetPinnedConversationIDsReq{UserID: ownerUserID}
|
||||
return extractField(ctx, x.ConversationClient.GetPinnedConversationIDs, req, (*conversation.GetPinnedConversationIDsResp).GetConversationIDs)
|
||||
}
|
||||
|
||||
func (x *ConversationClient) CreateGroupChatConversations(ctx context.Context, groupID string, userIDs []string) error {
|
||||
if len(userIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &conversation.CreateGroupChatConversationsReq{GroupID: groupID, UserIDs: userIDs}
|
||||
return ignoreResp(x.ConversationClient.CreateGroupChatConversations(ctx, req))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) CreateSingleChatConversations(ctx context.Context, req *conversation.CreateSingleChatConversationsReq) error {
|
||||
return ignoreResp(x.ConversationClient.CreateSingleChatConversations(ctx, req))
|
||||
}
|
||||
|
||||
func (x *ConversationClient) GetConversationOfflinePushUserIDs(ctx context.Context, conversationID string, userIDs []string) ([]string, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &conversation.GetConversationOfflinePushUserIDsReq{ConversationID: conversationID, UserIDs: userIDs}
|
||||
return extractField(ctx, x.ConversationClient.GetConversationOfflinePushUserIDs, req, (*conversation.GetConversationOfflinePushUserIDsResp).GetUserIDs)
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/group"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewGroupClient(cc grpc.ClientConnInterface) *GroupClient {
|
||||
return &GroupClient{group.NewGroupClient(cc)}
|
||||
}
|
||||
|
||||
type GroupClient struct {
|
||||
group.GroupClient
|
||||
}
|
||||
|
||||
func (x *GroupClient) GetGroupsInfo(ctx context.Context, groupIDs []string) ([]*sdkws.GroupInfo, error) {
|
||||
if len(groupIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &group.GetGroupsInfoReq{GroupIDs: groupIDs}
|
||||
return extractField(ctx, x.GroupClient.GetGroupsInfo, req, (*group.GetGroupsInfoResp).GetGroupInfos)
|
||||
}
|
||||
|
||||
func (x *GroupClient) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
||||
return firstValue(x.GetGroupsInfo(ctx, []string{groupID}))
|
||||
}
|
||||
|
||||
func (x *GroupClient) GetGroupInfoCache(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
||||
req := &group.GetGroupInfoCacheReq{GroupID: groupID}
|
||||
return extractField(ctx, x.GroupClient.GetGroupInfoCache, req, (*group.GetGroupInfoCacheResp).GetGroupInfo)
|
||||
}
|
||||
|
||||
func (x *GroupClient) GetGroupMemberCache(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
req := &group.GetGroupMemberCacheReq{GroupID: groupID, GroupMemberID: userID}
|
||||
return extractField(ctx, x.GroupClient.GetGroupMemberCache, req, (*group.GetGroupMemberCacheResp).GetMember)
|
||||
}
|
||||
|
||||
func (x *GroupClient) DismissGroup(ctx context.Context, groupID string, deleteMember bool) error {
|
||||
req := &group.DismissGroupReq{GroupID: groupID, DeleteMember: deleteMember}
|
||||
return ignoreResp(x.GroupClient.DismissGroup(ctx, req))
|
||||
}
|
||||
|
||||
func (x *GroupClient) GetGroupMemberUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
||||
req := &group.GetGroupMemberUserIDsReq{GroupID: groupID}
|
||||
return extractField(ctx, x.GroupClient.GetGroupMemberUserIDs, req, (*group.GetGroupMemberUserIDsResp).GetUserIDs)
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewMsgClient(cc grpc.ClientConnInterface) *MsgClient {
|
||||
return &MsgClient{msg.NewMsgClient(cc)}
|
||||
}
|
||||
|
||||
type MsgClient struct {
|
||||
msg.MsgClient
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
|
||||
if len(conversationIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &msg.GetMaxSeqsReq{ConversationIDs: conversationIDs}
|
||||
return extractField(ctx, x.MsgClient.GetMaxSeqs, req, (*msg.SeqsInfoResp).GetMaxSeqs)
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetMsgByConversationIDs(ctx context.Context, conversationIDs []string, maxSeqs map[string]int64) (map[string]*sdkws.MsgData, error) {
|
||||
if len(conversationIDs) == 0 || len(maxSeqs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &msg.GetMsgByConversationIDsReq{ConversationIDs: conversationIDs, MaxSeqs: maxSeqs}
|
||||
return extractField(ctx, x.MsgClient.GetMsgByConversationIDs, req, (*msg.GetMsgByConversationIDsResp).GetMsgDatas)
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetHasReadSeqs(ctx context.Context, conversationIDs []string, userID string) (map[string]int64, error) {
|
||||
if len(conversationIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &msg.GetHasReadSeqsReq{ConversationIDs: conversationIDs, UserID: userID}
|
||||
return extractField(ctx, x.MsgClient.GetHasReadSeqs, req, (*msg.SeqsInfoResp).GetMaxSeqs)
|
||||
}
|
||||
|
||||
func (x *MsgClient) SetUserConversationMaxSeq(ctx context.Context, conversationID string, ownerUserIDs []string, maxSeq int64) error {
|
||||
if len(ownerUserIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &msg.SetUserConversationMaxSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MaxSeq: maxSeq}
|
||||
return ignoreResp(x.MsgClient.SetUserConversationMaxSeq(ctx, req))
|
||||
}
|
||||
|
||||
func (x *MsgClient) SetUserConversationMin(ctx context.Context, conversationID string, ownerUserIDs []string, minSeq int64) error {
|
||||
if len(ownerUserIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &msg.SetUserConversationsMinSeqReq{ConversationID: conversationID, UserIDs: ownerUserIDs, Seq: minSeq}
|
||||
return ignoreResp(x.MsgClient.SetUserConversationsMinSeq(ctx, req))
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetLastMessageSeqByTime(ctx context.Context, conversationID string, lastTime int64) (int64, error) {
|
||||
req := &msg.GetLastMessageSeqByTimeReq{ConversationID: conversationID, Time: lastTime}
|
||||
return extractField(ctx, x.MsgClient.GetLastMessageSeqByTime, req, (*msg.GetLastMessageSeqByTimeResp).GetSeq)
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetConversationMaxSeq(ctx context.Context, conversationID string) (int64, error) {
|
||||
req := &msg.GetConversationMaxSeqReq{ConversationID: conversationID}
|
||||
return extractField(ctx, x.MsgClient.GetConversationMaxSeq, req, (*msg.GetConversationMaxSeqResp).GetMaxSeq)
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetActiveConversation(ctx context.Context, conversationIDs []string) ([]*msg.ActiveConversation, error) {
|
||||
if len(conversationIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &msg.GetActiveConversationReq{ConversationIDs: conversationIDs}
|
||||
return extractField(ctx, x.MsgClient.GetActiveConversation, req, (*msg.GetActiveConversationResp).GetConversations)
|
||||
}
|
||||
|
||||
func (x *MsgClient) GetSeqMessage(ctx context.Context, userID string, conversations []*msg.ConversationSeqs) (map[string]*sdkws.PullMsgs, error) {
|
||||
if len(conversations) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &msg.GetSeqMessageReq{UserID: userID, Conversations: conversations}
|
||||
return extractField(ctx, x.MsgClient.GetSeqMessage, req, (*msg.GetSeqMessageResp).GetMsgs)
|
||||
}
|
||||
|
||||
func (x *MsgClient) SetUserConversationsMinSeq(ctx context.Context, conversationID string, userIDs []string, seq int64) error {
|
||||
if len(userIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
req := &msg.SetUserConversationsMinSeqReq{ConversationID: conversationID, UserIDs: userIDs, Seq: seq}
|
||||
return ignoreResp(x.MsgClient.SetUserConversationsMinSeq(ctx, req))
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/protocol/msggateway"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewMsgGatewayClient(cc grpc.ClientConnInterface) *MsgGatewayClient {
|
||||
return &MsgGatewayClient{msggateway.NewMsgGatewayClient(cc)}
|
||||
}
|
||||
|
||||
type MsgGatewayClient struct {
|
||||
msggateway.MsgGatewayClient
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/protocol/push"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewPushMsgServiceClient(cc grpc.ClientConnInterface) *PushMsgServiceClient {
|
||||
return &PushMsgServiceClient{push.NewPushMsgServiceClient(cc)}
|
||||
}
|
||||
|
||||
type PushMsgServiceClient struct {
|
||||
push.PushMsgServiceClient
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/relation"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewRelationClient(cc grpc.ClientConnInterface) *RelationClient {
|
||||
return &RelationClient{relation.NewFriendClient(cc)}
|
||||
}
|
||||
|
||||
type RelationClient struct {
|
||||
relation.FriendClient
|
||||
}
|
||||
|
||||
func (x *RelationClient) GetFriendsInfo(ctx context.Context, ownerUserID string, friendUserIDs []string) ([]*relation.FriendInfoOnly, error) {
|
||||
if len(friendUserIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &relation.GetFriendInfoReq{OwnerUserID: ownerUserID, FriendUserIDs: friendUserIDs}
|
||||
return extractField(ctx, x.FriendClient.GetFriendInfo, req, (*relation.GetFriendInfoResp).GetFriendInfos)
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/protocol/rtc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewRtcServiceClient(cc grpc.ClientConnInterface) *RtcServiceClient {
|
||||
return &RtcServiceClient{rtc.NewRtcServiceClient(cc)}
|
||||
}
|
||||
|
||||
type RtcServiceClient struct {
|
||||
rtc.RtcServiceClient
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/protocol/third"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewThirdClient(cc grpc.ClientConnInterface) *ThirdClient {
|
||||
return &ThirdClient{third.NewThirdClient(cc)}
|
||||
}
|
||||
|
||||
type ThirdClient struct {
|
||||
third.ThirdClient
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func extractField[A, B, C any](ctx context.Context, fn func(ctx context.Context, req *A, opts ...grpc.CallOption) (*B, error), req *A, get func(*B) C) (C, error) {
|
||||
resp, err := fn(ctx, req)
|
||||
if err != nil {
|
||||
var c C
|
||||
return c, err
|
||||
}
|
||||
return get(resp), nil
|
||||
}
|
||||
|
||||
func firstValue[A any](val []A, err error) (A, error) {
|
||||
if err != nil {
|
||||
var a A
|
||||
return a, err
|
||||
}
|
||||
if len(val) == 0 {
|
||||
var a A
|
||||
return a, errs.ErrRecordNotFound.WrapMsg("record not found")
|
||||
}
|
||||
return val[0], nil
|
||||
}
|
||||
|
||||
func ignoreResp(_ any, err error) error {
|
||||
return err
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package rpcli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/openimsdk/tools/utils/datautil"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func NewUserClient(cc grpc.ClientConnInterface) *UserClient {
|
||||
return &UserClient{user.NewUserClient(cc)}
|
||||
}
|
||||
|
||||
type UserClient struct {
|
||||
user.UserClient
|
||||
}
|
||||
|
||||
func (x *UserClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &user.GetDesignateUsersReq{UserIDs: userIDs}
|
||||
return extractField(ctx, x.UserClient.GetDesignateUsers, req, (*user.GetDesignateUsersResp).GetUsersInfo)
|
||||
}
|
||||
|
||||
func (x *UserClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
return firstValue(x.GetUsersInfo(ctx, []string{userID}))
|
||||
}
|
||||
|
||||
func (x *UserClient) CheckUser(ctx context.Context, userIDs []string) error {
|
||||
if len(userIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
users, err := x.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) != len(userIDs) {
|
||||
return errs.ErrRecordNotFound.WrapMsg("user not found")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *UserClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := x.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return datautil.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (x *UserClient) GetAllOnlineUsers(ctx context.Context, cursor uint64) (*user.GetAllOnlineUsersResp, error) {
|
||||
req := &user.GetAllOnlineUsersReq{Cursor: cursor}
|
||||
return x.UserClient.GetAllOnlineUsers(ctx, req)
|
||||
}
|
||||
|
||||
func (x *UserClient) GetUsersOnlinePlatform(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
req := &user.GetUserStatusReq{UserIDs: userIDs}
|
||||
return extractField(ctx, x.UserClient.GetUserStatus, req, (*user.GetUserStatusResp).GetStatusList)
|
||||
|
||||
}
|
||||
|
||||
func (x *UserClient) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
||||
status, err := x.GetUsersOnlinePlatform(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(status) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return status[0].PlatformIDs, nil
|
||||
}
|
||||
|
||||
func (x *UserClient) SetUserOnlineStatus(ctx context.Context, req *user.SetUserOnlineStatusReq) error {
|
||||
if len(req.Status) == 0 {
|
||||
return nil
|
||||
}
|
||||
return ignoreResp(x.UserClient.SetUserOnlineStatus(ctx, req))
|
||||
}
|
||||
|
||||
func (x *UserClient) GetNotificationByID(ctx context.Context, userID string) error {
|
||||
return ignoreResp(x.UserClient.GetNotificationAccount(ctx, &user.GetNotificationAccountReq{UserID: userID}))
|
||||
}
|
||||
|
||||
func (x *UserClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
|
||||
req := &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}}
|
||||
return extractField(ctx, x.UserClient.GetAllUserID, req, (*user.GetAllUserIDResp).GetUserIDs)
|
||||
}
|
Loading…
Reference in new issue