optimization: change the configuration file from being read globally … (#1935)

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: change the configuration file from being read globally to being read independently.

* optimization: config file changed to dependency injection.

* fix: replace global config with dependency injection

* fix: replace global config with dependency injection

* fix: import the enough param

* fix: import the enough param

* fix: import the enough param

* fix: fix the component check of path

* fix: fix the kafka of tls is nil problem

* fix: fix the TLS.CACrt is nil error

* fix: fix the valiable shadows problem

* fix: fix the comflect

* optimization: message remove options.

* fix: fix the param pass error

* fix: find error

* fix: find error

* fix: find eror

* fix: find error

* fix: find error

* fix: del the undifined func

* fix: find error

* fix: fix the error

* fix: pass config

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: find error

* fix: fix the config

* fix: fix the error

* fix: fix the config pass error

* fix: fix the eror

* fix: fix the error

* fix: fix the error

* fix: fix the error

* fix: find error

* fix: fix the error

* fix: fix the config

* fix: add return err

* fix: fix the err2

* fix: err

* fix: fix the func

* fix: del the chinese comment

* fix: fix the func

* fix: fix the gateway_test logic

* fix: s3

* test

* test

* fix: not found

---------

Co-authored-by: luhaoling <2198702716@qq.com>
Co-authored-by: withchao <993506633@qq.com>
This commit is contained in:
OpenIM-Gordon
2024-03-05 17:53:22 +08:00
committed by GitHub
parent efb8310531
commit 383758782e
114 changed files with 1743 additions and 1802 deletions
+53 -50
View File
@@ -17,6 +17,8 @@ package rpcclient
import (
"context"
"encoding/json"
"fmt"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/protocol/msg"
@@ -29,47 +31,47 @@ import (
"google.golang.org/protobuf/proto"
)
func newContentTypeConf() map[int32]config.NotificationConf {
func newContentTypeConf(conf *config.GlobalConfig) map[int32]config.NotificationConf {
return map[int32]config.NotificationConf{
// group
constant.GroupCreatedNotification: config.Config.Notification.GroupCreated,
constant.GroupInfoSetNotification: config.Config.Notification.GroupInfoSet,
constant.JoinGroupApplicationNotification: config.Config.Notification.JoinGroupApplication,
constant.MemberQuitNotification: config.Config.Notification.MemberQuit,
constant.GroupApplicationAcceptedNotification: config.Config.Notification.GroupApplicationAccepted,
constant.GroupApplicationRejectedNotification: config.Config.Notification.GroupApplicationRejected,
constant.GroupOwnerTransferredNotification: config.Config.Notification.GroupOwnerTransferred,
constant.MemberKickedNotification: config.Config.Notification.MemberKicked,
constant.MemberInvitedNotification: config.Config.Notification.MemberInvited,
constant.MemberEnterNotification: config.Config.Notification.MemberEnter,
constant.GroupDismissedNotification: config.Config.Notification.GroupDismissed,
constant.GroupMutedNotification: config.Config.Notification.GroupMuted,
constant.GroupCancelMutedNotification: config.Config.Notification.GroupCancelMuted,
constant.GroupMemberMutedNotification: config.Config.Notification.GroupMemberMuted,
constant.GroupMemberCancelMutedNotification: config.Config.Notification.GroupMemberCancelMuted,
constant.GroupMemberInfoSetNotification: config.Config.Notification.GroupMemberInfoSet,
constant.GroupMemberSetToAdminNotification: config.Config.Notification.GroupMemberSetToAdmin,
constant.GroupMemberSetToOrdinaryUserNotification: config.Config.Notification.GroupMemberSetToOrdinary,
constant.GroupInfoSetAnnouncementNotification: config.Config.Notification.GroupInfoSetAnnouncement,
constant.GroupInfoSetNameNotification: config.Config.Notification.GroupInfoSetName,
constant.GroupCreatedNotification: conf.Notification.GroupCreated,
constant.GroupInfoSetNotification: conf.Notification.GroupInfoSet,
constant.JoinGroupApplicationNotification: conf.Notification.JoinGroupApplication,
constant.MemberQuitNotification: conf.Notification.MemberQuit,
constant.GroupApplicationAcceptedNotification: conf.Notification.GroupApplicationAccepted,
constant.GroupApplicationRejectedNotification: conf.Notification.GroupApplicationRejected,
constant.GroupOwnerTransferredNotification: conf.Notification.GroupOwnerTransferred,
constant.MemberKickedNotification: conf.Notification.MemberKicked,
constant.MemberInvitedNotification: conf.Notification.MemberInvited,
constant.MemberEnterNotification: conf.Notification.MemberEnter,
constant.GroupDismissedNotification: conf.Notification.GroupDismissed,
constant.GroupMutedNotification: conf.Notification.GroupMuted,
constant.GroupCancelMutedNotification: conf.Notification.GroupCancelMuted,
constant.GroupMemberMutedNotification: conf.Notification.GroupMemberMuted,
constant.GroupMemberCancelMutedNotification: conf.Notification.GroupMemberCancelMuted,
constant.GroupMemberInfoSetNotification: conf.Notification.GroupMemberInfoSet,
constant.GroupMemberSetToAdminNotification: conf.Notification.GroupMemberSetToAdmin,
constant.GroupMemberSetToOrdinaryUserNotification: conf.Notification.GroupMemberSetToOrdinary,
constant.GroupInfoSetAnnouncementNotification: conf.Notification.GroupInfoSetAnnouncement,
constant.GroupInfoSetNameNotification: conf.Notification.GroupInfoSetName,
// user
constant.UserInfoUpdatedNotification: config.Config.Notification.UserInfoUpdated,
constant.UserStatusChangeNotification: config.Config.Notification.UserStatusChanged,
constant.UserInfoUpdatedNotification: conf.Notification.UserInfoUpdated,
constant.UserStatusChangeNotification: conf.Notification.UserStatusChanged,
// friend
constant.FriendApplicationNotification: config.Config.Notification.FriendApplicationAdded,
constant.FriendApplicationApprovedNotification: config.Config.Notification.FriendApplicationApproved,
constant.FriendApplicationRejectedNotification: config.Config.Notification.FriendApplicationRejected,
constant.FriendAddedNotification: config.Config.Notification.FriendAdded,
constant.FriendDeletedNotification: config.Config.Notification.FriendDeleted,
constant.FriendRemarkSetNotification: config.Config.Notification.FriendRemarkSet,
constant.BlackAddedNotification: config.Config.Notification.BlackAdded,
constant.BlackDeletedNotification: config.Config.Notification.BlackDeleted,
constant.FriendInfoUpdatedNotification: config.Config.Notification.FriendInfoUpdated,
constant.FriendsInfoUpdateNotification: config.Config.Notification.FriendInfoUpdated, //use the same FriendInfoUpdated
constant.FriendApplicationNotification: conf.Notification.FriendApplicationAdded,
constant.FriendApplicationApprovedNotification: conf.Notification.FriendApplicationApproved,
constant.FriendApplicationRejectedNotification: conf.Notification.FriendApplicationRejected,
constant.FriendAddedNotification: conf.Notification.FriendAdded,
constant.FriendDeletedNotification: conf.Notification.FriendDeleted,
constant.FriendRemarkSetNotification: conf.Notification.FriendRemarkSet,
constant.BlackAddedNotification: conf.Notification.BlackAdded,
constant.BlackDeletedNotification: conf.Notification.BlackDeleted,
constant.FriendInfoUpdatedNotification: conf.Notification.FriendInfoUpdated,
constant.FriendsInfoUpdateNotification: conf.Notification.FriendInfoUpdated, //use the same FriendInfoUpdated
// conversation
constant.ConversationChangeNotification: config.Config.Notification.ConversationChanged,
constant.ConversationUnreadNotification: config.Config.Notification.ConversationChanged,
constant.ConversationPrivateChatNotification: config.Config.Notification.ConversationSetPrivate,
constant.ConversationChangeNotification: conf.Notification.ConversationChanged,
constant.ConversationUnreadNotification: conf.Notification.ConversationChanged,
constant.ConversationPrivateChatNotification: conf.Notification.ConversationSetPrivate,
// msg
constant.MsgRevokeNotification: {IsSendMsg: false, ReliabilityLevel: constant.ReliableNotificationNoMsg},
constant.HasReadReceipt: {IsSendMsg: false, ReliabilityLevel: constant.ReliableNotificationNoMsg},
@@ -127,21 +129,22 @@ type Message struct {
conn grpc.ClientConnInterface
Client msg.MsgClient
discov discoveryregistry.SvcDiscoveryRegistry
Config *config.GlobalConfig
}
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, config *config.GlobalConfig) *Message {
conn, err := discov.GetConn(context.Background(), config.RpcRegisterName.OpenImMsgName)
if err != nil {
panic(err)
}
client := msg.NewMsgClient(conn)
return &Message{discov: discov, conn: conn, Client: client}
return &Message{discov: discov, conn: conn, Client: client, Config: config}
}
type MessageRpcClient Message
func NewMessageRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) MessageRpcClient {
return MessageRpcClient(*NewMessage(discov))
func NewMessageRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, config *config.GlobalConfig) MessageRpcClient {
return MessageRpcClient(*NewMessage(discov, config))
}
// SendMsg sends a message through the gRPC client and returns the response.
@@ -234,8 +237,8 @@ func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
}
}
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()}
func NewNotificationSender(config *config.GlobalConfig, opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(config), sessionTypeConf: newSessionTypeConf()}
for _, opt := range opts {
opt(notificationSender)
}
@@ -258,8 +261,8 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
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)
return err
errInfo := fmt.Sprintf("MsgClient Notification json.Marshal failed, sendID:%s, recvID:%s, contentType:%d, msg:%s", sendID, recvID, contentType, m)
return errs.Wrap(err, errInfo)
}
notificationOpt := &notificationOpt{}
for _, opt := range opts {
@@ -271,7 +274,8 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil {
userInfo, err = s.getUserInfo(ctx, sendID)
if err != nil {
log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID)
errInfo := fmt.Sprintf("getUserInfo failed, sendID:%s", sendID)
return errs.Wrap(err, errInfo)
} else {
msg.SenderNickname = userInfo.Nickname
msg.SenderFaceURL = userInfo.FaceURL
@@ -303,10 +307,9 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
msg.OfflinePushInfo = &offlineInfo
req.MsgData = &msg
_, err = s.sendMsg(ctx, &req)
if err == nil {
log.ZDebug(ctx, "MsgClient Notification SendMsg success", "req", &req)
} else {
log.ZError(ctx, "MsgClient Notification SendMsg failed", err, "req", &req)
if err != nil {
errInfo := fmt.Sprintf("MsgClient Notification SendMsg failed, req:%s", &req)
return errs.Wrap(err, errInfo)
}
return err
}