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