mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-07-07 12:21:10 +08:00
Compare commits
3 Commits
95b49391e7
...
59ea752002
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ea752002 | ||
|
|
a5ac7f2a81 | ||
|
|
5556e89fa3 |
104
config/README.md
104
config/README.md
@ -1,48 +1,66 @@
|
||||
---
|
||||
title: 'OpenIM Configuration Files and Common Configuration Item Modifications Guide'
|
||||
# OpenIM Configuration File Descriptions and Common Configuration Modifications
|
||||
|
||||
## Configuration Files Explanation
|
||||
## External Component Configurations
|
||||
|
||||
| Configuration File | Description |
|
||||
| ------------------------------- | ------------------------------------------------------------ |
|
||||
| **kafka.yml** | Configurations for Kafka username, password, address, etc. |
|
||||
| **redis.yml** | Configurations for Redis password, address, etc. |
|
||||
| **minio.yml** | Configurations for MinIO username, password, address, and external IP/domain; failing to modify external IP or domain may cause image file sending failures |
|
||||
| **zookeeper.yml** | Configurations for ZooKeeper user, password, address, etc. |
|
||||
| **mongodb.yml** | Configurations for MongoDB username, password, address, etc. |
|
||||
| **log.yml** | Configurations for log level and storage directory. |
|
||||
| **notification.yml** | Configurations for events like adding friends, creating groups, etc. |
|
||||
| **share.yml** | Common configurations needed by various OpenIM services, such as secret. |
|
||||
| **webhooks.yml** | Configurations for URLs in Webhook. |
|
||||
| **local-cache.yml** | Local cache configurations. |
|
||||
| **openim-rpc-third.yml** | Configurations for listening IP, port, and storage settings for images and videos in openim-rpc-third service. |
|
||||
| **openim-rpc-user.yml** | Configurations for listening IP and port in openim-rpc-user service. |
|
||||
| **openim-api.yml** | Configurations for listening IP, port, etc., in openim-api service. |
|
||||
| **openim-crontask.yml** | Configurations for openim-crontask service. |
|
||||
| **openim-msggateway.yml** | Configurations for listening IP, port, etc., in openim-msggateway service. |
|
||||
| **openim-msgtransfer.yml** | Configurations for openim-msgtransfer service. |
|
||||
| **openim-push.yml** | Configurations for listening IP, port, and offline push settings in openim-push service. |
|
||||
| **openim-rpc-auth.yml** | Configurations for listening IP, port, and token expiration settings in openim-rpc-auth service. |
|
||||
| **openim-rpc-conversation.yml** | Configurations for listening IP, port, etc., in openim-rpc-conversation service. |
|
||||
| **openim-rpc-friend.yml** | Configurations for listening IP, port, etc., in openim-rpc-friend service. |
|
||||
| **openim-rpc-group.yml** | Configurations for listening IP, port, etc., in openim-rpc-group service. |
|
||||
| **openim-rpc-msg.yml** | Configurations for listening IP, port, and whether to verify friendship before sending messages in openim-rpc-msg service. |
|
||||
| Configuration File | Description |
|
||||
| ------------------ |-------------------------------------------------------------|
|
||||
| **kafka.yml** | Configuration for Kafka username, password, address, etc. |
|
||||
| **redis.yml** | Configuration for Redis password, address, etc. |
|
||||
| **minio.yml** | Configuration for MinIO username, password, address, etc. |
|
||||
| **mongodb.yml** | Configuration for MongoDB username, password, address, etc. |
|
||||
| **discovery.yml** | Service discovery and etcd credentials and address. |
|
||||
|
||||
## Common Configuration Item Modifications
|
||||
## OpenIMServer Related Configurations
|
||||
| Configuration File | Description |
|
||||
| ------------------------------- | ---------------------------------------------- |
|
||||
| **log.yml** | Configuration for logging levels and storage directory |
|
||||
| **notification.yml** | Event notification settings (e.g., add friend, create group) |
|
||||
| **share.yml** | Common settings for all services (e.g., secrets) |
|
||||
| **webhooks.yml** | Webhook URLs and related settings |
|
||||
| **local-cache.yml** | Local cache settings (generally do not modify) |
|
||||
| **openim-rpc-third.yml** | openim-rpc-third listen IP, port, and object storage settings |
|
||||
| **openim-rpc-user.yml** | openim-rpc-user listen IP and port settings |
|
||||
| **openim-api.yml** | openim-api listen IP, port, and other settings |
|
||||
| **openim-crontask.yml** | openim-crontask scheduled task settings |
|
||||
| **openim-msggateway.yml** | openim-msggateway listen IP, port, and other settings |
|
||||
| **openim-msgtransfer.yml** | Settings for openim-msgtransfer service |
|
||||
| **openim-push.yml** | openim-push listen IP, port, and offline push settings |
|
||||
| **openim-rpc-auth.yml** | openim-rpc-auth listen IP, port, token validity settings |
|
||||
| **openim-rpc-conversation.yml** | openim-rpc-conversation listen IP and port settings |
|
||||
| **openim-rpc-friend.yml** | openim-rpc-friend listen IP and port settings |
|
||||
| **openim-rpc-group.yml** | openim-rpc-group listen IP and port settings |
|
||||
| **openim-rpc-msg.yml** | openim-rpc-msg listen IP and port settings |
|
||||
|
||||
| Configuration Item Modification | Configuration File |
|
||||
| ----------------------------------------------------- | ----------------------- |
|
||||
| Using MinIO for image and video file object storage | `minio.yml` |
|
||||
| Adjusting production environment logs | `log.yml` |
|
||||
| Verifying friendship before sending messages | `openim-rpc-msg.yml` |
|
||||
| Modifying secret | `share.yml` |
|
||||
| Using OSS, COS, AWS, Kodo for image and video storage | `openim-rpc-third.yml` |
|
||||
| Setting multiple login policy | `openim-msggateway.yml` |
|
||||
| Setting up offline push | `openim-push.yml` |
|
||||
|
||||
## Starting Multiple Instances of an OpenIM Service
|
||||
## Monitoring and Alerting Related Configurations
|
||||
| Configuration File | Description |
|
||||
| ------------------------------ | --------------- |
|
||||
| **prometheus.yml** | Prometheus configuration |
|
||||
| **instance-down-rules.yml** | Alert rules |
|
||||
| **alertmanager.yml** | Alertmanager configuration |
|
||||
| **email.tmpl** | Email alert template |
|
||||
| **grefana-template/Demo.json** | Default Grafana dashboard |
|
||||
|
||||
To start multiple instances of an OpenIM service, simply increase the corresponding port numbers and modify the `start-config.yml` file in the project root directory. Restart the service to take effect. For example, the configuration to start 2 instances of `openim-rpc-user` is as follows:
|
||||
## Common Configuration Modifications
|
||||
| Configuration Item | Configuration File |
|
||||
| -------------------------------------------------------- | ----------------------- |
|
||||
| Configure MinIO as object storage (focus on the externalAddress field) | `minio.yml` |
|
||||
| Adjust log level and number of log files | `log.yml` |
|
||||
| Enable or disable friend verification when sending messages | `openim-rpc-msg.yml` |
|
||||
| OpenIMServer secret | `share.yml` |
|
||||
| Configure OSS, COS, AWS, or Kodo as object storage | `openim-rpc-third.yml` |
|
||||
| Multi-end mutual kick strategy and max concurrent connections per gateway | `openim-msggateway.yml` |
|
||||
| Offline message push configuration | `openim-push.yml` |
|
||||
| Configure webhooks for callback notifications (e.g., before/after message send) | `webhooks.yml` |
|
||||
| Whether new group members can view historical messages | `openim-rpc-group.yml` |
|
||||
| Token expiration time settings | `openim-rpc-auth.yml` |
|
||||
| Scheduled task settings (e.g., how long to retain messages) | `openim-crontask.yml` |
|
||||
|
||||
## Starting Multiple Instances of a Service and Maximum File Descriptors
|
||||
|
||||
|
||||
To start multiple instances of an OpenIM service, simply add the corresponding port numbers and modify the `start-config.yml` file in the project’s root directory,
|
||||
then restart the service. For example, to start 2 instances of `openim-rpc-user`:
|
||||
|
||||
```yaml
|
||||
rpc:
|
||||
@ -55,9 +73,15 @@ prometheus:
|
||||
ports: [ 20100, 20101 ]
|
||||
```
|
||||
|
||||
Modify `start-config.yml`:
|
||||
Modify`start-config.yml`:
|
||||
|
||||
```yaml
|
||||
serviceBinaries:
|
||||
openim-rpc-user: 2
|
||||
```
|
||||
|
||||
To set the maximum number of open file descriptors (typically one per online user):
|
||||
|
||||
```
|
||||
maxFileDescriptors: 10000
|
||||
```
|
||||
|
||||
@ -1,45 +1,63 @@
|
||||
# OpenIM配置文件说明以及常用配置修改说明
|
||||
|
||||
## 配置文件说明
|
||||
## 外部组件相关配置
|
||||
|
||||
| Configuration File | Description |
|
||||
| ------------------------------- | ------------------------------------------------------------ |
|
||||
| **kafka.yml** | Kafka用户名、密码、地址等配置 |
|
||||
| **redis.yml** | Redis密码、地址等配置 |
|
||||
| **minio.yml** | MinIO用户名、密码、地址及外网IP域名等配置;未修改外网IP或域名可能导致图片文件发送失败 |
|
||||
| **zookeeper.yml** | ZooKeeper用户、密码、地址等配置 |
|
||||
| **mongodb.yml** | MongoDB用户名、密码、地址等配置 |
|
||||
| **log.yml** | 日志级别及存储目录等配置 |
|
||||
| **notification.yml** | 添加好友、创建群组等事件通知配置 |
|
||||
| **share.yml** | OpenIM各服务所需的公共配置,如secret等 |
|
||||
| **webhooks.yml** | Webhook中URL等配置 |
|
||||
| **local-cache.yml** | 本地缓存配置 |
|
||||
| **openim-rpc-third.yml** | openim-rpc-third服务的监听IP、端口及图片视频对象存储配置 |
|
||||
| **openim-rpc-user.yml** | openim-rpc-user服务的监听IP、端口配置 |
|
||||
| **openim-api.yml** | openim-api服务的监听IP、端口等配置项 |
|
||||
| **openim-crontask.yml** | openim-crontask服务配置 |
|
||||
| **openim-msggateway.yml** | openim-msggateway服务的监听IP、端口等配置 |
|
||||
| **openim-msgtransfer.yml** | openim-msgtransfer服务配置 |
|
||||
| **openim-push.yml** | openim-push服务的监听IP、端口及离线推送配置 |
|
||||
| **openim-rpc-auth.yml** | openim-rpc-auth服务的监听IP、端口及token有效期等配置 |
|
||||
| **openim-rpc-conversation.yml** | openim-rpc-conversation服务的监听IP、端口等配置 |
|
||||
| **openim-rpc-friend.yml** | openim-rpc-friend服务的监听IP、端口等配置 |
|
||||
| **openim-rpc-group.yml** | openim-rpc-group服务的监听IP、端口等配置 |
|
||||
| **openim-rpc-msg.yml** | openim-rpc-msg服务的监听IP、端口及消息发送是否验证好友关系等配置 |
|
||||
| Configuration File | Description |
|
||||
| ------------------ | ---------------------------------- |
|
||||
| **kafka.yml** | Kafka用户名、密码、地址等配置 |
|
||||
| **redis.yml** | Redis密码、地址等配置 |
|
||||
| **minio.yml** | MinIO用户名、密码、地址等配置 |
|
||||
| **mongodb.yml** | MongoDB用户名、密码、地址等配置 |
|
||||
| **discovery.yml** | 服务发现以及etcd用户名、密码、地址 |
|
||||
|
||||
## OpenIMServer相关配置
|
||||
| Configuration File | Description |
|
||||
| ------------------------------- | ---------------------------------------------- |
|
||||
| **log.yml** | 日志级别及存储目录等配置 |
|
||||
| **notification.yml** | 添加好友、创建群组等事件通知配置 |
|
||||
| **share.yml** | 各服务所需的公共配置,如secret等 |
|
||||
| **webhooks.yml** | Webhook中URL等配置 |
|
||||
| **local-cache.yml** | 本地缓存配置,一般不用修改 |
|
||||
| **openim-rpc-third.yml** | openim-rpc-third监听IP、端口及对象存储配置 |
|
||||
| **openim-rpc-user.yml** | openim-rpc-user监听IP、端口配置 |
|
||||
| **openim-api.yml** | openim-api监听IP、端口等配置 |
|
||||
| **openim-crontask.yml** | openim-crontask定时任务配置 |
|
||||
| **openim-msggateway.yml** | openim-msggateway监听IP、端口等配置 |
|
||||
| **openim-msgtransfer.yml** | openim-msgtransfer服务配置 |
|
||||
| **openim-push.yml** | openim-push监听IP、端口及离线推送配置 |
|
||||
| **openim-rpc-auth.yml** | openim-rpc-auth监听IP、端口及token有效期等配置 |
|
||||
| **openim-rpc-conversation.yml** | openim-rpc-conversation监听IP、端口等配置 |
|
||||
| **openim-rpc-friend.yml** | openim-rpc-friend监听IP、端口等配置 |
|
||||
| **openim-rpc-group.yml** | openim-rpc-group监听IP、端口等配置 |
|
||||
| **openim-rpc-msg.yml** | openim-rpc-msg服务的监听IP、端口等配置 |
|
||||
|
||||
|
||||
## 监控告警相关配置
|
||||
| Configuration File | Description |
|
||||
| ------------------------------ | --------------- |
|
||||
| **prometheus.yml** | prometheus配置 |
|
||||
| **instance-down-rules.yml** | 告警规则 |
|
||||
| **alertmanager.yml** | 告警管理配置 |
|
||||
| **email.tmpl** | 邮件告警模版 |
|
||||
| **grefana-template/Demo.json** | 默认的dashboard |
|
||||
|
||||
## 常用配置修改
|
||||
| 修改配置项 | 配置文件 |
|
||||
| -------------------------------------------------------- | ----------------------- |
|
||||
| 使用minio作为对象存储时配置,重点关注externalAddress字段 | `minio.yml` |
|
||||
| 日志级别及日志文件数量调整 | `log.yml` |
|
||||
| 发送消息是否需要验证好友关系 | `openim-rpc-msg.yml` |
|
||||
| OpenIMServer秘钥 | `share.yml` |
|
||||
| 使用oss, cos, aws, kodo作为对象存储时配置 | `openim-rpc-third.yml` |
|
||||
| 多端互踢策略,单个gateway同时最大连接数 | `openim-msggateway.yml` |
|
||||
| 消息离线推送 | `openim-push.yml` |
|
||||
| 配置webhook来通知回调服务器,如消息发送前后回调 | `webhooks.yml` |
|
||||
| 新入群用户是否可以查看历史消息 | `openim-rpc-group.yml` |
|
||||
| token 过期时间设置 | `openim-rpc-auth.yml` |
|
||||
| 定时任务设置,例如消息保存多长时间 | `openim-crontask.yml` |
|
||||
|
||||
| 修改配置项 | 配置文件 |
|
||||
| ----------------------------------------------- | ----------------------- |
|
||||
| 使用minio作为图片视频文件对象存储 | `minio.yml` |
|
||||
| 生产环境日志调整 | `log.yml` |
|
||||
| 发送消息是否验证好友关系 | `openim-rpc-msg.yml` |
|
||||
| 修改secret | `share.yml` |
|
||||
| 使用oss, cos, aws, kodo作为图片视频文件对象存储 | `openim-rpc-third.yml` |
|
||||
| 设置多端互踢策略 | `openim-msggateway.yml` |
|
||||
| 设置离线推送 | `openim-push.yml` |
|
||||
## 启动某个服务的多个实例和最大文件句柄数
|
||||
|
||||
## 启动某个OpenIM服务的多个实例
|
||||
|
||||
若要启动某个OpenIM的多个实例,只需增加对应的端口数,并修改项目根目录下的`start-config.yml`文件,重启服务即可生效。例如,启动2个`openim-rpc-user`实例的配置如下:
|
||||
|
||||
@ -61,5 +79,8 @@ serviceBinaries:
|
||||
openim-rpc-user: 2
|
||||
```
|
||||
|
||||
修改最大同时打开的文件句柄数,一般是每个在线用户占用一个
|
||||
|
||||
|
||||
```
|
||||
maxFileDescriptors: 10000
|
||||
```
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
secret: openIM123
|
||||
|
||||
imAdminUserID: [imAdmin]
|
||||
# imAdminUser: Configuration for instant messaging system administrators
|
||||
imAdminUser:
|
||||
# userIDs: List of administrator user IDs.
|
||||
# Each entry here corresponds by index to the matching entry in the nicknames list below.
|
||||
userIDs: [imAdmin]
|
||||
# nicknames: List of administrator display names.
|
||||
# Each entry here corresponds by index to the matching entry in the userIDs list above.
|
||||
nicknames: [superAdmin]
|
||||
|
||||
# 1: For Android, iOS, Windows, Mac, and web platforms, only one instance can be online at a time
|
||||
multiLogin:
|
||||
|
||||
@ -98,7 +98,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf
|
||||
r.Use(gzip.Gzip(gzip.BestSpeed))
|
||||
}
|
||||
r.Use(api.GinLogger(), prommetricsGin(), gin.RecoveryWithWriter(gin.DefaultErrorWriter, mw.GinPanicErr), mw.CorsHandler(),
|
||||
mw.GinParseOperationID(), GinParseToken(rpcli.NewAuthClient(authConn)), setGinIsAdmin(cfg.Share.IMAdminUserID))
|
||||
mw.GinParseOperationID(), GinParseToken(rpcli.NewAuthClient(authConn)), setGinIsAdmin(cfg.Share.IMAdminUser.UserIDs))
|
||||
|
||||
u := NewUserApi(user.NewUserClient(userConn), client, cfg.Discovery.RpcService)
|
||||
{
|
||||
@ -232,7 +232,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf
|
||||
objectGroup.GET("/*name", t.ObjectRedirect)
|
||||
}
|
||||
// Message
|
||||
m := NewMessageApi(msg.NewMsgClient(msgConn), rpcli.NewUserClient(userConn), cfg.Share.IMAdminUserID)
|
||||
m := NewMessageApi(msg.NewMsgClient(msgConn), rpcli.NewUserClient(userConn), cfg.Share.IMAdminUser.UserIDs)
|
||||
{
|
||||
msgGroup := r.Group("/msg")
|
||||
msgGroup.POST("/newest_seq", m.GetSeq)
|
||||
@ -309,7 +309,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf
|
||||
if cfg.Discovery.Enable == config.ETCD {
|
||||
etcdClient = client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
||||
}
|
||||
cm := NewConfigManager(cfg.Share.IMAdminUserID, &cfg.AllConfig, etcdClient, string(cfg.ConfigPath))
|
||||
cm := NewConfigManager(cfg.Share.IMAdminUser.UserIDs, &cfg.AllConfig, etcdClient, string(cfg.ConfigPath))
|
||||
{
|
||||
configGroup := r.Group("/config", cm.CheckAdmin)
|
||||
configGroup.POST("/get_config_list", cm.GetConfigList)
|
||||
|
||||
@ -130,7 +130,7 @@ func NewWsServer(msgGatewayConfig *Config, opts ...Option) *WsServer {
|
||||
for _, o := range opts {
|
||||
o(&config)
|
||||
}
|
||||
//userRpcClient := rpcclient.NewUserRpcClient(client, config.Discovery.RpcService.User, config.Share.IMAdminUserID)
|
||||
//userRpcClient := rpcclient.NewUserRpcClient(client, config.Discovery.RpcService.User, config.Share.IMAdminUser)
|
||||
|
||||
v := validator.New()
|
||||
return &WsServer{
|
||||
|
||||
@ -317,8 +317,8 @@ func (c *ConsumerHandler) groupMessagesHandler(ctx context.Context, groupID stri
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(*pushToUserIDs), "list", pushToUserIDs)
|
||||
if len(c.config.Share.IMAdminUserID) > 0 {
|
||||
ctx = mcontext.WithOpUserIDContext(ctx, c.config.Share.IMAdminUserID[0])
|
||||
if len(c.config.Share.IMAdminUser.UserIDs) > 0 {
|
||||
ctx = mcontext.WithOpUserIDContext(ctx, c.config.Share.IMAdminUser.UserIDs[0])
|
||||
}
|
||||
defer func(groupID string) {
|
||||
if err := c.groupClient.DismissGroup(ctx, groupID, true); err != nil {
|
||||
|
||||
@ -49,6 +49,7 @@ type authServer struct {
|
||||
RegisterCenter discovery.Conn
|
||||
config *Config
|
||||
userClient *rpcli.UserClient
|
||||
adminUserIDs []string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -90,10 +91,11 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
||||
config.Share.Secret,
|
||||
config.RpcConfig.TokenPolicy.Expire,
|
||||
config.Share.MultiLogin,
|
||||
config.Share.IMAdminUserID,
|
||||
config.Share.IMAdminUser.UserIDs,
|
||||
),
|
||||
config: config,
|
||||
userClient: rpcli.NewUserClient(userConn),
|
||||
config: config,
|
||||
userClient: rpcli.NewUserClient(userConn),
|
||||
adminUserIDs: config.Share.IMAdminUser.UserIDs,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@ -104,8 +106,8 @@ func (s *authServer) GetAdminToken(ctx context.Context, req *pbauth.GetAdminToke
|
||||
return nil, errs.ErrNoPermission.WrapMsg("secret invalid")
|
||||
}
|
||||
|
||||
if !datautil.Contain(req.UserID, s.config.Share.IMAdminUserID...) {
|
||||
return nil, errs.ErrArgs.WrapMsg("userID is error.", "userID", req.UserID, "adminUserID", s.config.Share.IMAdminUserID)
|
||||
if !datautil.Contain(req.UserID, s.adminUserIDs...) {
|
||||
return nil, errs.ErrArgs.WrapMsg("userID is error.", "userID", req.UserID, "adminUserID", s.adminUserIDs)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -63,6 +63,7 @@ type groupServer struct {
|
||||
userClient *rpcli.UserClient
|
||||
msgClient *rpcli.MsgClient
|
||||
conversationClient *rpcli.ConversationClient
|
||||
adminUserIDs []string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -116,6 +117,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
||||
userClient: rpcli.NewUserClient(userConn),
|
||||
msgClient: rpcli.NewMsgClient(msgConn),
|
||||
conversationClient: rpcli.NewConversationClient(conversationConn),
|
||||
adminUserIDs: config.Share.IMAdminUser.UserIDs,
|
||||
}
|
||||
gs.db = controller.NewGroupDatabase(rdb, &config.LocalCacheConfig, groupDB, groupMemberDB, groupRequestDB, mgocli.GetTx(), grouphash.NewGroupHashFromGroupServer(&gs))
|
||||
gs.notification = NewNotificationSender(gs.db, config, gs.userClient, gs.msgClient, gs.conversationClient)
|
||||
@ -1901,7 +1903,7 @@ func (g *groupServer) GetSpecifiedUserGroupRequestInfo(ctx context.Context, req
|
||||
}
|
||||
|
||||
adminIDs = append(adminIDs, owners[0].UserID)
|
||||
adminIDs = append(adminIDs, g.config.Share.IMAdminUserID...)
|
||||
adminIDs = append(adminIDs, g.adminUserIDs...)
|
||||
|
||||
if !datautil.Contain(opUserID, adminIDs...) {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("opUser no permission")
|
||||
|
||||
@ -109,8 +109,8 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
|
||||
revokerUserID := mcontext.GetOpUserID(ctx)
|
||||
var flag bool
|
||||
|
||||
if len(m.config.Share.IMAdminUserID) > 0 {
|
||||
flag = datautil.Contain(revokerUserID, m.config.Share.IMAdminUserID...)
|
||||
if len(m.config.Share.IMAdminUser.UserIDs) > 0 {
|
||||
flag = datautil.Contain(revokerUserID, m.adminUserIDs...)
|
||||
}
|
||||
tips := sdkws.RevokeMsgTips{
|
||||
RevokerUserID: revokerUserID,
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/dbbuild"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/mqbuild"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
@ -71,6 +70,8 @@ type msgServer struct {
|
||||
config *Config // Global configuration settings.
|
||||
webhookClient *webhook.Client
|
||||
conversationClient *rpcli.ConversationClient
|
||||
|
||||
adminUserIDs []string
|
||||
}
|
||||
|
||||
func (m *msgServer) addInterceptorHandler(interceptorFunc ...MessageInterceptorFunc) {
|
||||
@ -145,6 +146,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
||||
config: config,
|
||||
webhookClient: webhook.NewWebhookClient(config.WebhooksConfig.URL),
|
||||
conversationClient: conversationClient,
|
||||
adminUserIDs: config.Share.IMAdminUser.UserIDs,
|
||||
}
|
||||
|
||||
s.notificationSender = notification.NewNotificationSender(&config.NotificationConfig, notification.WithLocalSendMsg(s.SendMsg))
|
||||
|
||||
@ -54,7 +54,7 @@ type MessageRevoked struct {
|
||||
func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) error {
|
||||
switch data.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
if datautil.Contain(data.MsgData.SendID, m.config.Share.IMAdminUserID...) {
|
||||
if datautil.Contain(data.MsgData.SendID, m.adminUserIDs...) {
|
||||
return nil
|
||||
}
|
||||
if data.MsgData.ContentType <= constant.NotificationEnd &&
|
||||
@ -102,7 +102,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
|
||||
return nil
|
||||
}
|
||||
|
||||
if datautil.Contain(data.MsgData.SendID, m.config.Share.IMAdminUserID...) {
|
||||
if datautil.Contain(data.MsgData.SendID, m.adminUserIDs...) {
|
||||
return nil
|
||||
}
|
||||
if data.MsgData.ContentType <= constant.NotificationEnd &&
|
||||
|
||||
@ -65,6 +65,8 @@ type userServer struct {
|
||||
groupClient *rpcli.GroupClient
|
||||
relationClient *rpcli.RelationClient
|
||||
clientConfig controller.ClientConfigDatabase
|
||||
|
||||
adminUserIDs []string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -92,8 +94,12 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
||||
|
||||
users := make([]*tablerelation.User, 0)
|
||||
|
||||
for _, v := range config.Share.IMAdminUserID {
|
||||
users = append(users, &tablerelation.User{UserID: v, Nickname: v, AppMangerLevel: constant.AppAdmin})
|
||||
for i := range config.Share.IMAdminUser.UserIDs {
|
||||
users = append(users, &tablerelation.User{
|
||||
UserID: config.Share.IMAdminUser.UserIDs[i],
|
||||
Nickname: config.Share.IMAdminUser.Nicknames[i],
|
||||
AppMangerLevel: constant.AppAdmin,
|
||||
})
|
||||
}
|
||||
userDB, err := mgo.NewUserMongo(mgocli.GetDB())
|
||||
if err != nil {
|
||||
@ -130,6 +136,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
||||
clientConfig: controller.NewClientConfigDatabase(clientConfigDB, redis.NewClientConfigCache(rdb, clientConfigDB), mgocli.GetTx()),
|
||||
groupClient: rpcli.NewGroupClient(groupConn),
|
||||
relationClient: rpcli.NewRelationClient(friendConn),
|
||||
adminUserIDs: config.Share.IMAdminUser.UserIDs,
|
||||
}
|
||||
pbuser.RegisterUserServer(server, u)
|
||||
return u.db.InitOnce(context.Background(), users)
|
||||
@ -648,7 +655,7 @@ func (s *userServer) userModelToResp(users []*tablerelation.User, pagination pag
|
||||
accounts := make([]*pbuser.NotificationAccountInfo, 0)
|
||||
var total int64
|
||||
for _, v := range users {
|
||||
if v.AppMangerLevel >= constant.AppNotificationAdmin && !datautil.Contain(v.UserID, s.config.Share.IMAdminUserID...) {
|
||||
if v.AppMangerLevel >= constant.AppNotificationAdmin && !datautil.Contain(v.UserID, s.adminUserIDs...) {
|
||||
if appManagerLevel != nil {
|
||||
if v.AppMangerLevel != *appManagerLevel {
|
||||
continue
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
"github.com/openimsdk/protocol/third"
|
||||
"github.com/openimsdk/tools/discovery"
|
||||
"github.com/openimsdk/tools/discovery/etcd"
|
||||
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"github.com/openimsdk/tools/log"
|
||||
"github.com/openimsdk/tools/mcontext"
|
||||
@ -32,7 +31,7 @@ func Start(ctx context.Context, conf *Config, client discovery.SvcDiscoveryRegis
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
}
|
||||
ctx = mcontext.SetOpUserID(ctx, conf.Share.IMAdminUserID[0])
|
||||
ctx = mcontext.SetOpUserID(ctx, conf.Share.IMAdminUser.UserIDs[0])
|
||||
|
||||
msgConn, err := client.GetConn(ctx, conf.Discovery.RpcService.Msg)
|
||||
if err != nil {
|
||||
|
||||
@ -356,8 +356,11 @@ type AfterConfig struct {
|
||||
}
|
||||
|
||||
type Share struct {
|
||||
Secret string `yaml:"secret"`
|
||||
IMAdminUserID []string `yaml:"imAdminUserID"`
|
||||
Secret string `yaml:"secret"`
|
||||
IMAdminUser struct {
|
||||
UserIDs []string `yaml:"userIDs"`
|
||||
Nicknames []string `yaml:"nicknames"`
|
||||
} `yaml:"imAdminUser"`
|
||||
MultiLogin MultiLogin `yaml:"multiLogin"`
|
||||
RPCMaxBodySize MaxRequestBody `yaml:"rpcMaxBodySize"`
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
||||
grpcsrv.GrpcServerRequestValidate(),
|
||||
grpcsrv.GrpcServerPanicCapture(),
|
||||
)
|
||||
if shareConfig != nil && len(shareConfig.IMAdminUserID) > 0 {
|
||||
options = append(options, grpcServerIMAdminUserID(shareConfig.IMAdminUserID))
|
||||
if shareConfig != nil && len(shareConfig.IMAdminUser.UserIDs) > 0 {
|
||||
options = append(options, grpcServerIMAdminUserID(shareConfig.IMAdminUser.UserIDs))
|
||||
}
|
||||
var clientOptions []grpc.DialOption
|
||||
if maxRequestBody != nil {
|
||||
|
||||
@ -97,16 +97,34 @@ func (u *userDatabase) InitOnce(ctx context.Context, users []*model.User) error
|
||||
}
|
||||
|
||||
// Determine which users are missing from the database.
|
||||
missingUsers := datautil.SliceAnySub(users, existingUsers, func(e *model.User) string {
|
||||
var (
|
||||
missing, update []*model.User
|
||||
)
|
||||
existMap := datautil.SliceToMap(existingUsers, func(e *model.User) string {
|
||||
return e.UserID
|
||||
})
|
||||
orgMap := datautil.SliceToMap(users, func(e *model.User) string { return e.UserID })
|
||||
for k, u1 := range orgMap {
|
||||
if u2, ok := existMap[k]; !ok {
|
||||
missing = append(missing, u1)
|
||||
} else if u1.Nickname != u2.Nickname {
|
||||
update = append(update, u1)
|
||||
}
|
||||
}
|
||||
|
||||
// Create records for missing users.
|
||||
if len(missingUsers) > 0 {
|
||||
if err := u.userDB.Create(ctx, missingUsers); err != nil {
|
||||
if len(missing) > 0 {
|
||||
if err := u.userDB.Create(ctx, missing); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(update) > 0 {
|
||||
for i := range update {
|
||||
if err := u.userDB.UpdateByMap(ctx, update[i].UserID, map[string]any{"nickname": update[i].Nickname}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -446,7 +446,7 @@ func main() {
|
||||
Share: *share,
|
||||
Api: *apiConfig,
|
||||
},
|
||||
AdminUserID: share.IMAdminUserID[0],
|
||||
AdminUserID: share.IMAdminUser.UserIDs[0],
|
||||
Ctx: ctx,
|
||||
Cancel: cancel,
|
||||
HttpClient: &http.Client{
|
||||
|
||||
@ -319,7 +319,7 @@ func main() {
|
||||
Share: *share,
|
||||
Api: *apiConfig,
|
||||
},
|
||||
AdminUserID: share.IMAdminUserID[0],
|
||||
AdminUserID: share.IMAdminUser.UserIDs[0],
|
||||
Ctx: ctx,
|
||||
Cancel: cancel,
|
||||
HttpClient: &http.Client{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user