feat: add scripts (#525)

This commit is contained in:
Xinwei Xiong
2023-07-13 11:37:23 +08:00
committed by GitHub
parent eb7953cacb
commit 7bf8a898e2
56 changed files with 2049 additions and 442 deletions
+41 -8
View File
@@ -4,6 +4,9 @@ import (
"context"
"encoding/json"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
@@ -11,8 +14,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
// "google.golang.org/protobuf/proto"
)
@@ -136,7 +137,10 @@ func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqRe
return resp, err
}
func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
func (m *MessageRpcClient) PullMessageBySeqList(
ctx context.Context,
req *sdkws.PullMessageBySeqsReq,
) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := m.Client.PullMessageBySeqs(ctx, req)
return resp, err
}
@@ -158,7 +162,9 @@ type NotificationSender struct {
type NotificationSenderOptions func(*NotificationSender)
func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)) NotificationSenderOptions {
func WithLocalSendMsg(
sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error),
) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = sendMsg
}
@@ -177,7 +183,10 @@ func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
}
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()}
notificationSender := &NotificationSender{
contentTypeConf: newContentTypeConf(),
sessionTypeConf: newSessionTypeConf(),
}
for _, opt := range opts {
opt(notificationSender)
}
@@ -196,11 +205,29 @@ func WithRpcGetUserName() NotificationOptions {
}
}
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
func (s *NotificationSender) NotificationWithSesstionType(
ctx context.Context,
sendID, recvID string,
contentType, sesstionType int32,
m proto.Message,
opts ...NotificationOptions,
) (err error) {
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n)
if err != nil {
log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m)
log.ZError(
ctx,
"MsgClient Notification json.Marshal failed",
err,
"sendID",
sendID,
"recvID",
recvID,
"contentType",
contentType,
"msg",
m,
)
return err
}
notificationOpt := &notificationOpt{}
@@ -247,6 +274,12 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
return err
}
func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error {
func (s *NotificationSender) Notification(
ctx context.Context,
sendID, recvID string,
contentType int32,
m proto.Message,
opts ...NotificationOptions,
) error {
return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...)
}