mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 14:29:19 +08:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 76b35210aa | |||
| 093f9a3b34 | |||
| 7ad8a7241d | |||
| c71bcefcbe | |||
| c4a8602428 | |||
| b17b364b02 | |||
| 7e2c535f37 | |||
| e0244d9ca7 | |||
| 6764fa5e70 | |||
| a3acba5eea | |||
| baf0d1888c | |||
| 5b99eb21e7 | |||
| 58ab340d1e | |||
| d8eec588de | |||
| b19d1f1726 | |||
| d446bdb943 | |||
| d3047d73b6 | |||
| 09c3229d9d | |||
| 4abddd8247 | |||
| c70ee5cbfb | |||
| 7bb44b8b88 | |||
| e1c2e94ec9 | |||
| 019ef60616 | |||
| 16bc053d09 | |||
| 9e2a256817 | |||
| 587533df4d | |||
| 61f83212b2 | |||
| 5d1cf8c061 | |||
| f1ba5c2bff | |||
| 11108e1ddf | |||
| c19bafc49d | |||
| d594d6f517 | |||
| 3fffc2f212 |
+25
-1
@@ -3,12 +3,36 @@
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- make clean
|
||||
# You may remove this if you don't use go modules.
|
||||
- make tidy
|
||||
- make copyright.add
|
||||
# you may remove this if you don't need go generate
|
||||
- go generate ./...
|
||||
|
||||
git:
|
||||
# What should be used to sort tags when gathering the current and previous
|
||||
# tags if there are more than one tag in the same commit.
|
||||
#
|
||||
# Default: '-version:refname'
|
||||
tag_sort: -version:creatordate
|
||||
|
||||
# What should be used to specify prerelease suffix while sorting tags when gathering
|
||||
# the current and previous tags if there are more than one tag in the same commit.
|
||||
#
|
||||
# Since: v1.17
|
||||
prerelease_suffix: "-"
|
||||
|
||||
# Tags to be ignored by GoReleaser.
|
||||
# This means that GoReleaser will not pick up tags that match any of the
|
||||
# provided values as either previous or current tags.
|
||||
#
|
||||
# Templates: allowed.
|
||||
# Since: v1.21.
|
||||
ignore_tags:
|
||||
- nightly
|
||||
# - "{{.Env.IGNORE_TAG}}"
|
||||
|
||||
snapshot:
|
||||
name_template: "{{ incpatch .Version }}-next"
|
||||
|
||||
@@ -495,4 +519,4 @@ checksum:
|
||||
algorithm: sha256
|
||||
|
||||
release:
|
||||
prerelease: auto
|
||||
prerelease: auto
|
||||
|
||||
@@ -84,19 +84,27 @@ OPENIM_IP=${OPENIM_IP}
|
||||
# Default: ZOOKEEPER_PORT=12181
|
||||
ZOOKEEPER_PORT=${ZOOKEEPER_PORT}
|
||||
|
||||
# Port on which MongoDB service is running.
|
||||
# MongoDB service port configuration.
|
||||
# Default: MONGO_PORT=37017
|
||||
# MONGO_PORT=${MONGO_PORT}
|
||||
|
||||
# Username to authenticate with the MongoDB service.
|
||||
# Username for MongoDB admin user. Used for service authentication.
|
||||
# Default: MONGO_USERNAME=root
|
||||
# MONGO_USERNAME=${MONGO_USERNAME}
|
||||
|
||||
# Password to authenticate with the MongoDB service.
|
||||
# Password for MongoDB admin user. Used for service authentication.
|
||||
# Default: MONGO_PASSWORD=openIM123
|
||||
MONGO_PASSWORD=${MONGO_PASSWORD}
|
||||
|
||||
# Name of the database in MongoDB to be used.
|
||||
# Username for a regular OpenIM user in MongoDB.
|
||||
# Default: MONGO_OPENIM_USERNAME=openIM
|
||||
MONGO_OPENIM_USERNAME=${MONGO_OPENIM_USERNAME}
|
||||
|
||||
# Password for a regular OpenIM user in MongoDB.
|
||||
# Default: MONGO_OPENIM_PASSWORD=openIM123456
|
||||
MONGO_OPENIM_PASSWORD=${MONGO_OPENIM_PASSWORD}
|
||||
|
||||
# Specifies the database name to be used within MongoDB.
|
||||
# Default: MONGO_DATABASE=openIM_v3
|
||||
MONGO_DATABASE=${MONGO_DATABASE}
|
||||
|
||||
@@ -177,7 +185,6 @@ OPENIM_WS_PORT=${OPENIM_WS_PORT}
|
||||
# Default: API_OPENIM_PORT=10002
|
||||
API_OPENIM_PORT=${API_OPENIM_PORT}
|
||||
|
||||
|
||||
# ======================================
|
||||
# ========== OpenIM Chat ===============
|
||||
# ======================================
|
||||
@@ -190,9 +197,9 @@ CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION}
|
||||
# Default: OPENIM_CHAT_API_PORT=10008
|
||||
OPENIM_CHAT_API_PORT=${OPENIM_CHAT_API_PORT}
|
||||
|
||||
# Directory path for storing data files or related information for OpenIM chat.
|
||||
# Default: OPENIM_CHAT_DATA_DIR=./openim-chat/main
|
||||
OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR}
|
||||
# Port for the OpenIM admin API.
|
||||
# Default: OPENIM_ADMIN_API_PORT=10009
|
||||
OPENIM_ADMIN_API_PORT=${OPENIM_ADMIN_API_PORT}
|
||||
|
||||
# ======================================
|
||||
# ========== OpenIM Admin ==============
|
||||
@@ -201,10 +208,6 @@ OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR}
|
||||
# Branch name for OpenIM server.
|
||||
# Default: SERVER_IMAGE_VERSION=main
|
||||
SERVER_IMAGE_VERSION=${SERVER_IMAGE_VERSION}
|
||||
|
||||
# Port for the OpenIM admin API.
|
||||
# Default: OPENIM_ADMIN_API_PORT=10009
|
||||
OPENIM_ADMIN_API_PORT=${OPENIM_ADMIN_API_PORT}
|
||||
|
||||
# Port for the node exporter.
|
||||
# Default: NODE_EXPORTER_PORT=19100
|
||||
@@ -224,4 +227,4 @@ OPENIM_ADMIN_FRONT_PORT=${OPENIM_ADMIN_FRONT_PORT}
|
||||
|
||||
# Port for the alertmanager.
|
||||
# Default: ALERT_MANAGER_PORT=19093
|
||||
ALERT_MANAGER_PORT=${ALERT_MANAGER_PORT}
|
||||
ALERT_MANAGER_PORT=${ALERT_MANAGER_PORT}
|
||||
|
||||
@@ -53,8 +53,8 @@ mongo:
|
||||
# Maximum connection pool size
|
||||
address: [ ${MONGO_ADDRESS}:${MONGO_PORT} ]
|
||||
database: ${MONGO_DATABASE}
|
||||
username: ${MONGO_USERNAME}
|
||||
password: ${MONGO_PASSWORD}
|
||||
username: ${MONGO_OPENIM_USERNAME}
|
||||
password: ${MONGO_OPENIM_PASSWORD}
|
||||
maxPoolSize: ${MONGO_MAX_POOL_SIZE}
|
||||
|
||||
###################### Redis configuration information ######################
|
||||
|
||||
+7
-9
@@ -10,6 +10,8 @@ networks:
|
||||
- subnet: '${DOCKER_BRIDGE_SUBNET:-172.28.0.0/16}'
|
||||
gateway: '${DOCKER_BRIDGE_GATEWAY:-172.28.0.1}'
|
||||
|
||||
|
||||
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:${MONGODB_IMAGE_VERSION-6.0.2}
|
||||
@@ -21,13 +23,15 @@ services:
|
||||
- "${DATA_DIR:-./}/components/mongodb/data/db:/data/db"
|
||||
- "${DATA_DIR:-./}/components/mongodb/data/logs:/data/logs"
|
||||
- "${DATA_DIR:-./}/components/mongodb/data/conf:/etc/mongo"
|
||||
- ./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro
|
||||
- "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro"
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- wiredTigerCacheSizeGB=1
|
||||
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME:-root}
|
||||
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD:-openIM123}
|
||||
- MONGO_INITDB_DATABASE=${MONGO_DATABASE:-openIM_v3}
|
||||
- MONGO_OPENIM_USERNAME=${MONGO_OPENIM_USERNAME:-openIM} # Non-root username
|
||||
- MONGO_OPENIM_PASSWORD=${MONGO_OPENIM_PASSWORD:-openIM123456} # Non-root password
|
||||
restart: always
|
||||
networks:
|
||||
server:
|
||||
@@ -122,9 +126,9 @@ services:
|
||||
server:
|
||||
ipv4_address: ${OPENIM_WEB_NETWORK_ADDRESS:-172.28.0.7}
|
||||
|
||||
## Uncomment and configure the following services as needed
|
||||
# Uncomment and configure the following services as needed
|
||||
# openim-admin:
|
||||
# image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-admin:toc-base-open-docker.35
|
||||
# image: ${IMAGE_REGISTRY:-ghcr.io/openimsdk}/openim-admin-front:v3.4.0
|
||||
# container_name: openim-admin
|
||||
# restart: always
|
||||
# ports:
|
||||
@@ -167,12 +171,6 @@ services:
|
||||
# hostname: grafana
|
||||
# user: root
|
||||
# restart: always
|
||||
# environment:
|
||||
# - GF_SECURITY_ALLOW_EMBEDDING=true
|
||||
# - GF_SESSION_COOKIE_SAMESITE=none
|
||||
# - GF_SESSION_COOKIE_SECURE=true
|
||||
# - GF_AUTH_ANONYMOUS_ENABLED=true
|
||||
# - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
||||
# ports:
|
||||
# - "${GRAFANA_PORT:-13000}:3000"
|
||||
# volumes:
|
||||
|
||||
@@ -304,8 +304,10 @@ This section involves setting up MongoDB, including its port, address, and crede
|
||||
| -------------- | -------------- | ----------------------- |
|
||||
| MONGO_PORT | "27017" | Port used by MongoDB. |
|
||||
| MONGO_ADDRESS | [Generated IP] | IP address for MongoDB. |
|
||||
| MONGO_USERNAME | [User Defined] | Username for MongoDB. |
|
||||
| MONGO_PASSWORD | [User Defined] | Password for MongoDB. |
|
||||
| MONGO_USERNAME | [User Defined] | Admin Username for MongoDB. |
|
||||
| MONGO_PASSWORD | [User Defined] | Admin Password for MongoDB. |
|
||||
| MONGO_OPENIM_PASSWORD | [User Defined] | OpenIM Username for MongoDB. |
|
||||
| MONGO_OPENIM_PASSWORD | [User Defined] | OpenIM Password for MongoDB. |
|
||||
|
||||
### 2.8. <a name='TencentCloudCOSConfiguration'></a>Tencent Cloud COS Configuration
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ go 1.19
|
||||
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
github.com/OpenIMSDK/protocol v0.0.42
|
||||
github.com/OpenIMSDK/tools v0.0.21
|
||||
github.com/OpenIMSDK/protocol v0.0.46
|
||||
github.com/OpenIMSDK/tools v0.0.23
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/dtm-labs/rockscache v0.1.1
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
@@ -155,4 +155,4 @@ require (
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
)
|
||||
)
|
||||
|
||||
@@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c=
|
||||
github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ=
|
||||
github.com/OpenIMSDK/protocol v0.0.42 h1:vIWXqZJZZ1ddleJA25fxhjZ1GyEHATpYM3wVWh4/+PY=
|
||||
github.com/OpenIMSDK/protocol v0.0.42/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
|
||||
github.com/OpenIMSDK/protocol v0.0.46 h1:LKfwcC3pUcJKSxiIyj82fc479BuDbDtsCrPxa7bHxmo=
|
||||
github.com/OpenIMSDK/protocol v0.0.46/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
|
||||
github.com/OpenIMSDK/tools v0.0.21 h1:iTapc2mIEVH/xl5Nd6jfwPub11Pgp44tVcE1rjB3a48=
|
||||
github.com/OpenIMSDK/tools v0.0.21/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
|
||||
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
Compression = "compression"
|
||||
GzipCompressionProtocol = "gzip"
|
||||
BackgroundStatus = "isBackground"
|
||||
MsgResp = "isMsgResp"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -16,7 +16,10 @@ package msggateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/apiresp"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -342,11 +345,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
||||
if !clientOK {
|
||||
return
|
||||
}
|
||||
|
||||
isDeleteUser := ws.clients.deleteClients(newClient.UserID, oldClients)
|
||||
if isDeleteUser {
|
||||
ws.onlineUserNum.Add(-1)
|
||||
}
|
||||
ws.clients.deleteClients(newClient.UserID, oldClients)
|
||||
for _, c := range oldClients {
|
||||
err := c.KickOnlineMessage()
|
||||
if err != nil {
|
||||
@@ -422,84 +421,102 @@ func (ws *WsServer) unregisterClient(client *Client) {
|
||||
)
|
||||
}
|
||||
|
||||
func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
connContext := newContext(w, r)
|
||||
func (ws *WsServer) ParseWSArgs(r *http.Request) (args *WSArgs, err error) {
|
||||
var v WSArgs
|
||||
defer func() {
|
||||
args = &v
|
||||
}()
|
||||
query := r.URL.Query()
|
||||
v.MsgResp, _ = strconv.ParseBool(query.Get(MsgResp))
|
||||
if ws.onlineUserConnNum.Load() >= ws.wsMaxConnNum {
|
||||
httpError(connContext, errs.ErrConnOverMaxNumLimit)
|
||||
return
|
||||
return nil, errs.ErrConnOverMaxNumLimit.Wrap("over max conn num limit")
|
||||
}
|
||||
var (
|
||||
token string
|
||||
userID string
|
||||
platformIDStr string
|
||||
exists bool
|
||||
compression bool
|
||||
)
|
||||
|
||||
token, exists = connContext.Query(Token)
|
||||
if !exists {
|
||||
httpError(connContext, errs.ErrConnArgsErr)
|
||||
return
|
||||
if v.Token = query.Get(Token); v.Token == "" {
|
||||
return nil, errs.ErrConnArgsErr.Wrap("token is empty")
|
||||
}
|
||||
userID, exists = connContext.Query(WsUserID)
|
||||
if !exists {
|
||||
httpError(connContext, errs.ErrConnArgsErr)
|
||||
return
|
||||
if v.UserID = query.Get(WsUserID); v.UserID == "" {
|
||||
return nil, errs.ErrConnArgsErr.Wrap("sendID is empty")
|
||||
}
|
||||
platformIDStr, exists = connContext.Query(PlatformID)
|
||||
if !exists {
|
||||
httpError(connContext, errs.ErrConnArgsErr)
|
||||
return
|
||||
platformIDStr := query.Get(PlatformID)
|
||||
if platformIDStr == "" {
|
||||
return nil, errs.ErrConnArgsErr.Wrap("platformID is empty")
|
||||
}
|
||||
platformID, err := strconv.Atoi(platformIDStr)
|
||||
if err != nil {
|
||||
httpError(connContext, errs.ErrConnArgsErr)
|
||||
return
|
||||
return nil, errs.ErrConnArgsErr.Wrap("platformID is not int")
|
||||
}
|
||||
if err = authverify.WsVerifyToken(token, userID, platformID); err != nil {
|
||||
httpError(connContext, err)
|
||||
return
|
||||
v.PlatformID = platformID
|
||||
if err = authverify.WsVerifyToken(v.Token, v.UserID, platformID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, err := ws.cache.GetTokensWithoutError(context.Background(), userID, platformID)
|
||||
if query.Get(Compression) == GzipCompressionProtocol {
|
||||
v.Compression = true
|
||||
}
|
||||
if r.Header.Get(Compression) == GzipCompressionProtocol {
|
||||
v.Compression = true
|
||||
}
|
||||
m, err := ws.cache.GetTokensWithoutError(context.Background(), v.UserID, platformID)
|
||||
if err != nil {
|
||||
httpError(connContext, err)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := m[token]; ok {
|
||||
if v, ok := m[v.Token]; ok {
|
||||
switch v {
|
||||
case constant.NormalToken:
|
||||
case constant.KickedToken:
|
||||
httpError(connContext, errs.ErrTokenKicked.Wrap())
|
||||
return
|
||||
return nil, errs.ErrTokenKicked.Wrap()
|
||||
default:
|
||||
httpError(connContext, errs.ErrTokenUnknown.Wrap())
|
||||
return nil, errs.ErrTokenUnknown.Wrap(fmt.Sprintf("token status is %d", v))
|
||||
}
|
||||
} else {
|
||||
return nil, errs.ErrTokenNotExist.Wrap()
|
||||
}
|
||||
return &v, nil
|
||||
}
|
||||
|
||||
type WSArgs struct {
|
||||
Token string
|
||||
UserID string
|
||||
PlatformID int
|
||||
Compression bool
|
||||
MsgResp bool
|
||||
}
|
||||
|
||||
func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
connContext := newContext(w, r)
|
||||
args, pErr := ws.ParseWSArgs(r)
|
||||
var wsLongConn *GWebSocket
|
||||
if args.MsgResp {
|
||||
wsLongConn = newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize)
|
||||
if err := wsLongConn.GenerateLongConn(w, r); err != nil {
|
||||
httpError(connContext, err)
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(apiresp.ParseError(pErr))
|
||||
if err != nil {
|
||||
_ = wsLongConn.Close()
|
||||
return
|
||||
}
|
||||
if err := wsLongConn.WriteMessage(MessageText, data); err != nil {
|
||||
_ = wsLongConn.Close()
|
||||
return
|
||||
}
|
||||
if pErr != nil {
|
||||
_ = wsLongConn.Close()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
httpError(connContext, errs.ErrTokenNotExist.Wrap())
|
||||
return
|
||||
}
|
||||
|
||||
wsLongConn := newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize)
|
||||
err = wsLongConn.GenerateLongConn(w, r)
|
||||
if err != nil {
|
||||
httpError(connContext, err)
|
||||
return
|
||||
}
|
||||
compressProtoc, exists := connContext.Query(Compression)
|
||||
if exists {
|
||||
if compressProtoc == GzipCompressionProtocol {
|
||||
compression = true
|
||||
if pErr != nil {
|
||||
httpError(connContext, pErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
compressProtoc, exists = connContext.GetHeader(Compression)
|
||||
if exists {
|
||||
if compressProtoc == GzipCompressionProtocol {
|
||||
compression = true
|
||||
wsLongConn = newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize)
|
||||
if err := wsLongConn.GenerateLongConn(w, r); err != nil {
|
||||
httpError(connContext, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
client := ws.clientPool.Get().(*Client)
|
||||
client.ResetClient(connContext, wsLongConn, connContext.GetBackground(), compression, ws, token)
|
||||
client.ResetClient(connContext, wsLongConn, connContext.GetBackground(), args.Compression, ws, args.Token)
|
||||
ws.registerChan <- client
|
||||
go client.readMessage()
|
||||
}
|
||||
|
||||
@@ -476,13 +476,42 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbgroup.GetGro
|
||||
|
||||
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbgroup.GetGroupMemberListReq) (*pbgroup.GetGroupMemberListResp, error) {
|
||||
resp := &pbgroup.GetGroupMemberListResp{}
|
||||
total, members, err := s.db.PageGetGroupMember(ctx, req.GroupID, req.Pagination)
|
||||
var (
|
||||
total int64
|
||||
members []*relationtb.GroupMemberModel
|
||||
err error
|
||||
)
|
||||
if req.Keyword == "" {
|
||||
total, members, err = s.db.PageGetGroupMember(ctx, req.GroupID, req.Pagination)
|
||||
} else {
|
||||
members, err = s.db.FindGroupMemberAll(ctx, req.GroupID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.PopulateGroupMember(ctx, members...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Keyword != "" {
|
||||
groupMembers := make([]*relationtb.GroupMemberModel, 0)
|
||||
for _, member := range members {
|
||||
if member.UserID == req.Keyword {
|
||||
groupMembers = append(groupMembers, member)
|
||||
total++
|
||||
continue
|
||||
}
|
||||
if member.Nickname == req.Keyword {
|
||||
groupMembers = append(groupMembers, member)
|
||||
total++
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
GMembers := utils.Paginate(groupMembers, int(req.Pagination.GetPageNumber()), int(req.Pagination.GetShowNumber()))
|
||||
resp.Members = utils.Batch(convert.Db2PbGroupMember, GMembers)
|
||||
resp.Total = uint32(total)
|
||||
return resp, nil
|
||||
}
|
||||
resp.Total = uint32(total)
|
||||
resp.Members = utils.Batch(convert.Db2PbGroupMember, members)
|
||||
return resp, nil
|
||||
@@ -1042,20 +1071,29 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbgroup.Trans
|
||||
func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq) (*pbgroup.GetGroupsResp, error) {
|
||||
resp := &pbgroup.GetGroupsResp{}
|
||||
var (
|
||||
groups []*relationtb.GroupModel
|
||||
err error
|
||||
group []*relationtb.GroupModel
|
||||
err error
|
||||
)
|
||||
if req.GroupID != "" {
|
||||
groups, err = s.db.FindGroup(ctx, []string{req.GroupID})
|
||||
resp.Total = uint32(len(groups))
|
||||
group, err = s.db.FindGroup(ctx, []string{req.GroupID})
|
||||
resp.Total = uint32(len(group))
|
||||
} else {
|
||||
var total int64
|
||||
total, groups, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
|
||||
total, group, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
|
||||
resp.Total = uint32(total)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var groups []*relationtb.GroupModel
|
||||
for _, v := range group {
|
||||
if v.Status == constant.GroupStatusDismissed {
|
||||
resp.Total--
|
||||
continue
|
||||
}
|
||||
groups = append(groups, v)
|
||||
}
|
||||
groupIDs := utils.Slice(groups, func(e *relationtb.GroupModel) string {
|
||||
return e.GroupID
|
||||
})
|
||||
|
||||
+46
-57
@@ -17,6 +17,7 @@ package user
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/OpenIMSDK/tools/pagination"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"math/rand"
|
||||
"strings"
|
||||
@@ -58,6 +59,11 @@ type userServer struct {
|
||||
RegisterCenter registry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func (s *userServer) ProcessUserCommandGetAll(ctx context.Context, req *pbuser.ProcessUserCommandGetAllReq) (*pbuser.ProcessUserCommandGetAllResp, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
rdb, err := cache.NewRedis()
|
||||
if err != nil {
|
||||
@@ -228,7 +234,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
|
||||
}
|
||||
|
||||
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||
total, users, err := s.Page(ctx, req.Pagination)
|
||||
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, req.Pagination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -379,11 +385,6 @@ func (s *userServer) GetSubscribeUsersStatus(ctx context.Context,
|
||||
|
||||
// ProcessUserCommandAdd user general function add
|
||||
func (s *userServer) ProcessUserCommandAdd(ctx context.Context, req *pbuser.ProcessUserCommandAddReq) (*pbuser.ProcessUserCommandAddResp, error) {
|
||||
// Assuming you have a method in s.UserDatabase to add a user command
|
||||
err := s.UserDatabase.AddUserCommand(ctx, req.UserID, req.Type, req.Uuid, req.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbuser.ProcessUserCommandAddResp{}, nil
|
||||
}
|
||||
@@ -395,42 +396,19 @@ func (s *userServer) ProcessUserCommandDelete(ctx context.Context, req *pbuser.P
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbuser.ProcessUserCommandDeleteResp{}, nil
|
||||
}
|
||||
|
||||
// ProcessUserCommandUpdate user general function update
|
||||
func (s *userServer) ProcessUserCommandUpdate(ctx context.Context, req *pbuser.ProcessUserCommandUpdateReq) (*pbuser.ProcessUserCommandUpdateResp, error) {
|
||||
// Assuming you have a method in s.UserDatabase to update a user command
|
||||
err := s.UserDatabase.UpdateUserCommand(ctx, req.UserID, req.Type, req.Uuid, req.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbuser.ProcessUserCommandUpdateResp{}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.ProcessUserCommandGetReq) (*pbuser.ProcessUserCommandGetResp, error) {
|
||||
// Fetch user commands from the database
|
||||
commands, err := s.UserDatabase.GetUserCommands(ctx, req.UserID, req.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Initialize commandInfoSlice as an empty slice
|
||||
commandInfoSlice := make([]*pbuser.CommandInfoResp, 0, len(commands))
|
||||
|
||||
for _, command := range commands {
|
||||
// No need to use index since command is already a pointer
|
||||
commandInfoSlice = append(commandInfoSlice, &pbuser.CommandInfoResp{
|
||||
Uuid: command.Uuid,
|
||||
Value: command.Value,
|
||||
CreateTime: command.CreateTime,
|
||||
})
|
||||
}
|
||||
|
||||
// Return the response with the slice
|
||||
return &pbuser.ProcessUserCommandGetResp{KVArray: commandInfoSlice}, nil
|
||||
return &pbuser.ProcessUserCommandGetResp{}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.AddNotificationAccountReq) (*pbuser.AddNotificationAccountResp, error) {
|
||||
@@ -438,22 +416,23 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userID string
|
||||
for i := 0; i < 20; i++ {
|
||||
userId := s.genUserID()
|
||||
_, err := s.UserDatabase.FindWithError(ctx, []string{userId})
|
||||
if err == nil {
|
||||
continue
|
||||
if req.UserID == "" {
|
||||
for i := 0; i < 20; i++ {
|
||||
userId := s.genUserID()
|
||||
_, err := s.UserDatabase.FindWithError(ctx, []string{userId})
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
req.UserID = userId
|
||||
break
|
||||
}
|
||||
if req.UserID == "" {
|
||||
return nil, errs.ErrInternalServer.Wrap("gen user id failed")
|
||||
}
|
||||
userID = userId
|
||||
break
|
||||
}
|
||||
if userID == "" {
|
||||
return nil, errs.ErrInternalServer.Wrap("gen user id failed")
|
||||
}
|
||||
|
||||
user := &tablerelation.UserModel{
|
||||
UserID: userID,
|
||||
UserID: req.UserID,
|
||||
Nickname: req.NickName,
|
||||
FaceURL: req.FaceURL,
|
||||
CreateTime: time.Now(),
|
||||
@@ -463,7 +442,11 @@ func (s *userServer) AddNotificationAccount(ctx context.Context, req *pbuser.Add
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbuser.AddNotificationAccountResp{}, nil
|
||||
return &pbuser.AddNotificationAccountResp{
|
||||
UserID: req.UserID,
|
||||
NickName: req.NickName,
|
||||
FaceURL: req.FaceURL,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UpdateNotificationAccountInfo(ctx context.Context, req *pbuser.UpdateNotificationAccountInfoReq) (*pbuser.UpdateNotificationAccountInfoResp, error) {
|
||||
@@ -497,30 +480,33 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.NickName != "" {
|
||||
users, err := s.UserDatabase.FindByNickname(ctx, req.NickName)
|
||||
var users []*relation.UserModel
|
||||
var err error
|
||||
if req.Keyword != "" {
|
||||
users, err = s.UserDatabase.Find(ctx, []string{req.Keyword})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := s.userModelToResp(users)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
if req.UserID != "" {
|
||||
users, err := s.UserDatabase.Find(ctx, []string{req.UserID})
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
if resp.Total != 0 {
|
||||
return resp, nil
|
||||
}
|
||||
users, err = s.UserDatabase.FindByNickname(ctx, req.Keyword)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := s.userModelToResp(users)
|
||||
resp = s.userModelToResp(users, req.Pagination)
|
||||
return resp, nil
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
_, users, err := s.UserDatabase.Page(ctx, req.Pagination)
|
||||
users, err = s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := s.userModelToResp(users)
|
||||
resp := s.userModelToResp(users, req.Pagination)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -554,11 +540,11 @@ func (s *userServer) genUserID() string {
|
||||
return string(data)
|
||||
}
|
||||
|
||||
func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.SearchNotificationAccountResp {
|
||||
func (s *userServer) userModelToResp(users []*relation.UserModel, pagination pagination.Pagination) *pbuser.SearchNotificationAccountResp {
|
||||
accounts := make([]*pbuser.NotificationAccountInfo, 0)
|
||||
var total int64
|
||||
for _, v := range users {
|
||||
if v.AppMangerLevel == constant.AppNotificationAdmin || v.AppMangerLevel == constant.AppAdmin {
|
||||
if v.AppMangerLevel == constant.AppNotificationAdmin && !utils.IsContain(v.UserID, config.Config.IMAdmin.UserID) {
|
||||
temp := &pbuser.NotificationAccountInfo{
|
||||
UserID: v.UserID,
|
||||
FaceURL: v.FaceURL,
|
||||
@@ -568,5 +554,8 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search
|
||||
total += 1
|
||||
}
|
||||
}
|
||||
return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: accounts}
|
||||
|
||||
notificationAccounts := utils.Paginate(accounts, int(pagination.GetPageNumber()), int(pagination.GetShowNumber()))
|
||||
|
||||
return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: notificationAccounts}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
||||
if utils.IsContain(opUserID, config.Config.Manager.UserID) {
|
||||
return nil
|
||||
}
|
||||
if utils.IsContain(opUserID, config.Config.IMAdmin.UserID) {
|
||||
return nil
|
||||
}
|
||||
if opUserID == ownerUserID {
|
||||
return nil
|
||||
}
|
||||
@@ -45,13 +48,16 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
||||
}
|
||||
|
||||
func IsAppManagerUid(ctx context.Context) bool {
|
||||
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID)
|
||||
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) || utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID)
|
||||
}
|
||||
|
||||
func CheckAdmin(ctx context.Context) error {
|
||||
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
|
||||
return nil
|
||||
}
|
||||
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID) {
|
||||
return nil
|
||||
}
|
||||
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
|
||||
}
|
||||
func CheckIMAdmin(ctx context.Context) error {
|
||||
@@ -69,7 +75,7 @@ func ParseRedisInterfaceToken(redisToken any) (*tokenverify.Claims, error) {
|
||||
}
|
||||
|
||||
func IsManagerUserID(opUserID string) bool {
|
||||
return utils.IsContain(opUserID, config.Config.Manager.UserID)
|
||||
return utils.IsContain(opUserID, config.Config.Manager.UserID) || utils.IsContain(opUserID, config.Config.IMAdmin.UserID)
|
||||
}
|
||||
|
||||
func WsVerifyToken(token, userID string, platformID int) error {
|
||||
|
||||
@@ -279,7 +279,7 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context,
|
||||
for _, v := range existConversationUserIDs {
|
||||
cache = cache.DelConversations(v, conversationID)
|
||||
}
|
||||
return c.cache.ExecDel(ctx)
|
||||
return cache.ExecDel(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ func (g *groupDatabase) UpdateGroup(ctx context.Context, groupID string, data ma
|
||||
func (g *groupDatabase) DismissGroup(ctx context.Context, groupID string, deleteMember bool) error {
|
||||
return g.ctxTx.Transaction(ctx, func(ctx context.Context) error {
|
||||
c := g.cache.NewCache()
|
||||
if err := g.groupDB.UpdateState(ctx, groupID, constant.GroupStatusDismissed); err != nil {
|
||||
if err := g.groupDB.UpdateStatus(ctx, groupID, constant.GroupStatusDismissed); err != nil {
|
||||
return err
|
||||
}
|
||||
if deleteMember {
|
||||
|
||||
@@ -40,12 +40,16 @@ type UserDatabase interface {
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
|
||||
// Find userInfo By Nickname
|
||||
FindByNickname(ctx context.Context, nickname string) (users []*relation.UserModel, err error)
|
||||
// Find notificationAccounts
|
||||
FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error)
|
||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db
|
||||
Create(ctx context.Context, users []*relation.UserModel) (err error)
|
||||
// Update update (non-zero value) external guarantee userID exists
|
||||
//Update(ctx context.Context, user *relation.UserModel) (err error)
|
||||
// UpdateByMap update (zero value) external guarantee userID exists
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||
// FindUser
|
||||
PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||
// Page If not found, no error is returned
|
||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||
// IsExist true as long as one exists
|
||||
@@ -140,6 +144,11 @@ func (u *userDatabase) FindByNickname(ctx context.Context, nickname string) (use
|
||||
return u.userDB.TakeByNickname(ctx, nickname)
|
||||
}
|
||||
|
||||
// Find notificationAccouts
|
||||
func (u *userDatabase) FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error) {
|
||||
return u.userDB.TakeNotification(ctx, level)
|
||||
}
|
||||
|
||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db.
|
||||
func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||
return u.tx.Transaction(ctx, func(ctx context.Context) error {
|
||||
@@ -175,6 +184,10 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
|
||||
return u.userDB.Page(ctx, pagination)
|
||||
}
|
||||
|
||||
func (u *userDatabase) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
return u.userDB.PageFindUser(ctx, level, pagination)
|
||||
}
|
||||
|
||||
// IsExist Does userIDs exist? As long as there is one, it will be true.
|
||||
func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
||||
users, err := u.userDB.Find(ctx, userIDs)
|
||||
|
||||
@@ -49,8 +49,8 @@ func (g *GroupMgo) Create(ctx context.Context, groups []*relation.GroupModel) (e
|
||||
return mgoutil.InsertMany(ctx, g.coll, groups)
|
||||
}
|
||||
|
||||
func (g *GroupMgo) UpdateState(ctx context.Context, groupID string, state int32) (err error) {
|
||||
return g.UpdateMap(ctx, groupID, map[string]any{"state": state})
|
||||
func (g *GroupMgo) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) {
|
||||
return g.UpdateMap(ctx, groupID, map[string]any{"status": status})
|
||||
}
|
||||
|
||||
func (g *GroupMgo) UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error) {
|
||||
|
||||
@@ -51,7 +51,11 @@ func (g *GroupMemberMgo) Create(ctx context.Context, groupMembers []*relation.Gr
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) Delete(ctx context.Context, groupID string, userIDs []string) (err error) {
|
||||
return mgoutil.DeleteMany(ctx, g.coll, bson.M{"group_id": groupID, "user_id": bson.M{"$in": userIDs}})
|
||||
filter := bson.M{"group_id": groupID}
|
||||
if len(userIDs) > 0 {
|
||||
filter["user_id"] = bson.M{"$in": userIDs}
|
||||
}
|
||||
return mgoutil.DeleteMany(ctx, g.coll, filter)
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) UpdateRoleLevel(ctx context.Context, groupID string, userID string, roleLevel int32) error {
|
||||
@@ -84,8 +88,8 @@ func (g *GroupMemberMgo) FindRoleLevelUserIDs(ctx context.Context, groupID strin
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) SearchMember(ctx context.Context, keyword string, groupID string, pagination pagination.Pagination) (total int64, groupList []*relation.GroupMemberModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
filter := bson.M{"group_id": groupID, "nickname": bson.M{"$regex": keyword}}
|
||||
return mgoutil.FindPage[*relation.GroupMemberModel](ctx, g.coll, filter, pagination)
|
||||
}
|
||||
|
||||
func (g *GroupMemberMgo) FindUserJoinedGroupID(ctx context.Context, userID string) (groupIDs []string, err error) {
|
||||
|
||||
@@ -65,6 +65,10 @@ func (u *UserMgo) Take(ctx context.Context, userID string) (user *relation.UserM
|
||||
return mgoutil.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
|
||||
}
|
||||
|
||||
func (u *UserMgo) TakeNotification(ctx context.Context, level int64) (user []*relation.UserModel, err error) {
|
||||
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level})
|
||||
}
|
||||
|
||||
func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*relation.UserModel, err error) {
|
||||
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"nickname": nickname})
|
||||
}
|
||||
@@ -73,6 +77,10 @@ func (u *UserMgo) Page(ctx context.Context, pagination pagination.Pagination) (c
|
||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{}, pagination)
|
||||
}
|
||||
|
||||
func (u *UserMgo) PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level}, pagination)
|
||||
}
|
||||
|
||||
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
|
||||
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"user_id": 1}))
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type GroupModel struct {
|
||||
type GroupModelInterface interface {
|
||||
Create(ctx context.Context, groups []*GroupModel) (err error)
|
||||
UpdateMap(ctx context.Context, groupID string, args map[string]any) (err error)
|
||||
UpdateState(ctx context.Context, groupID string, state int32) (err error)
|
||||
UpdateStatus(ctx context.Context, groupID string, status int32) (err error)
|
||||
Find(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error)
|
||||
Take(ctx context.Context, groupID string) (group *GroupModel, err error)
|
||||
Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*GroupModel, err error)
|
||||
|
||||
@@ -53,8 +53,10 @@ type UserModelInterface interface {
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
||||
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
||||
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
|
||||
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||
PageFindUser(ctx context.Context, level int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||
Exist(ctx context.Context, userID string) (exist bool, err error)
|
||||
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
|
||||
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
||||
|
||||
@@ -78,8 +78,8 @@ func buildMongoURI() string {
|
||||
return config.Config.Mongo.Uri
|
||||
}
|
||||
|
||||
username := os.Getenv("MONGO_USERNAME")
|
||||
password := os.Getenv("MONGO_PASSWORD")
|
||||
username := os.Getenv("MONGO_OPENIM_USERNAME")
|
||||
password := os.Getenv("MONGO_OPENIM_PASSWORD")
|
||||
address := os.Getenv("MONGO_ADDRESS")
|
||||
port := os.Getenv("MONGO_PORT")
|
||||
database := os.Getenv("MONGO_DATABASE")
|
||||
@@ -103,9 +103,9 @@ func buildMongoURI() string {
|
||||
maxPoolSize = fmt.Sprint(config.Config.Mongo.MaxPoolSize)
|
||||
}
|
||||
|
||||
uriFormat := "mongodb://%s/%s?maxPoolSize=%s&authSource=admin"
|
||||
uriFormat := "mongodb://%s/%s?maxPoolSize=%s"
|
||||
if username != "" && password != "" {
|
||||
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s&authSource=admin"
|
||||
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s"
|
||||
return fmt.Sprintf(uriFormat, username, password, address, database, maxPoolSize)
|
||||
}
|
||||
return fmt.Sprintf(uriFormat, address, database, maxPoolSize)
|
||||
|
||||
@@ -64,6 +64,9 @@ func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClie
|
||||
|
||||
// GetUsersInfo retrieves information for multiple users based on their user IDs.
|
||||
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return []*sdkws.UserInfo{}, nil
|
||||
}
|
||||
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||
UserIDs: userIDs,
|
||||
})
|
||||
|
||||
@@ -36,4 +36,4 @@ sleep 5
|
||||
|
||||
"${OPENIM_ROOT}"/scripts/check-all.sh
|
||||
|
||||
tail -f ${LOG_FILE}
|
||||
tail -f ${LOG_FILE}
|
||||
|
||||
@@ -43,10 +43,20 @@ fi
|
||||
"${OPENIM_ROOT}"/scripts/init-config.sh
|
||||
pushd "${OPENIM_ROOT}"
|
||||
${DOCKER_COMPOSE_COMMAND} stop
|
||||
curl https://gitee.com/openimsdk/openim-docker/raw/main/example/full-openim-server-and-chat.yml -o docker-compose.yml
|
||||
curl https://raw.githubusercontent.com/openimsdk/openim-docker/main/docker-compose.yaml -o docker-compose.yml
|
||||
${DOCKER_COMPOSE_COMMAND} up -d
|
||||
sleep 60
|
||||
|
||||
# Wait for a short period to allow containers to initialize
|
||||
sleep 30
|
||||
|
||||
# Check the status of the containers
|
||||
if ! ${DOCKER_COMPOSE_COMMAND} ps | grep -q 'Up'; then
|
||||
echo "Error: One or more docker containers failed to start."
|
||||
${DOCKER_COMPOSE_COMMAND} logs
|
||||
fi
|
||||
|
||||
sleep 30 # Keep the original 60-second wait, adjusted for the 10-second check above
|
||||
${DOCKER_COMPOSE_COMMAND} logs openim-server
|
||||
${DOCKER_COMPOSE_COMMAND} ps
|
||||
|
||||
popd
|
||||
popd
|
||||
|
||||
@@ -35,8 +35,8 @@ docker run -d \
|
||||
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
|
||||
-e MONGO_INITDB_DATABASE=openIM \
|
||||
-e MONGO_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_PASSWORD=${PASSWORD} \
|
||||
-e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
|
||||
-e MONGO_OPENIM_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
|
||||
|
||||
|
||||
@@ -171,9 +171,14 @@ def "MONGO_URI" # MongoDB的URI
|
||||
def "MONGO_PORT" "37017" # MongoDB的端口
|
||||
def "MONGO_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # MongoDB的地址
|
||||
def "MONGO_DATABASE" "${DATABASE_NAME}" # MongoDB的数据库名
|
||||
def "MONGO_USERNAME" "${OPENIM_USER}" # MongoDB的用户名
|
||||
# MongoDB的密码
|
||||
def "MONGO_USERNAME" "root" # MongoDB的管理员身份用户名
|
||||
# MongoDB的管理员身份密码
|
||||
readonly MONGO_PASSWORD=${MONGO_PASSWORD:-"${PASSWORD}"}
|
||||
# Mongo OpenIM 身份用户名
|
||||
def "MONGO_OPENIM_USERNAME" "openIM"
|
||||
# Mongo OpenIM 身份密码
|
||||
readonly MONGO_OPENIM_PASSWORD=${MONGO_OPENIM_PASSWORD:-'openIM123456'}
|
||||
|
||||
def "MONGO_MAX_POOL_SIZE" "100" # 最大连接池大小
|
||||
|
||||
###################### Object 配置信息 ######################
|
||||
|
||||
+12
-6
@@ -12,15 +12,21 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
mongo -- "$MONGO_INITDB_DATABASE" <<EOF
|
||||
db = db.getSiblingDB('admin')
|
||||
set -e
|
||||
|
||||
mongosh <<EOF
|
||||
use admin
|
||||
db.auth('$MONGO_INITDB_ROOT_USERNAME', '$MONGO_INITDB_ROOT_PASSWORD')
|
||||
|
||||
|
||||
db = db.getSiblingDB('$MONGO_INITDB_DATABASE')
|
||||
db.createUser({
|
||||
user: "$MONGO_USERNAME",
|
||||
pwd: "$MONGO_PASSWORD",
|
||||
user: "$MONGO_OPENIM_USERNAME",
|
||||
pwd: "$MONGO_OPENIM_PASSWORD",
|
||||
roles: [
|
||||
{ role: 'root', db: '$MONGO_INITDB_DATABASE' }
|
||||
// Assign appropriate roles here
|
||||
{ role: 'readWrite', db: '$MONGO_INITDB_DATABASE' }
|
||||
]
|
||||
})
|
||||
});
|
||||
EOF
|
||||
|
||||
|
||||
@@ -25,10 +25,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/IBM/sarama"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"github.com/go-zookeeper/zk"
|
||||
@@ -38,6 +34,9 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -172,10 +171,10 @@ func buildMongoURI() string {
|
||||
mongodbHosts := strings.Join(config.Config.Mongo.Address, ",")
|
||||
|
||||
if username != "" && password != "" {
|
||||
return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d&authSource=admin",
|
||||
return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d",
|
||||
username, password, mongodbHosts, database, maxPoolSize)
|
||||
}
|
||||
return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%d&authSource=admin",
|
||||
return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%d",
|
||||
mongodbHosts, database, maxPoolSize)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user