mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
refactor: user and conversation rpc config change.
This commit is contained in:
parent
177f7fdf99
commit
e6f1452974
@ -43,19 +43,18 @@ type authServer struct {
|
||||
}
|
||||
|
||||
func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
rdb, err := cache.NewRedis(config)
|
||||
rdb, err := cache.NewRedis(&config.Redis)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client, config)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client, config.RpcRegisterName.OpenImUserName)
|
||||
pbauth.RegisterAuthServer(server, &authServer{
|
||||
userRpcClient: &userRpcClient,
|
||||
RegisterCenter: client,
|
||||
authDatabase: controller.NewAuthDatabase(
|
||||
cache.NewMsgCacheModel(rdb, config),
|
||||
cache.NewMsgCacheModel(rdb, config.MsgCacheTimeout, &config.Redis),
|
||||
config.Secret,
|
||||
config.TokenPolicy.Expire,
|
||||
config,
|
||||
),
|
||||
config: config,
|
||||
})
|
||||
@ -81,12 +80,12 @@ func (s *authServer) UserToken(ctx context.Context, req *pbauth.UserTokenReq) (*
|
||||
}
|
||||
|
||||
func (s *authServer) GetUserToken(ctx context.Context, req *pbauth.GetUserTokenReq) (*pbauth.GetUserTokenResp, error) {
|
||||
if err := authverify.CheckAdmin(ctx, s.config); err != nil {
|
||||
if err := authverify.CheckAdmin(ctx, &s.config.Manager, &s.config.IMAdmin); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := pbauth.GetUserTokenResp{}
|
||||
|
||||
if authverify.IsManagerUserID(req.UserID, s.config) {
|
||||
if authverify.IsManagerUserID(req.UserID, &s.config.Manager, &s.config.IMAdmin) {
|
||||
return nil, errs.ErrNoPermission.Wrap("don't get Admin token")
|
||||
}
|
||||
|
||||
@ -143,7 +142,7 @@ func (s *authServer) ParseToken(
|
||||
}
|
||||
|
||||
func (s *authServer) ForceLogout(ctx context.Context, req *pbauth.ForceLogoutReq) (*pbauth.ForceLogoutResp, error) {
|
||||
if err := authverify.CheckAdmin(ctx, s.config); err != nil {
|
||||
if err := authverify.CheckAdmin(ctx, &s.config.Manager, &s.config.IMAdmin); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.forceKickOff(ctx, req.UserID, req.PlatformID, mcontext.GetOperationID(ctx)); err != nil {
|
||||
|
||||
@ -46,15 +46,14 @@ type conversationServer struct {
|
||||
groupRpcClient *rpcclient.GroupRpcClient
|
||||
conversationDatabase controller.ConversationDatabase
|
||||
conversationNotificationSender *notification.ConversationNotificationSender
|
||||
config *config.GlobalConfig
|
||||
}
|
||||
|
||||
func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
rdb, err := cache.NewRedis(config)
|
||||
rdb, err := cache.NewRedis(&config.Redis)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mongo, err := unrelation.NewMongo(config)
|
||||
mongo, err := unrelation.NewMongo(&config.Mongo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -62,16 +61,15 @@ func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryReg
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupRpcClient := rpcclient.NewGroupRpcClient(client, config)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client, config)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client, config)
|
||||
groupRpcClient := rpcclient.NewGroupRpcClient(client, config.RpcRegisterName.OpenImGroupName)
|
||||
msgRpcClient := rpcclient.NewMessageRpcClient(client, config.RpcRegisterName.OpenImMsgName)
|
||||
userRpcClient := rpcclient.NewUserRpcClient(client, config.RpcRegisterName.OpenImUserName)
|
||||
pbconversation.RegisterConversationServer(server, &conversationServer{
|
||||
msgRpcClient: &msgRpcClient,
|
||||
user: &userRpcClient,
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(config, &msgRpcClient),
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(&config.Notification, &msgRpcClient),
|
||||
groupRpcClient: &groupRpcClient,
|
||||
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewMongo(mongo.GetClient())),
|
||||
config: config,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -75,8 +75,8 @@ func ParseRedisInterfaceToken(redisToken any, secret string) (*tokenverify.Claim
|
||||
return tokenverify.GetClaimFromToken(string(redisToken.([]uint8)), Secret(secret))
|
||||
}
|
||||
|
||||
func IsManagerUserID(opUserID string, config *config.GlobalConfig) bool {
|
||||
return (len(config.Manager.UserID) > 0 && utils.IsContain(opUserID, config.Manager.UserID)) || utils.IsContain(opUserID, config.IMAdmin.UserID)
|
||||
func IsManagerUserID(opUserID string, manager *config.Manager, imAdmin *config.IMAdmin) bool {
|
||||
return (len(manager.UserID) > 0 && utils.IsContain(opUserID, manager.UserID)) || utils.IsContain(opUserID, imAdmin.UserID)
|
||||
}
|
||||
|
||||
func WsVerifyToken(token, userID, secret string, platformID int) error {
|
||||
|
||||
@ -382,14 +382,14 @@ type GlobalConfig struct {
|
||||
Callback Callback `yaml:"callback"`
|
||||
|
||||
Prometheus Prometheus `yaml:"prometheus"`
|
||||
Notification notification `yaml:"notification"`
|
||||
Notification Notification `yaml:"notification"`
|
||||
}
|
||||
|
||||
func NewGlobalConfig() *GlobalConfig {
|
||||
return &GlobalConfig{}
|
||||
}
|
||||
|
||||
type notification struct {
|
||||
type Notification struct {
|
||||
GroupCreated NotificationConf `yaml:"groupCreated"`
|
||||
GroupInfoSet NotificationConf `yaml:"groupInfoSet"`
|
||||
JoinGroupApplication NotificationConf `yaml:"joinGroupApplication"`
|
||||
|
||||
@ -33,47 +33,47 @@ import (
|
||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||
)
|
||||
|
||||
func newContentTypeConf(conf *config.GlobalConfig) map[int32]config.NotificationConf {
|
||||
func newContentTypeConf(conf *config.Notification) map[int32]config.NotificationConf {
|
||||
return map[int32]config.NotificationConf{
|
||||
// group
|
||||
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,
|
||||
constant.GroupCreatedNotification: conf.GroupCreated,
|
||||
constant.GroupInfoSetNotification: conf.GroupInfoSet,
|
||||
constant.JoinGroupApplicationNotification: conf.JoinGroupApplication,
|
||||
constant.MemberQuitNotification: conf.MemberQuit,
|
||||
constant.GroupApplicationAcceptedNotification: conf.GroupApplicationAccepted,
|
||||
constant.GroupApplicationRejectedNotification: conf.GroupApplicationRejected,
|
||||
constant.GroupOwnerTransferredNotification: conf.GroupOwnerTransferred,
|
||||
constant.MemberKickedNotification: conf.MemberKicked,
|
||||
constant.MemberInvitedNotification: conf.MemberInvited,
|
||||
constant.MemberEnterNotification: conf.MemberEnter,
|
||||
constant.GroupDismissedNotification: conf.GroupDismissed,
|
||||
constant.GroupMutedNotification: conf.GroupMuted,
|
||||
constant.GroupCancelMutedNotification: conf.GroupCancelMuted,
|
||||
constant.GroupMemberMutedNotification: conf.GroupMemberMuted,
|
||||
constant.GroupMemberCancelMutedNotification: conf.GroupMemberCancelMuted,
|
||||
constant.GroupMemberInfoSetNotification: conf.GroupMemberInfoSet,
|
||||
constant.GroupMemberSetToAdminNotification: conf.GroupMemberSetToAdmin,
|
||||
constant.GroupMemberSetToOrdinaryUserNotification: conf.GroupMemberSetToOrdinary,
|
||||
constant.GroupInfoSetAnnouncementNotification: conf.GroupInfoSetAnnouncement,
|
||||
constant.GroupInfoSetNameNotification: conf.GroupInfoSetName,
|
||||
// user
|
||||
constant.UserInfoUpdatedNotification: conf.Notification.UserInfoUpdated,
|
||||
constant.UserStatusChangeNotification: conf.Notification.UserStatusChanged,
|
||||
constant.UserInfoUpdatedNotification: conf.UserInfoUpdated,
|
||||
constant.UserStatusChangeNotification: conf.UserStatusChanged,
|
||||
// friend
|
||||
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
|
||||
constant.FriendApplicationNotification: conf.FriendApplicationAdded,
|
||||
constant.FriendApplicationApprovedNotification: conf.FriendApplicationApproved,
|
||||
constant.FriendApplicationRejectedNotification: conf.FriendApplicationRejected,
|
||||
constant.FriendAddedNotification: conf.FriendAdded,
|
||||
constant.FriendDeletedNotification: conf.FriendDeleted,
|
||||
constant.FriendRemarkSetNotification: conf.FriendRemarkSet,
|
||||
constant.BlackAddedNotification: conf.BlackAdded,
|
||||
constant.BlackDeletedNotification: conf.BlackDeleted,
|
||||
constant.FriendInfoUpdatedNotification: conf.FriendInfoUpdated,
|
||||
constant.FriendsInfoUpdateNotification: conf.FriendInfoUpdated, //use the same FriendInfoUpdated
|
||||
// conversation
|
||||
constant.ConversationChangeNotification: conf.Notification.ConversationChanged,
|
||||
constant.ConversationUnreadNotification: conf.Notification.ConversationChanged,
|
||||
constant.ConversationPrivateChatNotification: conf.Notification.ConversationSetPrivate,
|
||||
constant.ConversationChangeNotification: conf.ConversationChanged,
|
||||
constant.ConversationUnreadNotification: conf.ConversationChanged,
|
||||
constant.ConversationPrivateChatNotification: conf.ConversationSetPrivate,
|
||||
// msg
|
||||
constant.MsgRevokeNotification: {IsSendMsg: false, ReliabilityLevel: constant.ReliableNotificationNoMsg},
|
||||
constant.HasReadReceipt: {IsSendMsg: false, ReliabilityLevel: constant.ReliableNotificationNoMsg},
|
||||
@ -238,8 +238,8 @@ func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func NewNotificationSender(config *config.GlobalConfig, opts ...NotificationSenderOptions) *NotificationSender {
|
||||
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(config), sessionTypeConf: newSessionTypeConf()}
|
||||
func NewNotificationSender(conf *config.Notification, opts ...NotificationSenderOptions) *NotificationSender {
|
||||
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(conf), sessionTypeConf: newSessionTypeConf()}
|
||||
for _, opt := range opts {
|
||||
opt(notificationSender)
|
||||
}
|
||||
|
||||
@ -28,8 +28,8 @@ type ConversationNotificationSender struct {
|
||||
*rpcclient.NotificationSender
|
||||
}
|
||||
|
||||
func NewConversationNotificationSender(config *config.GlobalConfig, msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender {
|
||||
return &ConversationNotificationSender{rpcclient.NewNotificationSender(config, rpcclient.WithRpcClient(msgRpcClient))}
|
||||
func NewConversationNotificationSender(conf *config.Notification, msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender {
|
||||
return &ConversationNotificationSender{rpcclient.NewNotificationSender(conf, rpcclient.WithRpcClient(msgRpcClient))}
|
||||
}
|
||||
|
||||
// SetPrivate invote.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user