mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-30 15:29:20 +08:00
Compare commits
122 Commits
v2.2.0
...
v2.3.0-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bd42defaf | |||
| a71b42c335 | |||
| f3ed48e0ac | |||
| 55cc8cead1 | |||
| 0d24078ee4 | |||
| 18db5c500f | |||
| f87806edb4 | |||
| a3f62e2246 | |||
| a5ef78fd1e | |||
| 337d01008b | |||
| a937a94e43 | |||
| 8bb82be2b9 | |||
| a6cf407a8f | |||
| eec8eb4766 | |||
| 52c71e3843 | |||
| b5ea79e3ea | |||
| 960e3d34eb | |||
| cbb127ff38 | |||
| db1a043261 | |||
| f9eee19cbe | |||
| eb1aeefc8c | |||
| e64cf47d31 | |||
| 3f79409a11 | |||
| dd0d518ecd | |||
| 6d236a2dd6 | |||
| 663db12594 | |||
| f383d6c636 | |||
| 2b3bb92357 | |||
| 87a2944837 | |||
| ea32c88d85 | |||
| 725f8ce761 | |||
| 3f42390f2f | |||
| 4d3343d0d0 | |||
| 4b22eb946c | |||
| 53eebb0638 | |||
| 4546e77d5b | |||
| 7d2eb31f05 | |||
| 7c15a53a62 | |||
| 1531db0a35 | |||
| 6d91f766e7 | |||
| bf5bce9e64 | |||
| 5afa3380a6 | |||
| 85f5c59781 | |||
| 8ee4ca0357 | |||
| 656241c23f | |||
| 5936492f76 | |||
| abe06b8753 | |||
| ac536c48cd | |||
| 1b4b2b9bb1 | |||
| ad1d759840 | |||
| a55134ae63 | |||
| 67b20d073e | |||
| 2187f44ed7 | |||
| 026f61126a | |||
| 8a8fce927e | |||
| 99873e2136 | |||
| e904651541 | |||
| d65a0dbbc7 | |||
| 2b2ecad437 | |||
| 89406f1c57 | |||
| ea93e97e79 | |||
| 1e6a93b4b6 | |||
| 8ad22f8148 | |||
| e667ec944b | |||
| b064244907 | |||
| a01156feb6 | |||
| af1d8fa834 | |||
| 0234795200 | |||
| 58f4ebe411 | |||
| d4e575f777 | |||
| 2d110deb09 | |||
| 2e552e8711 | |||
| fb4cef7ccb | |||
| 3b6b88fd62 | |||
| 95630c6d61 | |||
| 33222d59c2 | |||
| adb7da7aaf | |||
| 04eb85d279 | |||
| 58847c7fb6 | |||
| 504e4cc6a3 | |||
| ec5177342e | |||
| 4d982ab816 | |||
| c390617151 | |||
| fff7f30005 | |||
| ca72d4840a | |||
| 7ccb1b6a6f | |||
| 126e1f44ca | |||
| 84a4382532 | |||
| 40f7048eee | |||
| c94fb80cb0 | |||
| 2db194b9d1 | |||
| 34420c1265 | |||
| 9e0e2fe124 | |||
| 9cfbd8107e | |||
| b70a4070f2 | |||
| d3b302ce66 | |||
| 5a423f88dd | |||
| b47877235f | |||
| f89c1edadf | |||
| bc5774c934 | |||
| 9e885c2379 | |||
| 1380d2c1e9 | |||
| 4895323200 | |||
| f737d2e8ce | |||
| 3157f97ae6 | |||
| 278329b73c | |||
| 033ec6bc76 | |||
| 1aa106ba4a | |||
| c638072902 | |||
| 6eb9041df4 | |||
| 4035f037d2 | |||
| 2b6f861f3b | |||
| 9a813030a3 | |||
| 04b7dd719c | |||
| 3ad3b30d97 | |||
| d0e7147911 | |||
| b0669b7eea | |||
| a504961e93 | |||
| b14bcf966d | |||
| 7ef37a9fa2 | |||
| d7ce455f2f | |||
| 7ffe857f52 |
+1
-1
Submodule cmd/Open-IM-SDK-Core updated: 588c9bb77b...18c0a4485c
@@ -3,11 +3,11 @@ package main
|
||||
import (
|
||||
_ "Open_IM/cmd/open_im_api/docs"
|
||||
apiAuth "Open_IM/internal/api/auth"
|
||||
apiChat "Open_IM/internal/api/chat"
|
||||
"Open_IM/internal/api/conversation"
|
||||
"Open_IM/internal/api/friend"
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/api/manage"
|
||||
apiChat "Open_IM/internal/api/msg"
|
||||
"Open_IM/internal/api/office"
|
||||
"Open_IM/internal/api/organization"
|
||||
apiThird "Open_IM/internal/api/third"
|
||||
@@ -139,14 +139,11 @@ func main() {
|
||||
chatGroup.POST("/send_msg", apiChat.SendMsg)
|
||||
chatGroup.POST("/pull_msg_by_seq", apiChat.PullMsgBySeqList)
|
||||
chatGroup.POST("/del_msg", apiChat.DelMsg)
|
||||
chatGroup.POST("/del_super_group_msg", apiChat.DelSuperGroupMsg)
|
||||
chatGroup.POST("/clear_msg", apiChat.ClearMsg)
|
||||
chatGroup.POST("/manage_send_msg", manage.ManagementSendMsg)
|
||||
chatGroup.POST("/batch_send_msg", manage.ManagementBatchSendMsg)
|
||||
}
|
||||
//Manager
|
||||
managementGroup := r.Group("/manager")
|
||||
{
|
||||
managementGroup.POST("/delete_user", manage.DeleteUser) //1
|
||||
chatGroup.POST("/set_msg_min_seq", apiChat.SetMsgMinSeq)
|
||||
}
|
||||
//Conversation
|
||||
conversationGroup := r.Group("/conversation")
|
||||
|
||||
@@ -50,6 +50,7 @@ func main() {
|
||||
}
|
||||
address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort)
|
||||
fmt.Println("start demo api server address: ", address)
|
||||
go register.OnboardingProcessRoutine()
|
||||
err := r.Run(address)
|
||||
if err != nil {
|
||||
log.Error("", "run failed ", *ginPort, err.Error())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpcChat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -12,6 +12,6 @@ func main() {
|
||||
rpcPort := flag.Int("port", defaultPorts[0], "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start msg rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
|
||||
rpcServer := msg.NewRpcChatServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
+10
-7
@@ -2,7 +2,7 @@
|
||||
# The class cannot be named by Pascal or camel case.
|
||||
# If it is not used, the corresponding structure will not be set,
|
||||
# and it will not be read naturally.
|
||||
serverversion: 2.0.0
|
||||
serverversion: 2.3.0-rc1
|
||||
#---------------Infrastructure configuration---------------------#
|
||||
etcd:
|
||||
etcdSchema: openim #默认即可
|
||||
@@ -38,6 +38,7 @@ redis:
|
||||
dbMaxIdle: 128
|
||||
dbMaxActive: 0
|
||||
dbIdleTimeout: 120
|
||||
dbUserName: #only redis version 6.0+ need username
|
||||
dbPassWord: openIM #redis密码 建议修改
|
||||
enableCluster: false #如果外部redis以集群方式启动,需要打开此开关
|
||||
|
||||
@@ -128,7 +129,8 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申
|
||||
stsDurationSeconds: 3600
|
||||
OssRoleArn: "acs:ram::xxx:role/xxx"
|
||||
|
||||
|
||||
dtm:
|
||||
serverURL: 43.128.5.63:10007
|
||||
|
||||
rpcport: #rpc服务端口 默认即可
|
||||
openImUserPort: [ 10110 ]
|
||||
@@ -158,9 +160,9 @@ rpcport: #rpc服务端口 默认即可
|
||||
rpcregistername: #rpc注册服务名,默认即可
|
||||
openImUserName: User
|
||||
openImFriendName: Friend
|
||||
openImOfflineMessageName: OfflineMessage
|
||||
openImMsgName: Msg
|
||||
openImPushName: Push
|
||||
openImOnlineMessageRelayName: OnlineMessageRelay
|
||||
openImRelayName: Relay
|
||||
openImGroupName: Group
|
||||
openImAuthName: Auth
|
||||
openImStatisticsName: Statistics
|
||||
@@ -174,7 +176,7 @@ rpcregistername: #rpc注册服务名,默认即可
|
||||
log:
|
||||
storageLocation: ../logs/
|
||||
rotationTime: 24
|
||||
remainRotationCount: 3 #日志数量
|
||||
remainRotationCount: 2 #日志数量
|
||||
#日志级别 6表示全都打印,测试阶段建议设置为6
|
||||
remainLogLevel: 6
|
||||
elasticSearchSwitch: false
|
||||
@@ -229,7 +231,7 @@ secret: tuoyun
|
||||
# 1:多平台登录:Android、iOS、Windows、Mac 每种平台只能一个在线,web端可以多个同时在线
|
||||
multiloginpolicy: 1
|
||||
|
||||
#chat log insert to db
|
||||
#msg log insert to db
|
||||
chatpersistencemysql: true
|
||||
#可靠性存储
|
||||
reliablestorage: false
|
||||
@@ -343,7 +345,7 @@ notification:
|
||||
desc: "memberQuit desc"
|
||||
ext: "memberQuit ext"
|
||||
defaultTips:
|
||||
tips: "quit group chat" # group info changed by xx
|
||||
tips: "quit group msg" # group info changed by xx
|
||||
|
||||
groupApplicationAccepted:
|
||||
conversation:
|
||||
@@ -706,6 +708,7 @@ demo:
|
||||
superCode: 666666 #超级验证码,建议修改掉,收不到短信验证码时可以用此替代
|
||||
# second
|
||||
codeTTL: 60
|
||||
useSuperCode: true
|
||||
mail: #仅支持qq邮箱,具体操作参考 https://service.mail.qq.com/cgi-bin/help?subtype=1&id=28&no=1001256 必须修改
|
||||
title: "openIM"
|
||||
senderMail: "765567899@qq.com"
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: admin-cms
|
||||
image: openim/admin_cms:v2.1.0
|
||||
image: openim/admin_cms:v2.2.0
|
||||
# imagePullPolicy: Always #每次启动都重新拉取镜像
|
||||
ports:
|
||||
- containerPort: 10200
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: api
|
||||
image: openim/api:v2.1.0
|
||||
image: openim/api:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10002
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: auth
|
||||
image: openim/auth:v2.1.0
|
||||
image: openim/auth:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10160
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
source ./path_info.cfg
|
||||
|
||||
# images version
|
||||
version=v2.1.0
|
||||
version=v2.2.0
|
||||
git pull
|
||||
cd ../script/; ./build_all_service.sh
|
||||
cd ../deploy_k8s/
|
||||
|
||||
Vendored
+1
-1
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: cache
|
||||
image: openim/cache:v2.1.0
|
||||
image: openim/cache:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10240
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: cms-api
|
||||
image: openim/cms_api:v2.1.0
|
||||
image: openim/cms_api:v2.2.0
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10006
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: conversation
|
||||
image: openim/conversation:v2.1.0
|
||||
image: openim/conversation:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10230
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: demo
|
||||
image: openim/demo:v2.1.0
|
||||
image: openim/demo:v2.2.0
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10004
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: friend
|
||||
image: openim/friend:v2.1.0
|
||||
image: openim/friend:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10120
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: group
|
||||
image: openim/group:v2.1.0
|
||||
image: openim/group:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10150
|
||||
|
||||
@@ -48,6 +48,12 @@ kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
nginx.ingress.kubernetes.io/Access-Control-Allow-Origin: '*'
|
||||
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,x-auth-token,Pagination
|
||||
nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
|
||||
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
|
||||
nginx.ingress.kubernetes.io/enable-cors: 'true'
|
||||
nginx.ingress.kubernetes.io/service-weight: ''
|
||||
name: api-ingress
|
||||
spec:
|
||||
rules:
|
||||
@@ -67,6 +73,12 @@ kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
nginx.ingress.kubernetes.io/Access-Control-Allow-Origin: '*'
|
||||
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,x-auth-token,Pagination
|
||||
nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
|
||||
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
|
||||
nginx.ingress.kubernetes.io/enable-cors: 'true'
|
||||
nginx.ingress.kubernetes.io/service-weight: ''
|
||||
name: demo-ingress
|
||||
spec:
|
||||
rules:
|
||||
@@ -86,6 +98,12 @@ kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
nginx.ingress.kubernetes.io/Access-Control-Allow-Origin: '*'
|
||||
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,x-auth-token,Pagination
|
||||
nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
|
||||
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
|
||||
nginx.ingress.kubernetes.io/enable-cors: 'true'
|
||||
nginx.ingress.kubernetes.io/service-weight: ''
|
||||
name: cms-api-ingress
|
||||
spec:
|
||||
rules:
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: message-cms
|
||||
image: openim/message_cms:v2.1.0
|
||||
image: openim/message_cms:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10190
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: msg
|
||||
image: openim/msg:v2.1.0
|
||||
image: openim/msg:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10130
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: msg-gateway
|
||||
image: openim/msg_gateway:v2.1.0
|
||||
image: openim/msg_gateway:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- name: rpc-port
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: msg-transfer
|
||||
image: openim/msg_transfer:v2.1.0
|
||||
image: openim/msg_transfer:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
volumeMounts:
|
||||
- name: config
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: office
|
||||
image: openim/office:v2.1.0
|
||||
image: openim/office:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10210
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: organization
|
||||
image: openim/organization:v2.1.0
|
||||
image: openim/organization:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10220
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: push
|
||||
image: openim/push:v2.1.0
|
||||
image: openim/push:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10170
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: sdk-server
|
||||
image: openim/sdk_server:v2.1.0
|
||||
image: openim/sdk_server:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10003
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: statistics
|
||||
image: openim/statistics:v2.1.0
|
||||
image: openim/statistics:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 10180
|
||||
|
||||
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: user
|
||||
image: openim/user:v2.1.0
|
||||
image: openim/user:v2.2.0
|
||||
# imagePullPolicy: Always
|
||||
volumeMounts:
|
||||
- name: config
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
version: "3"
|
||||
#fixme Clone openIM Server project before using docker-compose,project address:https://github.com/OpenIMSDK/Open-IM-Server.git
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
ports:
|
||||
- 13306:3306
|
||||
- 23306:33060
|
||||
container_name: mysql
|
||||
volumes:
|
||||
- ./components/mysql/data:/var/lib/mysql
|
||||
- /etc/localtime:/etc/localtime
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: openIM
|
||||
restart: always
|
||||
|
||||
mongos:
|
||||
image: mongo:latest
|
||||
ports:
|
||||
- 37017:27017
|
||||
container_name: mongos
|
||||
command: mongos --configdb config/103.116.45.174:27019 --bind_ip_all
|
||||
volumes:
|
||||
- ./components/mongos_mongodb/data/db:/data/db
|
||||
- ./components/mongos_mongodb/data/logs:/data/logs
|
||||
- ./components/mongos_mongodb/data/conf:/etc/mongo
|
||||
- ./components/mongos_mongodb/data/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
# environment:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=openIM
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=openIM
|
||||
|
||||
|
||||
#TZ: Asia/Shanghai
|
||||
restart: always
|
||||
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
ports:
|
||||
- 16379:6379
|
||||
container_name: redis
|
||||
volumes:
|
||||
- ./components/redis/data:/data
|
||||
#redis config file
|
||||
- ./components/redis/config/redis.conf:/usr/local/redis/config/redis.conf
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
restart: always
|
||||
sysctls:
|
||||
net.core.somaxconn: 1024
|
||||
command: redis-server --requirepass openIM --appendonly yes
|
||||
|
||||
|
||||
zookeeper:
|
||||
image: wurstmeister/zookeeper
|
||||
ports:
|
||||
- 2181:2181
|
||||
container_name: zookeeper
|
||||
volumes:
|
||||
- /etc/localtime:/etc/localtime
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
restart: always
|
||||
|
||||
|
||||
kafka:
|
||||
image: wurstmeister/kafka
|
||||
container_name: kafka
|
||||
restart: always
|
||||
ports:
|
||||
- 9092:9092
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
KAFKA_BROKER_ID: 0
|
||||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
||||
KAFKA_CREATE_TOPICS: "ws2ms_chat:8:1,ms2ps_chat:8:1,msg_to_mongo:8:1"
|
||||
KAFKA_ADVERTISED_LISTENERS: INSIDE://127.0.0.1:9092,OUTSIDE://103.116.45.174:9092
|
||||
KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9093
|
||||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT"
|
||||
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
|
||||
depends_on:
|
||||
- zookeeper
|
||||
|
||||
etcd:
|
||||
image: quay.io/coreos/etcd
|
||||
ports:
|
||||
- 2379:2379
|
||||
- 2380:2380
|
||||
container_name: etcd
|
||||
volumes:
|
||||
- /etc/timezone:/etc/timezone
|
||||
- /etc/localtime:/etc/localtime
|
||||
environment:
|
||||
ETCDCTL_API: 3
|
||||
restart: always
|
||||
command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new
|
||||
|
||||
minio:
|
||||
image: minio/minio
|
||||
ports:
|
||||
- 10005:9000
|
||||
- 9090:9090
|
||||
container_name: minio
|
||||
volumes:
|
||||
- /mnt/data:/data
|
||||
- /mnt/config:/root/.minio
|
||||
environment:
|
||||
MINIO_ROOT_USER: user12345
|
||||
MINIO_ROOT_PASSWORD: key12345
|
||||
restart: always
|
||||
command: minio server /data --console-address ':9090'
|
||||
|
||||
open_im_server:
|
||||
image: openim/open_im_server:v2.3.0-rc1
|
||||
container_name: open_im_server
|
||||
volumes:
|
||||
- ./logs:/Open-IM-Server/logs
|
||||
- ./config/config.yaml:/Open-IM-Server/config/config.yaml
|
||||
- ./db/sdk:/Open-IM-Server/db/sdk
|
||||
- ./script:/Open-IM-Server/script
|
||||
restart: always
|
||||
depends_on:
|
||||
- kafka
|
||||
- mysql
|
||||
- mongos
|
||||
- redis
|
||||
- etcd
|
||||
- minio
|
||||
network_mode: "host"
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "1g"
|
||||
max-file: "2"
|
||||
@@ -0,0 +1,113 @@
|
||||
version: '3'
|
||||
networks:
|
||||
mongo-network:
|
||||
external: false
|
||||
services:
|
||||
# 配置服务器configsvr
|
||||
config:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: config
|
||||
restart: always
|
||||
ports:
|
||||
- 27019:27019
|
||||
command: --configsvr --replSet "config" --bind_ip_all
|
||||
volumes:
|
||||
- ./components/config_mongodb/data/db:/data/db
|
||||
- ./components/config_mongodb/data/logs:/data/logs
|
||||
- ./components/config_mongodb/data/conf:/etc/mongo
|
||||
- ./components/config_mongodb/data/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
|
||||
# shard分片1
|
||||
shard1:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: shard1
|
||||
restart: always
|
||||
ports:
|
||||
- 27118:27018
|
||||
command: --shardsvr --replSet "shard1" --bind_ip_all
|
||||
volumes:
|
||||
- /data01/mongo/shard1/db:/data/db
|
||||
- /data01/mongo/shard1/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
|
||||
# shard分片2
|
||||
shard2:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: shard2
|
||||
restart: always
|
||||
ports:
|
||||
- 27218:27018
|
||||
command: --shardsvr --replSet "shard2" --bind_ip_all
|
||||
volumes:
|
||||
- /data02/mongo/shard2/db:/data/db
|
||||
- /data02/mongo/shard2/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
# - ${PWD}/key.file:/data/mongodb/key.file
|
||||
|
||||
# shard分片3
|
||||
shard3:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: shard3
|
||||
restart: always
|
||||
ports:
|
||||
- 27318:27018
|
||||
command: --shardsvr --replSet "shard3" --bind_ip_all
|
||||
volumes:
|
||||
- /data03/mongo/shard3/db:/data/db
|
||||
- /data03/mongo/shard3/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
# shard分片4
|
||||
shard4:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: shard4
|
||||
restart: always
|
||||
ports:
|
||||
- 27418:27018
|
||||
command: --shardsvr --replSet "shard4" --bind_ip_all
|
||||
volumes:
|
||||
- /data04/mongo/shard4/db:/data/db
|
||||
- /data04/mongo/shard4/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
# shard分片5
|
||||
shard5:
|
||||
image: mongo:latest
|
||||
networks:
|
||||
- mongo-network
|
||||
container_name: shard5
|
||||
restart: always
|
||||
ports:
|
||||
- 27518:27018
|
||||
command: --shardsvr --replSet "shard5" --bind_ip_all
|
||||
volumes:
|
||||
- /data05/mongo/shard5/db:/data/db
|
||||
- /data05/mongo/shard5/configdb:/data/configdb
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
+20
-8
@@ -25,16 +25,16 @@ services:
|
||||
- ./components/mongodb/data/db:/data/db
|
||||
- ./components/mongodb/data/logs:/data/logs
|
||||
- ./components/mongodb/data/conf:/etc/mongo
|
||||
# - ./script/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh
|
||||
# - ./script/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# cache
|
||||
- wiredTigerCacheSizeGB=1
|
||||
# - MONGO_USERNAME=openIM
|
||||
# - MONGO_PASSWORD=openIM
|
||||
# - MONGO_INITDB_ROOT_USERNAME=root
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=root
|
||||
# - MONGO_INITDB_DATABASE=openIM
|
||||
# - MONGO_USERNAME=openIM
|
||||
# - MONGO_PASSWORD=openIM
|
||||
# - MONGO_INITDB_ROOT_USERNAME=root
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=root
|
||||
# - MONGO_INITDB_DATABASE=openIM
|
||||
restart: always
|
||||
|
||||
redis:
|
||||
@@ -71,7 +71,7 @@ services:
|
||||
container_name: kafka
|
||||
restart: always
|
||||
ports:
|
||||
- 9092:9092
|
||||
- 9092:9092
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
KAFKA_BROKER_ID: 0
|
||||
@@ -112,9 +112,21 @@ services:
|
||||
MINIO_ROOT_PASSWORD: key12345
|
||||
restart: always
|
||||
command: minio server /data --console-address ':9090'
|
||||
#
|
||||
# dtm:
|
||||
# image: yedf/dtm
|
||||
# ports:
|
||||
# - 36789:36789
|
||||
# - 36790:36790
|
||||
# environment:
|
||||
# STORE_DRIVER: mysql
|
||||
# STORE_HOST: localhost
|
||||
# STORE_USER: root
|
||||
# STORE_PASSWORD: ''
|
||||
# STORE_PORT: 3306
|
||||
|
||||
open_im_server:
|
||||
image: openim/open_im_server:v2.2.0
|
||||
image: openim/open_im_server:v2.3.0-rc1
|
||||
container_name: open_im_server
|
||||
volumes:
|
||||
- ./logs:/Open-IM-Server/logs
|
||||
|
||||
@@ -10,25 +10,25 @@ require (
|
||||
github.com/alibabacloud-go/tea v1.1.17
|
||||
github.com/antonfisher/nested-logrus-formatter v1.3.0
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
github.com/dtm-labs/dtmcli v1.15.0
|
||||
github.com/dtm-labs/dtmgrpc v1.15.0
|
||||
github.com/dtm-labs/rockscache v0.0.8
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/go-openapi/spec v0.20.6 // indirect
|
||||
github.com/go-openapi/swag v0.21.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.11.0
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/jinzhu/copier v0.3.4
|
||||
github.com/jinzhu/gorm v1.9.16
|
||||
github.com/jinzhu/now v1.1.3 // indirect
|
||||
github.com/jonboulle/clockwork v0.2.2 // indirect
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/lestrrat-go/strftime v1.0.4 // indirect
|
||||
github.com/lib/pq v1.2.0 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.6 // indirect
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible
|
||||
github.com/minio/minio-go/v7 v7.0.22
|
||||
github.com/mitchellh/mapstructure v1.4.2
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
@@ -60,6 +60,8 @@ require (
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
gorm.io/driver/mysql v1.3.5
|
||||
gorm.io/gorm v1.23.8
|
||||
)
|
||||
|
||||
replace github.com/Shopify/sarama => github.com/Shopify/sarama v1.29.0
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
|
||||
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
@@ -49,6 +51,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
|
||||
github.com/antonfisher/nested-logrus-formatter v1.3.0 h1:8zixYquU1Odk+vzAaAQPAdRh1ZjmUXNQ1T+dUBvlhVo=
|
||||
github.com/antonfisher/nested-logrus-formatter v1.3.0/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
|
||||
github.com/aws/aws-sdk-go v1.38.3/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
@@ -80,10 +84,17 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/dtm-labs/dtmcli v1.15.0 h1:kqiV47I9Am/0QuzX11cGTPp/Z2AcOaRDXU7E7SZWYNk=
|
||||
github.com/dtm-labs/dtmcli v1.15.0/go.mod h1:otEdxUwM5FIKlCLmg5hL5+Z539DmCK2YJ0G4WNsP6Tw=
|
||||
github.com/dtm-labs/dtmdriver v0.0.3 h1:9iAtvXKR3lJXQ7dvS87e4xdtmqkzN+ofek+CF9AvUSY=
|
||||
github.com/dtm-labs/dtmdriver v0.0.3/go.mod h1:fLiEeD2BPwM9Yq96TfcP9KpbTwFsn5nTxa/PP0jmFuk=
|
||||
github.com/dtm-labs/dtmgrpc v1.15.0 h1:ZLSbCa/83J4LUR2A/h1h68D6EPuFfDkiUTZ5btKlJvg=
|
||||
github.com/dtm-labs/dtmgrpc v1.15.0/go.mod h1:fc7Mg6UGrNsHVsPrFNZhAH12/ddNHUP5E84EQY1Fz7w=
|
||||
github.com/dtm-labs/rockscache v0.0.8 h1:H6cXO7YhguE9jdvdfK5rrbUUu2MWjgWqsGEA645iFQQ=
|
||||
github.com/dtm-labs/rockscache v0.0.8/go.mod h1:vJmJJmuBNxcio03abYk1QPLmmQo/Kg92jB+28QmLcgY=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.2.0 h1:v7g92e/KSN71Rq7vSThKaWIq68fL4YHvWyiUKorFR1Q=
|
||||
@@ -100,7 +111,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
@@ -151,8 +161,12 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn
|
||||
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
||||
github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
|
||||
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
|
||||
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q=
|
||||
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
|
||||
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
@@ -167,7 +181,6 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0=
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
@@ -198,13 +211,15 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||
@@ -238,8 +253,9 @@ github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBef
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
|
||||
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||
@@ -286,8 +302,8 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECae
|
||||
github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8=
|
||||
github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
|
||||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
|
||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
@@ -297,8 +313,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
|
||||
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
|
||||
@@ -320,6 +334,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
@@ -337,6 +353,7 @@ github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
@@ -459,12 +476,17 @@ go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R
|
||||
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
|
||||
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
|
||||
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
|
||||
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
|
||||
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
@@ -487,6 +509,8 @@ golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+o
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
@@ -524,7 +548,9 @@ golang.org/x/net v0.0.0-20210427231257-85d9c07bbe3a/go.mod h1:OJAsFXCWl8Ukc7SiCT
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220622184535-263ec571b305 h1:dAgbJ2SP4jD6XYfMNLVj0BF21jo2PjChrtGaAvF5M3I=
|
||||
golang.org/x/net v0.0.0-20220622184535-263ec571b305/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
@@ -619,6 +645,7 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||
google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48=
|
||||
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 h1:z+ErRPu0+KS02Td3fOAgdX+lnPDh/VyaABEJPD4JRQs=
|
||||
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
@@ -629,7 +656,9 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
|
||||
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
|
||||
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
|
||||
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
|
||||
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
@@ -665,6 +694,8 @@ gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
|
||||
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -681,8 +712,10 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY=
|
||||
gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
|
||||
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
|
||||
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
// @Tags 鉴权认证
|
||||
// @ID UserRegister
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.UserRegisterReq true "secret为openIM密钥, 详细见服务端config.yaml secret字段 <br> platform为平台ID <br> ex为拓展字段 <br> gender为性别, 0为女, 1为男"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.UserRegisterResp
|
||||
@@ -90,7 +89,6 @@ func UserRegister(c *gin.Context) {
|
||||
// @Tags 鉴权认证
|
||||
// @ID UserToken
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.UserTokenReq true "secret为openIM密钥, 详细见服务端config.yaml secret字段 <br> platform为平台ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.UserTokenResp
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package apiChat
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
rpc "Open_IM/pkg/proto/chat"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary 根据seq列表删除消息
|
||||
// @Description 根据seq列表删除消息
|
||||
// @Tags 消息相关
|
||||
// @ID DelMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DelMsgReq true "userID为要删除的用户ID <br> seqList为seq列表"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DelMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/del_msg [post]
|
||||
func DelMsg(c *gin.Context) {
|
||||
var (
|
||||
req api.DelMsgReq
|
||||
resp api.DelMsgResp
|
||||
reqPb pbCommon.DelMsgListReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewChatClient(grpcConn)
|
||||
respPb, err := msgClient.DelMsgList(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 清空用户消息
|
||||
// @Description 清空用户消息
|
||||
// @Tags 消息相关
|
||||
// @ID ClearMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CleanUpMsgReq true "userID为要清空的用户ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CleanUpMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/clear_msg [post]
|
||||
func ClearMsg(c *gin.Context) {
|
||||
params := api.CleanUpMsgReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
//
|
||||
req := &rpc.ClearMsgReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewChatClient(etcdConn)
|
||||
RpcResp, err := client.ClearMsg(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, " CleanUpMsg failed ", err.Error(), req.String(), RpcResp.ErrMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": RpcResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CleanUpMsgResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package group
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
@@ -316,7 +317,12 @@ func InviteUserToGroup(c *gin.Context) {
|
||||
}
|
||||
req := &rpc.InviteUserToGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
if len(req.InvitedUserIDList) > constant.MaxNotificationNum {
|
||||
errMsg := req.OperationID + " too many, Limit: " + utils.IntToString(constant.MaxNotificationNum)
|
||||
log.NewError(req.OperationID, errMsg, len(req.InvitedUserIDList))
|
||||
c.JSON(http.StatusRequestEntityTooLarge, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
@@ -779,12 +785,7 @@ func SetGroupInfo(c *gin.Context) {
|
||||
req := &rpc.SetGroupInfoReq{GroupInfoForSet: &open_im_sdk.GroupInfoForSet{}}
|
||||
utils.CopyStructFields(req.GroupInfoForSet, ¶ms)
|
||||
req.OperationID = params.OperationID
|
||||
|
||||
if params.NeedVerification != nil {
|
||||
req.GroupInfoForSet.NeedVerification = &wrappers.Int32Value{Value: *params.NeedVerification}
|
||||
log.NewInfo(req.OperationID, "NeedVerification ", req.GroupInfoForSet.NeedVerification)
|
||||
}
|
||||
|
||||
argsHandle(¶ms, req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
@@ -815,6 +816,20 @@ func SetGroupInfo(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.OperationID, "SetGroupInfo api return ", resp)
|
||||
}
|
||||
func argsHandle(params *api.SetGroupInfoReq, req *rpc.SetGroupInfoReq) {
|
||||
if params.NeedVerification != nil {
|
||||
req.GroupInfoForSet.NeedVerification = &wrappers.Int32Value{Value: *params.NeedVerification}
|
||||
log.NewInfo(req.OperationID, "NeedVerification ", req.GroupInfoForSet.NeedVerification)
|
||||
}
|
||||
if params.LookMemberInfo != nil {
|
||||
req.GroupInfoForSet.LookMemberInfo = &wrappers.Int32Value{Value: *params.LookMemberInfo}
|
||||
log.NewInfo(req.OperationID, "LookMemberInfo ", req.GroupInfoForSet.LookMemberInfo)
|
||||
}
|
||||
if params.ApplyMemberFriend != nil {
|
||||
req.GroupInfoForSet.ApplyMemberFriend = &wrappers.Int32Value{Value: *params.ApplyMemberFriend}
|
||||
log.NewInfo(req.OperationID, "ApplyMemberFriend ", req.GroupInfoForSet.ApplyMemberFriend)
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 转让群主
|
||||
// @Description 转让群主
|
||||
|
||||
@@ -47,7 +47,7 @@ func GetJoinedSuperGroupList(c *gin.Context) {
|
||||
}
|
||||
GroupListResp := api.GetJoinedSuperGroupListResp{GetJoinedGroupListResp: api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, GroupInfoList: rpcResp.GroupList}}
|
||||
GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
|
||||
log.NewInfo(req.OperationID, "GetJoinedSuperGroupList api return ", GroupListResp)
|
||||
c.JSON(http.StatusOK, GroupListResp)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/proto/sdk_ws"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -185,14 +185,14 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
pbData := newUserSendMsgReq(¶ms)
|
||||
log.Info(params.OperationID, "", "api ManagementSendMsg call start..., [data: %s]", pbData.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, params.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, params.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := params.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(params.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
|
||||
log.Info(params.OperationID, "", "api ManagementSendMsg call, api call rpc...")
|
||||
|
||||
@@ -294,14 +294,14 @@ func ManagementBatchSendMsg(c *gin.Context) {
|
||||
pbData := newUserSendMsgReq(req)
|
||||
pbData.MsgData.RecvID = recvID
|
||||
log.Info(params.OperationID, "", "api ManagementSendMsg call start..., ", pbData.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, params.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, params.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := params.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(params.OperationID, errMsg)
|
||||
resp.Data.FailedIDList = append(resp.Data.FailedIDList, recvID)
|
||||
continue
|
||||
}
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
rpcResp, err := client.SendMsg(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "call delete UserSendMsg rpc server failed", err.Error())
|
||||
|
||||
@@ -198,9 +198,9 @@ func GetUsersOnlineStatus(c *gin.Context) {
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
client := pbRelay.NewRelayClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
rpc "Open_IM/pkg/proto/msg"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary 根据seq列表删除消息
|
||||
// @Description 根据seq列表删除消息
|
||||
// @Tags 消息相关
|
||||
// @ID DelMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DelMsgReq true "userID为要删除的用户ID <br> seqList为seq列表"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DelMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/del_msg [post]
|
||||
func DelMsg(c *gin.Context) {
|
||||
var (
|
||||
req api.DelMsgReq
|
||||
resp api.DelMsgResp
|
||||
reqPb pbCommon.DelMsgListReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.DelMsgList(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
func DelSuperGroupMsg(c *gin.Context) {
|
||||
var (
|
||||
req api.DelSuperGroupMsgReq
|
||||
resp api.DelSuperGroupMsgResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
|
||||
ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + opUserID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
options := make(map[string]bool, 5)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||
pbData := rpc.SendMsgReq{
|
||||
OperationID: req.OperationID,
|
||||
MsgData: &pbCommon.MsgData{
|
||||
SendID: req.UserID,
|
||||
RecvID: req.UserID,
|
||||
ClientMsgID: utils.GetMsgID(req.UserID),
|
||||
SessionType: constant.SingleChatType,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.MsgDeleteNotification,
|
||||
// ForceList: params.ForceList,
|
||||
CreateTime: utils.GetCurrentTimestampByMill(),
|
||||
Options: options,
|
||||
},
|
||||
}
|
||||
var tips pbCommon.TipsComm
|
||||
deleteMsg := api.MsgDeleteNotificationElem{
|
||||
GroupID: req.GroupID,
|
||||
IsAllDelete: req.IsAllDelete,
|
||||
SeqList: req.SeqList,
|
||||
}
|
||||
tips.JsonDetail = utils.StructToJsonString(deleteMsg)
|
||||
var err error
|
||||
pbData.MsgData.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
resp.ErrCode = 400
|
||||
resp.ErrMsg = err.Error()
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call start..., [data: %s]", pbData.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call, api call rpc...")
|
||||
|
||||
RpcResp, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "call delete UserSendMsg rpc server failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call UserSendMsg rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String())
|
||||
resp.ErrCode = RpcResp.ErrCode
|
||||
resp.ErrMsg = RpcResp.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 清空用户消息
|
||||
// @Description 清空用户消息
|
||||
// @Tags 消息相关
|
||||
// @ID ClearMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CleanUpMsgReq true "userID为要清空的用户ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CleanUpMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/clear_msg [post]
|
||||
func ClearMsg(c *gin.Context) {
|
||||
params := api.CleanUpMsgReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
//
|
||||
req := &rpc.ClearMsgReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
RpcResp, err := client.ClearMsg(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, " CleanUpMsg failed ", err.Error(), req.String(), RpcResp.ErrMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": RpcResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CleanUpMsgResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 设置用户最小seq
|
||||
// @Description 设置用户最小seq,以及用户相关读扩散群组最小seq
|
||||
// @Tags 消息相关
|
||||
// @ID SetMsgMinSeq
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
func SetMsgMinSeq(c *gin.Context) {
|
||||
params := api.SetMsgMinSeqReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
//
|
||||
req := &rpc.SetMsgMinSeqReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
RpcResp, err := client.SetMsgMinSeq(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, " SetMsgMinSeq failed ", err.Error(), req.String(), RpcResp.ErrMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": RpcResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.SetMsgMinSeqResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package apiChat
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -35,7 +35,7 @@ func GetSeq(c *gin.Context) {
|
||||
pbData := sdk_ws.GetMaxAndMinSeqReq{}
|
||||
pbData.UserID = params.SendID
|
||||
pbData.OperationID = params.OperationID
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, pbData.OperationID)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, pbData.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := pbData.OperationID + " getcdv3.GetConn == nil"
|
||||
log.NewError(pbData.OperationID, errMsg)
|
||||
@@ -43,7 +43,7 @@ func GetSeq(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
msgClient := pbChat.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "UserGetSeq rpc failed, ", params, err.Error())
|
||||
@@ -1,11 +1,11 @@
|
||||
package apiChat
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/chat"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -51,14 +51,14 @@ func PullMsgBySeqList(c *gin.Context) {
|
||||
pbData.OperationID = params.OperationID
|
||||
pbData.SeqList = params.SeqList
|
||||
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, pbData.OperationID)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, pbData.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := pbData.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(pbData.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
msgClient := msg.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.Error(pbData.OperationID, "PullMessageBySeqList error", err.Error())
|
||||
@@ -1,9 +1,9 @@
|
||||
package apiChat
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
|
||||
@@ -71,14 +71,14 @@ func SendMsg(c *gin.Context) {
|
||||
pbData := newUserSendMsgReq(token, ¶ms)
|
||||
log.Info(params.OperationID, "", "api SendMsg call start..., [data: %s]", pbData.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, params.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, params.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := params.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(params.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
|
||||
log.Info("", "", "api SendMsg call, api call rpc...")
|
||||
|
||||
@@ -324,8 +324,9 @@ func SetGlobalRecvMessageOpt(c *gin.Context) {
|
||||
func GetSelfUserInfo(c *gin.Context) {
|
||||
params := api.GetSelfUserInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
errMsg := "BindJSON failed " + err.Error()
|
||||
log.NewError("0", "BindJSON failed ", errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserInfoReq{}
|
||||
@@ -414,9 +415,9 @@ func GetUsersOnlineStatus(c *gin.Context) {
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
client := pbRelay.NewRelayClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type ParamsLogin struct {
|
||||
UserID string `json:"userID"`
|
||||
Email string `json:"email"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Password string `json:"password"`
|
||||
@@ -32,11 +33,13 @@ func Login(c *gin.Context) {
|
||||
var account string
|
||||
if params.Email != "" {
|
||||
account = params.Email
|
||||
} else {
|
||||
} else if params.PhoneNumber != "" {
|
||||
account = params.PhoneNumber
|
||||
} else {
|
||||
account = params.UserID
|
||||
}
|
||||
|
||||
r, err := im_mysql_model.GetRegister(account, params.AreaCode)
|
||||
r, err := im_mysql_model.GetRegister(account, params.AreaCode, params.UserID)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "user have not register", params.Password, account, err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "Mobile phone number is not registered"})
|
||||
|
||||
@@ -21,6 +21,30 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type OnboardingProcessReq struct {
|
||||
OperationID string
|
||||
UserID string
|
||||
NickName string
|
||||
FaceURL string
|
||||
PhoneNumber string
|
||||
Email string
|
||||
}
|
||||
|
||||
var Ch chan OnboardingProcessReq
|
||||
|
||||
func init() {
|
||||
Ch = make(chan OnboardingProcessReq, 1000)
|
||||
}
|
||||
|
||||
func OnboardingProcessRoutine() {
|
||||
for {
|
||||
req := <-Ch
|
||||
go func() {
|
||||
onboardingProcess(req.OperationID, req.UserID, req.NickName, req.FaceURL, req.PhoneNumber, req.Email)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func onboardingProcess(operationID, userID, userName, faceURL, phoneNumber, email string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), userName, userID, faceURL)
|
||||
if err := createOrganizationUser(operationID, userID, userName, phoneNumber, email); err != nil {
|
||||
@@ -208,7 +232,7 @@ func onboardingProcessNotification(operationID, userID, groupID, userName, faceU
|
||||
Content: []byte(welcomeString),
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.Text,
|
||||
SessionType: constant.GroupChatType,
|
||||
SessionType: constant.SuperGroupChatType,
|
||||
OperationID: operationID,
|
||||
SenderNickname: userName,
|
||||
SenderFaceURL: faceURL,
|
||||
|
||||
@@ -34,7 +34,8 @@ func ResetPassword(c *gin.Context) {
|
||||
} else {
|
||||
account = req.PhoneNumber
|
||||
}
|
||||
if req.VerificationCode != config.Config.Demo.SuperCode {
|
||||
|
||||
if (config.Config.Demo.UseSuperCode && req.VerificationCode != config.Config.Demo.SuperCode) || !config.Config.Demo.UseSuperCode {
|
||||
accountKey := req.AreaCode + account + "_" + constant.VerificationCodeForResetSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
if err != nil || v != req.VerificationCode {
|
||||
@@ -43,7 +44,7 @@ func ResetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
user, err := im_mysql_model.GetRegister(account, req.AreaCode)
|
||||
user, err := im_mysql_model.GetRegister(account, req.AreaCode, "")
|
||||
if err != nil || user.Account == "" {
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
|
||||
|
||||
@@ -66,7 +66,7 @@ func SendVerificationCode(c *gin.Context) {
|
||||
}
|
||||
switch params.UsedFor {
|
||||
case constant.VerificationCodeForRegister:
|
||||
_, err := im_mysql_model.GetRegister(account, params.AreaCode)
|
||||
_, err := im_mysql_model.GetRegister(account, params.AreaCode, "")
|
||||
if err == nil {
|
||||
log.NewError(params.OperationID, "The phone number has been registered", params)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": "The phone number has been registered"})
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
)
|
||||
|
||||
type ParamsSetPassword struct {
|
||||
UserID string `json:"userID"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
@@ -40,29 +41,37 @@ func SetPassword(c *gin.Context) {
|
||||
var account string
|
||||
if params.Email != "" {
|
||||
account = params.Email
|
||||
} else {
|
||||
} else if params.PhoneNumber != "" {
|
||||
account = params.PhoneNumber
|
||||
} else {
|
||||
account = params.UserID
|
||||
}
|
||||
if params.Nickname == "" {
|
||||
params.Nickname = account
|
||||
}
|
||||
if params.VerificationCode != config.Config.Demo.SuperCode {
|
||||
accountKey := params.AreaCode + account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
if err != nil || v != params.VerificationCode {
|
||||
log.NewError(params.OperationID, "password Verification code error", account, params.VerificationCode)
|
||||
data := make(map[string]interface{})
|
||||
data["PhoneNumber"] = account
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code error!", "data": data})
|
||||
return
|
||||
if params.UserID == "" {
|
||||
if (config.Config.Demo.UseSuperCode && params.VerificationCode != config.Config.Demo.SuperCode) || !config.Config.Demo.UseSuperCode {
|
||||
accountKey := params.AreaCode + account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
if err != nil || v != params.VerificationCode {
|
||||
log.NewError(params.OperationID, "password Verification code error", account, params.VerificationCode)
|
||||
data := make(map[string]interface{})
|
||||
data["PhoneNumber"] = account
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code error!", "data": data})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
//userID := utils.Base64Encode(account)
|
||||
|
||||
userID := utils.Md5(params.OperationID + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(userID[0:8], 16)
|
||||
userID = bi.String()
|
||||
var userID string
|
||||
if params.UserID == "" {
|
||||
userID = utils.Md5(params.OperationID + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(userID[0:8], 16)
|
||||
userID = bi.String()
|
||||
} else {
|
||||
userID = params.UserID
|
||||
}
|
||||
|
||||
url := config.Config.Demo.ImAPIURL + "/auth/user_register"
|
||||
openIMRegisterReq := api.UserRegisterReq{}
|
||||
@@ -73,6 +82,7 @@ func SetPassword(c *gin.Context) {
|
||||
openIMRegisterReq.Secret = config.Config.Secret
|
||||
openIMRegisterReq.FaceURL = params.FaceURL
|
||||
openIMRegisterResp := api.UserRegisterResp{}
|
||||
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
|
||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "request openIM register error", account, "err", err.Error())
|
||||
@@ -97,7 +107,20 @@ func SetPassword(c *gin.Context) {
|
||||
}
|
||||
log.Info(params.OperationID, "end setPassword", account, params.Password)
|
||||
// demo onboarding
|
||||
onboardingProcess(params.OperationID, userID, params.Nickname, params.FaceURL, params.AreaCode+params.PhoneNumber, params.Email)
|
||||
if params.UserID == "" {
|
||||
select {
|
||||
case Ch <- OnboardingProcessReq{
|
||||
OperationID: params.OperationID,
|
||||
UserID: userID,
|
||||
NickName: params.Nickname,
|
||||
FaceURL: params.FaceURL,
|
||||
PhoneNumber: params.AreaCode + params.PhoneNumber,
|
||||
Email: params.Email,
|
||||
}:
|
||||
case <-time.After(time.Second * 2):
|
||||
log.NewWarn(params.OperationID, utils.GetSelfFuncName(), "to ch timeOut")
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func Verify(c *gin.Context) {
|
||||
account = params.AreaCode + params.PhoneNumber
|
||||
}
|
||||
|
||||
if params.VerificationCode == config.Config.Demo.SuperCode {
|
||||
if config.Config.Demo.UseSuperCode && params.VerificationCode == config.Config.Demo.SuperCode {
|
||||
log.NewInfo(params.OperationID, "Super Code Verified successfully", account)
|
||||
data := make(map[string]interface{})
|
||||
data["account"] = account
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -89,14 +89,14 @@ func (r *RPCServer) GetSingleUserMsg(operationID string, currentMsgSeq uint32, u
|
||||
rpcReq.SeqList = seqList
|
||||
rpcReq.UserID = userID
|
||||
rpcReq.OperationID = operationID
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, rpcReq.OperationID)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, rpcReq.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := "getcdv3.GetConn == nil"
|
||||
log.NewError(rpcReq.OperationID, errMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
msgClient := pbChat.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &rpcReq)
|
||||
if err != nil {
|
||||
log.Error(operationID, "PullMessageBySeqList failed ", err.Error(), rpcReq.String())
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -69,7 +69,7 @@ func (ws *WServer) getSeqReq(conn *UserConn, m *Req) {
|
||||
rpcReq.UserID = m.SendID
|
||||
rpcReq.OperationID = m.OperationID
|
||||
log.Debug(m.OperationID, "Ws call success to getMaxAndMinSeq", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(sdk_ws.GetMaxAndMinSeqReq).GroupIDList)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, rpcReq.OperationID)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, rpcReq.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := rpcReq.OperationID + "getcdv3.GetConn == nil"
|
||||
nReply.ErrCode = 500
|
||||
@@ -78,7 +78,7 @@ func (ws *WServer) getSeqReq(conn *UserConn, m *Req) {
|
||||
ws.getSeqResp(conn, m, nReply)
|
||||
return
|
||||
}
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
msgClient := pbChat.NewMsgClient(grpcConn)
|
||||
rpcReply, err := msgClient.GetMaxAndMinSeq(context.Background(), &rpcReq)
|
||||
if err != nil {
|
||||
nReply.ErrCode = 500
|
||||
@@ -124,7 +124,7 @@ func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) {
|
||||
rpcReq.OperationID = m.OperationID
|
||||
rpcReq.GroupSeqList = data.(sdk_ws.PullMessageBySeqListReq).GroupSeqList
|
||||
log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq middle", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(sdk_ws.PullMessageBySeqListReq).SeqList)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, m.OperationID)
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, m.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := rpcReq.OperationID + "getcdv3.GetConn == nil"
|
||||
nReply.ErrCode = 500
|
||||
@@ -133,7 +133,7 @@ func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) {
|
||||
ws.pullMsgBySeqListResp(conn, m, nReply)
|
||||
return
|
||||
}
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
msgClient := pbChat.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &rpcReq)
|
||||
if err != nil {
|
||||
log.NewError(rpcReq.OperationID, "pullMsgBySeqListReq err", err.Error())
|
||||
@@ -183,7 +183,7 @@ func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) {
|
||||
MsgData: &data,
|
||||
}
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, data.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, m.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, m.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := m.OperationID + "getcdv3.GetConn == nil"
|
||||
nReply.ErrCode = 500
|
||||
@@ -192,7 +192,7 @@ func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) {
|
||||
ws.sendMsgResp(conn, m, nReply)
|
||||
return
|
||||
}
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, "UserSendMsg err", err.Error())
|
||||
@@ -264,14 +264,14 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||
}
|
||||
log.NewInfo(m.OperationID, utils.GetSelfFuncName(), "pbData: ", pbData)
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, msgData)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, m.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, m.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := m.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(m.OperationID, errMsg)
|
||||
ws.sendSignalMsgResp(conn, 200, errMsg, m, &signalResp)
|
||||
return
|
||||
}
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, utils.GetSelfFuncName(), "rpc sendMsg err", err.Error())
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ type RPCServer struct {
|
||||
|
||||
func (r *RPCServer) onInit(rpcPort int) {
|
||||
r.rpcPort = rpcPort
|
||||
r.rpcRegisterName = config.Config.RpcRegisterName.OpenImOnlineMessageRelayName
|
||||
r.rpcRegisterName = config.Config.RpcRegisterName.OpenImRelayName
|
||||
r.etcdSchema = config.Config.Etcd.EtcdSchema
|
||||
r.etcdAddr = config.Config.Etcd.EtcdAddr
|
||||
r.platformList = genPlatformArray()
|
||||
@@ -53,7 +53,7 @@ func (r *RPCServer) run() {
|
||||
defer listener.Close()
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
pbRelay.RegisterOnlineMessageRelayServiceServer(srv, r)
|
||||
pbRelay.RegisterRelayServer(srv, r)
|
||||
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
@@ -3,7 +3,7 @@ package logic
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
kfk "Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
pbPush "Open_IM/pkg/proto/push"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -97,36 +97,50 @@ func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
|
||||
// return
|
||||
//}
|
||||
log.Debug(triggerID, "msg storage length", len(storageMsgList), "push length", len(notStoragePushMsgList))
|
||||
err, lastSeq := saveUserChatList(msgChannelValue.aggregationID, storageMsgList, triggerID)
|
||||
if err != nil {
|
||||
singleMsgFailedCount += uint64(len(storageMsgList))
|
||||
log.NewError(triggerID, "single data insert to redis err", err.Error(), storageMsgList)
|
||||
if len(storageMsgList) > 0 {
|
||||
err, lastSeq := saveUserChatList(msgChannelValue.aggregationID, storageMsgList, triggerID)
|
||||
if err != nil {
|
||||
singleMsgFailedCount += uint64(len(storageMsgList))
|
||||
log.NewError(triggerID, "single data insert to redis err", err.Error(), storageMsgList)
|
||||
} else {
|
||||
singleMsgSuccessCountMutex.Lock()
|
||||
singleMsgSuccessCount += uint64(len(storageMsgList))
|
||||
singleMsgSuccessCountMutex.Unlock()
|
||||
och.SendMessageToMongoCH(msgChannelValue.aggregationID, triggerID, storageMsgList, lastSeq)
|
||||
go func(push, storage []*pbMsg.MsgDataToMQ) {
|
||||
for _, v := range storage {
|
||||
sendMessageToPush(v, msgChannelValue.aggregationID)
|
||||
}
|
||||
for _, x := range push {
|
||||
sendMessageToPush(x, msgChannelValue.aggregationID)
|
||||
}
|
||||
|
||||
}(notStoragePushMsgList, storageMsgList)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
singleMsgSuccessCountMutex.Lock()
|
||||
singleMsgSuccessCount += uint64(len(storageMsgList))
|
||||
singleMsgSuccessCountMutex.Unlock()
|
||||
och.SendMessageToMongoCH(msgChannelValue.aggregationID, triggerID, storageMsgList, lastSeq)
|
||||
go func(push, storage []*pbMsg.MsgDataToMQ) {
|
||||
for _, v := range storage {
|
||||
sendMessageToPush(v, msgChannelValue.aggregationID)
|
||||
}
|
||||
go func(push []*pbMsg.MsgDataToMQ) {
|
||||
for _, x := range push {
|
||||
sendMessageToPush(x, msgChannelValue.aggregationID)
|
||||
}
|
||||
|
||||
}(notStoragePushMsgList, storageMsgList)
|
||||
}(notStoragePushMsgList)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func (och *OnlineHistoryRedisConsumerHandler) SendMessageToMongoCH(aggregationID string, triggerID string, messages []*pbMsg.MsgDataToMQ, lastSeq uint64) {
|
||||
pid, offset, err := producerToMongo.SendMessage(&pbMsg.MsgDataToMongoByMQ{LastSeq: lastSeq, AggregationID: aggregationID, MessageList: messages, TriggerID: triggerID}, aggregationID, triggerID)
|
||||
if err != nil {
|
||||
log.Error(triggerID, "kafka send failed", "send data", len(messages), "pid", pid, "offset", offset, "err", err.Error(), "key", aggregationID)
|
||||
} else {
|
||||
// log.NewWarn(m.OperationID, "sendMsgToKafka client msgID ", m.MsgData.ClientMsgID)
|
||||
if len(messages) > 0 {
|
||||
pid, offset, err := producerToMongo.SendMessage(&pbMsg.MsgDataToMongoByMQ{LastSeq: lastSeq, AggregationID: aggregationID, MessageList: messages, TriggerID: triggerID}, aggregationID, triggerID)
|
||||
if err != nil {
|
||||
log.Error(triggerID, "kafka send failed", "send data", len(messages), "pid", pid, "offset", offset, "err", err.Error(), "key", aggregationID)
|
||||
} else {
|
||||
// log.NewWarn(m.OperationID, "sendMsgToKafka client msgID ", m.MsgData.ClientMsgID)
|
||||
}
|
||||
}
|
||||
//hashCode := getHashCode(aggregationID)
|
||||
//channelID := hashCode % ChannelNum
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
kfk "Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/Shopify/sarama"
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_msg_model"
|
||||
kfk "Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
kfk "Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbPush "Open_IM/pkg/proto/push"
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
@@ -45,12 +45,12 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
||||
log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
||||
if len(grpcCons) == 0 {
|
||||
log.NewWarn(pushMsg.OperationID, "first GetConn4Unique ")
|
||||
grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
}
|
||||
//Online push message
|
||||
log.Debug(pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
|
||||
for _, v := range grpcCons {
|
||||
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
msgClient := pbRelay.NewRelayClient(v)
|
||||
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(context.Background(), &pbRelay.OnlineBatchPushOneMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserIDList: []string{pushMsg.PushToUserID}})
|
||||
if err != nil {
|
||||
log.NewError("SuperGroupOnlineBatchPushOneMsg push data to client rpc err", pushMsg.OperationID, "err", err)
|
||||
@@ -167,12 +167,12 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
|
||||
}
|
||||
if len(grpcCons) == 0 {
|
||||
log.NewWarn(pushMsg.OperationID, "first GetConn4Unique ")
|
||||
grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
}
|
||||
//Online push message
|
||||
log.Debug("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
|
||||
for _, v := range grpcCons {
|
||||
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
msgClient := pbRelay.NewRelayClient(v)
|
||||
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(context.Background(), &pbRelay.OnlineBatchPushOneMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserIDList: cacheResp.UserIDList})
|
||||
if err != nil {
|
||||
log.NewError("push data to client rpc err", pushMsg.OperationID, "err", err)
|
||||
@@ -233,30 +233,32 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
|
||||
|
||||
}
|
||||
}
|
||||
if len(onlineFailedUserIDList) > 0 {
|
||||
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList[0], pushMsg.MsgData)
|
||||
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
|
||||
}
|
||||
if callbackResp.ActionCode != constant.ActionAllow {
|
||||
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
|
||||
return
|
||||
}
|
||||
if offlinePusher == nil {
|
||||
return
|
||||
}
|
||||
opts, err := GetOfflinePushOpts(pushMsg)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetOfflinePushOpts failed", pushMsg, err.Error())
|
||||
}
|
||||
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), onlineFailedUserIDList, content, jsonCustomContent, "opts:", opts)
|
||||
pushResult, err := offlinePusher.Push(onlineFailedUserIDList, content, jsonCustomContent, pushMsg.OperationID, opts)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
||||
} else {
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
||||
}
|
||||
}
|
||||
|
||||
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList[0], pushMsg.MsgData)
|
||||
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
|
||||
}
|
||||
if callbackResp.ActionCode != constant.ActionAllow {
|
||||
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
|
||||
return
|
||||
}
|
||||
if offlinePusher == nil {
|
||||
return
|
||||
}
|
||||
opts, err := GetOfflinePushOpts(pushMsg)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetOfflinePushOpts failed", pushMsg, err.Error())
|
||||
}
|
||||
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), onlineFailedUserIDList, content, jsonCustomContent, "opts:", opts)
|
||||
pushResult, err := offlinePusher.Push(onlineFailedUserIDList, content, jsonCustomContent, pushMsg.OperationID, opts)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
||||
} else {
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,9 +83,9 @@ func (rpc *rpcAuth) ForceLogout(_ context.Context, req *pbAuth.ForceLogoutReq) (
|
||||
|
||||
func (rpc *rpcAuth) forceKickOff(userID string, platformID int32, operationID string) error {
|
||||
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
client := pbRelay.NewRelayClient(v)
|
||||
kickReq := &pbRelay.KickUserOfflineReq{OperationID: operationID, KickUserIDList: []string{userID}, PlatformID: platformID}
|
||||
log.NewInfo(operationID, "KickUserOffline ", client, kickReq.String())
|
||||
_, err := client.KickUserOffline(context.Background(), kickReq)
|
||||
|
||||
Vendored
+24
-230
@@ -3,20 +3,16 @@ package cache
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type cacheServer struct {
|
||||
@@ -54,13 +50,6 @@ func (s *cacheServer) Run() {
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
|
||||
//to cache
|
||||
err = SyncDB2Cache()
|
||||
if err != nil {
|
||||
log.NewError("", err.Error(), "db to cache failed")
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
pbCache.RegisterCacheServer(srv, s)
|
||||
@@ -86,167 +75,10 @@ func (s *cacheServer) Run() {
|
||||
log.NewInfo("0", "message cms rpc success")
|
||||
}
|
||||
|
||||
func SyncDB2Cache() error {
|
||||
var err error
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
userList, err := imdb.GetAllUser()
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "userList", userList)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
//err = updateAllUserToCache(userList)
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(3)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err = updateAllFriendToCache(userList)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err = updateAllBlackListToCache(userList)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err = updateAllGroupMemberListToCache()
|
||||
}()
|
||||
wg.Wait()
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelRelationCache() {}
|
||||
|
||||
func updateAllUserToCache(userList []db.User) error {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(len(userList))
|
||||
for _, userInfo := range userList {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
userInfoPb := &commonPb.UserInfo{
|
||||
UserID: userInfo.UserID,
|
||||
Nickname: userInfo.Nickname,
|
||||
FaceURL: userInfo.FaceURL,
|
||||
Gender: userInfo.Gender,
|
||||
PhoneNumber: userInfo.PhoneNumber,
|
||||
Birth: uint32(userInfo.Birth.Unix()),
|
||||
Email: userInfo.Email,
|
||||
Ex: userInfo.Ex,
|
||||
CreateTime: uint32(userInfo.CreateTime.Unix()),
|
||||
AppMangerLevel: userInfo.AppMangerLevel,
|
||||
}
|
||||
m, err := utils.Pb2Map(userInfoPb)
|
||||
if err != nil {
|
||||
log.NewWarn("", utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
|
||||
log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllGroupMemberListToCache() error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
groupIDList, err := imdb.GetAllGroupIDList()
|
||||
if err != nil {
|
||||
log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error())
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
for _, groupID := range groupIDList {
|
||||
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error())
|
||||
continue
|
||||
}
|
||||
if len(groupMemberIDList) > 0 {
|
||||
if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil {
|
||||
log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllFriendToCache(userList []db.User) error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
for _, user := range userList {
|
||||
friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID)
|
||||
if err != nil {
|
||||
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
|
||||
continue
|
||||
}
|
||||
if len(friendIDList) > 0 {
|
||||
if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil {
|
||||
log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllBlackListToCache(userList []db.User) error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
for _, user := range userList {
|
||||
blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID)
|
||||
if err != nil {
|
||||
log.NewWarn("", utils.GetSelfFuncName(), err.Error())
|
||||
continue
|
||||
}
|
||||
if len(blackIDList) > 0 {
|
||||
if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil {
|
||||
log.NewWarn("0", utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetUserInfoFromCache(_ context.Context, req *pbCache.GetUserInfoFromCacheReq) (resp *pbCache.GetUserInfoFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetUserInfoFromCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
for _, userID := range req.UserIDList {
|
||||
userInfo, err := db.DB.GetUserInfoFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get userInfo from cache failed", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.UserInfoList = append(resp.UserInfoList, userInfo)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) UpdateUserInfoToCache(_ context.Context, req *pbCache.UpdateUserInfoToCacheReq) (resp *pbCache.UpdateUserInfoToCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.UpdateUserInfoToCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
for _, userInfo := range req.UserInfoList {
|
||||
m, err := utils.Pb2Map(userInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), *userInfo)
|
||||
}
|
||||
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
friendIDList, err := db.DB.GetFriendIDListFromCache(req.UserID)
|
||||
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
@@ -259,36 +91,24 @@ func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.G
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddFriendToCache(_ context.Context, req *pbCache.AddFriendToCacheReq) (resp *pbCache.AddFriendToCacheResp, err error) {
|
||||
// this is for dtm call
|
||||
func (s *cacheServer) DelFriendIDListFromCache(_ context.Context, req *pbCache.DelFriendIDListFromCacheReq) (resp *pbCache.DelFriendIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddFriendToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddFriendToCache(req.UserID, req.FriendID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp = &pbCache.DelFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := rocksCache.DelFriendIDListFromCache(req.UserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) ReduceFriendFromCache(_ context.Context, req *pbCache.ReduceFriendFromCacheReq) (resp *pbCache.ReduceFriendFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceFriendFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.ReduceFriendToCache(req.UserID, req.FriendID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
blackUserIDList, err := db.DB.GetBlackListFromCache(req.UserID)
|
||||
blackUserIDList, err := rocksCache.GetBlackListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
@@ -301,29 +121,16 @@ func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.Ge
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddBlackUserToCache(_ context.Context, req *pbCache.AddBlackUserToCacheReq) (resp *pbCache.AddBlackUserToCacheResp, err error) {
|
||||
func (s *cacheServer) DelBlackIDListFromCache(_ context.Context, req *pbCache.DelBlackIDListFromCacheReq) (resp *pbCache.DelBlackIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddBlackUserToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddBlackUserToCache(req.UserID, req.BlackUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
resp = &pbCache.DelBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := rocksCache.DelBlackIDListFromCache(req.UserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) ReduceBlackUserFromCache(_ context.Context, req *pbCache.ReduceBlackUserFromCacheReq) (resp *pbCache.ReduceBlackUserFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceBlackUserFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.ReduceBlackUserFromCache(req.UserID, req.BlackUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -332,7 +139,7 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa
|
||||
resp = &pbCache.GetGroupMemberIDListFromCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
userIDList, err := db.DB.GetGroupMemberIDListFromCache(req.GroupID)
|
||||
userIDList, err := rocksCache.GetGroupMemberIDListFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListFromCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
@@ -344,28 +151,15 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddGroupMemberToCache(_ context.Context, req *pbCache.AddGroupMemberToCacheReq) (resp *pbCache.AddGroupMemberToCacheResp, err error) {
|
||||
func (s *cacheServer) DelGroupMemberIDListFromCache(_ context.Context, req *pbCache.DelGroupMemberIDListFromCacheReq) (resp *pbCache.DelGroupMemberIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddGroupMemberToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddGroupMemberToCache(req.GroupID, req.UserIDList...); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddGroupMemberToCache failed", err.Error())
|
||||
resp = &pbCache.DelGroupMemberIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := rocksCache.DelGroupMemberIDListFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.GroupID, err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) ReduceGroupMemberFromCache(_ context.Context, req *pbCache.ReduceGroupMemberFromCacheReq) (resp *pbCache.ReduceGroupMemberFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceGroupMemberFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.ReduceGroupMemberFromCache(req.GroupID, req.UserIDList...); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ReduceGroupMemberFromCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
@@ -95,10 +96,10 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
err := imdb.InsertInToUserBlackList(black)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
reqAddBlackUserToCache := &pbCache.AddBlackUserToCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -106,15 +107,16 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddBlackUserToCache(context.Background(), reqAddBlackUserToCache)
|
||||
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc call failed ", err.Error())
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -208,6 +210,51 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
resp.CommonResp.ErrMsg = errMsg
|
||||
resp.CommonResp.ErrCode = 500
|
||||
return &resp, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: req.FromUserID, OperationID: req.OperationID})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
|
||||
resp.CommonResp.ErrCode = 500
|
||||
resp.CommonResp.ErrMsg = err.Error()
|
||||
return &resp, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
resp.CommonResp.ErrCode = 500
|
||||
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
|
||||
return &resp, nil
|
||||
}
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(req.FromUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.FromUserID)
|
||||
}
|
||||
|
||||
for _, userID := range req.FriendUserIDList {
|
||||
cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: userID, OperationID: req.OperationID})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
|
||||
}
|
||||
if cacheResp != nil && cacheResp.CommonResp != nil {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
resp.CommonResp.ErrCode = 500
|
||||
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
|
||||
return &resp, nil
|
||||
}
|
||||
}
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(userID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
|
||||
}
|
||||
}
|
||||
|
||||
resp.CommonResp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp.String())
|
||||
return &resp, nil
|
||||
@@ -267,7 +314,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
// cache rpc
|
||||
addFriendToCacheReq := &pbCache.AddFriendToCacheReq{OperationID: req.CommID.OperationID}
|
||||
delFriendIDListFromCacheReq := &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -275,29 +322,32 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
addFriendToCacheReq.UserID = req.CommID.ToUserID
|
||||
addFriendToCacheReq.FriendID = req.CommID.FromUserID
|
||||
respPb, err := client.AddFriendToCache(context.Background(), addFriendToCacheReq)
|
||||
delFriendIDListFromCacheReq.UserID = req.CommID.ToUserID
|
||||
respPb, err := client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
addFriendToCacheReq.UserID = req.CommID.FromUserID
|
||||
addFriendToCacheReq.FriendID = req.CommID.ToUserID
|
||||
respPb, err = client.AddFriendToCache(context.Background(), addFriendToCacheReq)
|
||||
delFriendIDListFromCacheReq.UserID = req.CommID.FromUserID
|
||||
respPb, err = client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.ToUserID)
|
||||
}
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
|
||||
}
|
||||
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
}
|
||||
}
|
||||
@@ -327,7 +377,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
|
||||
reduceFriendFromCache := &pbCache.ReduceFriendFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID, FriendID: req.CommID.ToUserID}
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -335,15 +385,21 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
respPb, err := client.ReduceFriendFromCache(context.Background(), reduceFriendFromCache)
|
||||
respPb, err := client.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID})
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache rpc failed", err.Error())
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache rpc failed", err.Error())
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed")
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
|
||||
}
|
||||
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
|
||||
}
|
||||
chat.FriendDeletedNotification(req)
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -351,13 +407,12 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
|
||||
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
blackListInfo, err := imdb.GetBlackListByUserID(req.CommID.FromUserID)
|
||||
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
@@ -366,15 +421,14 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl
|
||||
var (
|
||||
userInfoList []*sdkws.PublicUserInfo
|
||||
)
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo sdkws.PublicUserInfo
|
||||
//Find black user information
|
||||
us, err := imdb.GetUserByUserID(blackUser.BlockUserID)
|
||||
for _, userID := range blackIDList {
|
||||
user, err := rocksCache.GetUserInfoFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), blackUser.BlockUserID)
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), userID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&blackUserInfo, us)
|
||||
var blackUserInfo sdkws.PublicUserInfo
|
||||
utils.CopyStructFields(&blackUserInfo, user)
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList})
|
||||
@@ -391,10 +445,15 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
||||
|
||||
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark, err.Error())
|
||||
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
|
||||
err = rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DelAllFriendInfoFromCache failed ", req.CommID.FromUserID, err.Error())
|
||||
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
chat.FriendRemarkSetNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -413,7 +472,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
|
||||
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ")
|
||||
reqReduceBlackUserFromCache := &pbCache.ReduceBlackUserFromCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -422,13 +481,13 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
|
||||
}
|
||||
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.ReduceBlackUserFromCache(context.Background(), reqReduceBlackUserFromCache)
|
||||
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc call failed ", err.Error())
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.CommonResp.String())
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
chat.BlackDeletedNotification(req)
|
||||
@@ -441,10 +500,13 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var isInBlacklist = false
|
||||
err := imdb.CheckBlack(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.IsInBlackListResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
|
||||
}
|
||||
var isInBlacklist bool
|
||||
if utils.IsContain(req.CommID.ToUserID, blackIDList) {
|
||||
isInBlacklist = true
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist})
|
||||
@@ -453,16 +515,18 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, req.String())
|
||||
var isFriend bool
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsFriendResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
_, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.IsFriendResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
|
||||
}
|
||||
var isFriend bool
|
||||
if utils.IsContain(req.CommID.ToUserID, friendIDList) {
|
||||
isFriend = true
|
||||
} else {
|
||||
isFriend = false
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, pbFriend.IsFriendResp{Response: isFriend})
|
||||
return &pbFriend.IsFriendResp{Response: isFriend}, nil
|
||||
@@ -474,16 +538,16 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
friends, err := imdb.GetFriendListByUserID(req.CommID.FromUserID)
|
||||
friendList, err := rocksCache.GetAllFriendsInfoFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed ", err.Error(), req.CommID.FromUserID)
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache failed", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var userInfoList []*sdkws.FriendInfo
|
||||
for _, friendUser := range friends {
|
||||
for _, friendUser := range friendList {
|
||||
friendUserInfo := sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
|
||||
cp.FriendDBCopyOpenIM(&friendUserInfo, &friendUser)
|
||||
cp.FriendDBCopyOpenIM(&friendUserInfo, friendUser)
|
||||
log.NewDebug(req.CommID.OperationID, "friends : ", friendUser, "openim friends: ", friendUserInfo)
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
}
|
||||
+309
-140
@@ -6,6 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
@@ -106,6 +107,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
utils.CopyStructFields(&groupInfo, req.GroupInfo)
|
||||
groupInfo.CreatorUserID = req.OpUserID
|
||||
groupInfo.GroupID = groupId
|
||||
|
||||
if groupInfo.NotificationUpdateTime.Unix() < 0 {
|
||||
groupInfo.NotificationUpdateTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err := imdb.InsertIntoGroup(groupInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
||||
@@ -122,7 +127,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
//to group member
|
||||
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
|
||||
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
if err != nil {
|
||||
@@ -143,6 +148,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
continue
|
||||
}
|
||||
groupMember.RoleLevel = user.RoleLevel
|
||||
groupMember.JoinSource = constant.JoinByInvitation
|
||||
groupMember.InviterUserID = req.OpUserID
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
if err != nil {
|
||||
@@ -159,7 +166,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return resp, nil
|
||||
}
|
||||
utils.CopyStructFields(resp.GroupInfo, group)
|
||||
resp.GroupInfo.MemberCount, err = imdb.GetGroupMemberNumByGroupID(groupId)
|
||||
memberCount, err := imdb.GetGroupMemberNumByGroupID(groupId)
|
||||
resp.GroupInfo.MemberCount = uint32(memberCount)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
@@ -181,29 +189,13 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
}
|
||||
}
|
||||
|
||||
if len(okUserIDList) != 0 {
|
||||
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
|
||||
UserIDList: okUserIDList,
|
||||
GroupID: groupId,
|
||||
OperationID: req.OperationID,
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
for _, userID := range okUserIDList {
|
||||
if err := rocksCache.DelJoinedGroupIDListFromCache(userID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), userID, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if len(okUserIDList) != 0 {
|
||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||
if req.GroupInfo.GroupType != constant.SuperGroup {
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
|
||||
@@ -227,29 +219,45 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
//group list
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(req.FromUserID)
|
||||
|
||||
joinedGroupList, err := rocksCache.GetJoinedGroupIDListFromCache(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetJoinedGroupIDListByUserID failed ", err.Error(), req.FromUserID)
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetJoinedGroupIDListFromCache failed", err.Error(), req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "joinedGroupList: ", joinedGroupList)
|
||||
var resp pbGroup.GetJoinedGroupListResp
|
||||
for _, v := range joinedGroupList {
|
||||
var groupNode open_im_sdk.GroupInfo
|
||||
num, err := imdb.GetGroupMemberNumByGroupID(v)
|
||||
owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v)
|
||||
group, err := imdb.GetGroupInfoByGroupID(v)
|
||||
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
||||
utils.CopyStructFields(&groupNode, group)
|
||||
groupNode.CreateTime = uint32(group.CreateTime.Unix())
|
||||
groupNode.MemberCount = uint32(num)
|
||||
groupNode.OwnerUserID = owner.UserID
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
} else {
|
||||
log.NewError(req.OperationID, "check nil ", num, owner, err, group)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), v)
|
||||
continue
|
||||
}
|
||||
owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err2.Error(), v)
|
||||
continue
|
||||
}
|
||||
group, err := rocksCache.GetGroupInfoFromCache(v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), v)
|
||||
continue
|
||||
}
|
||||
if group.Status == constant.GroupStatusDismissed {
|
||||
log.NewError(req.OperationID, "constant.GroupStatusDismissed ", group)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&groupNode, group)
|
||||
groupNode.CreateTime = uint32(group.CreateTime.Unix())
|
||||
groupNode.NotificationUpdateTime = uint32(group.NotificationUpdateTime.Unix())
|
||||
if group.NotificationUpdateTime.Unix() < 0 {
|
||||
groupNode.NotificationUpdateTime = 0
|
||||
}
|
||||
|
||||
groupNode.MemberCount = uint32(num)
|
||||
groupNode.OwnerUserID = owner.UserID
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
log.NewDebug(req.OperationID, "joinedGroup ", groupNode)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList rpc return ", resp.String())
|
||||
@@ -281,6 +289,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
var groupRequest db.GroupRequest
|
||||
groupRequest.UserID = v
|
||||
groupRequest.GroupID = req.GroupID
|
||||
groupRequest.JoinSource = constant.JoinByInvitation
|
||||
groupRequest.InviterUserID = req.OpUserID
|
||||
err = imdb.InsertIntoGroupRequest(groupRequest)
|
||||
if err != nil {
|
||||
var resultNode pbGroup.Id2Result
|
||||
@@ -334,6 +344,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
toInsertInfo.GroupID = req.GroupID
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
toInsertInfo.OperatorUserID = req.OpUserID
|
||||
toInsertInfo.InviterUserID = req.OpUserID
|
||||
toInsertInfo.JoinSource = constant.JoinByInvitation
|
||||
err = imdb.InsertIntoGroupMember(toInsertInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceURL)
|
||||
@@ -416,11 +428,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
|
||||
}
|
||||
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
|
||||
UserIDList: okUserIDList,
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
}
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -428,17 +436,30 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
for _, userID := range okUserIDList {
|
||||
err = rocksCache.DelJoinedGroupIDListFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
|
||||
}
|
||||
}
|
||||
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
|
||||
} else {
|
||||
go func() {
|
||||
@@ -455,7 +476,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String())
|
||||
var resp pbGroup.GetGroupAllMemberResp
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
//groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
@@ -463,18 +485,23 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
return &resp, nil
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
|
||||
memberList, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
//memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
|
||||
//if err != nil {
|
||||
// log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
|
||||
// resp.ErrCode = constant.ErrDB.ErrCode
|
||||
// resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
// return &resp, nil
|
||||
//}
|
||||
for _, v := range memberList {
|
||||
//log.Debug(req.OperationID, v)
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
||||
cp.GroupMemberDBCopyOpenIM(&node, v)
|
||||
//log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix())
|
||||
//log.Debug(req.OperationID, "cp value: ", node)
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
@@ -506,7 +533,6 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
||||
} else {
|
||||
resp.NextSeq = req.NextSeq + int32(len(memberList))
|
||||
}
|
||||
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
@@ -635,11 +661,6 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
}
|
||||
|
||||
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
|
||||
UserIDList: okUserIDList,
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -647,16 +668,33 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
for _, userID := range okUserIDList {
|
||||
err = rocksCache.DelJoinedGroupIDListFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
|
||||
}
|
||||
}
|
||||
if err = rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.MemberKickedNotification(req, okUserIDList)
|
||||
} else {
|
||||
go func() {
|
||||
@@ -666,6 +704,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
@@ -674,27 +713,45 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
||||
|
||||
var resp pbGroup.GetGroupMembersInfoResp
|
||||
resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
|
||||
|
||||
for _, v := range req.MemberList {
|
||||
var memberNode open_im_sdk.GroupMemberFullInfo
|
||||
memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v)
|
||||
memberNode.UserID = v
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v)
|
||||
continue
|
||||
} else {
|
||||
utils.CopyStructFields(&memberNode, memberInfo)
|
||||
memberNode.JoinTime = int32(memberInfo.JoinTime.Unix())
|
||||
//for _, v := range req.MemberList {
|
||||
// var memberNode open_im_sdk.GroupMemberFullInfo
|
||||
// memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v)
|
||||
// memberNode.UserID = v
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v)
|
||||
// continue
|
||||
// } else {
|
||||
// utils.CopyStructFields(&memberNode, memberInfo)
|
||||
// memberNode.JoinTime = int32(memberInfo.JoinTime.Unix())
|
||||
// resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
// }
|
||||
//}
|
||||
|
||||
groupMembers, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return &resp, nil
|
||||
}
|
||||
for _, member := range groupMembers {
|
||||
if utils.IsContain(member.UserID, req.MemberList) {
|
||||
var memberNode open_im_sdk.GroupMemberFullInfo
|
||||
utils.CopyStructFields(&memberNode, member)
|
||||
memberNode.JoinTime = int32(member.JoinTime.Unix())
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
}
|
||||
}
|
||||
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GetGroupApplicationList(_ context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
||||
log.NewInfo(req.OperationID, "GetGroupApplicationList args ", req.String())
|
||||
reply, err := imdb.GetGroupApplicationList(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.FromUserID)
|
||||
@@ -710,6 +767,10 @@ func (s *groupServer) GetGroupApplicationList(_ context.Context, req *pbGroup.Ge
|
||||
log.Error(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), v.GroupID)
|
||||
continue
|
||||
}
|
||||
if group.Status == constant.GroupStatusDismissed {
|
||||
log.Debug(req.OperationID, "group constant.GroupStatusDismissed ", group.GroupID)
|
||||
continue
|
||||
}
|
||||
user, err := imdb.GetUserByUserID(v.UserID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetUserByUserID failed ", err.Error(), v.UserID)
|
||||
@@ -730,16 +791,17 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
|
||||
groupsInfoList := make([]*open_im_sdk.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
//groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
var groupInfo open_im_sdk.GroupInfo
|
||||
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromMysql)
|
||||
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis)
|
||||
//groupInfo.NeedVerification
|
||||
|
||||
groupInfo.NeedVerification = groupInfoFromMysql.NeedVerification
|
||||
groupInfo.NeedVerification = groupInfoFromRedis.NeedVerification
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
|
||||
@@ -762,10 +824,14 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
}
|
||||
err := imdb.UpdateGroupRequest(groupRequest)
|
||||
if err != nil {
|
||||
//{openIM002 7836e478bc43ce1d3b8889cac983f59b 1 ok 0001-01-01 00:00:00 +0000 UTC openIM001 0001-01-01 00:00:00 +0000 UTC }
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), groupRequest)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
request, err := imdb.GetGroupRequestByGroupIDAndUserID(req.GroupID, req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.GroupID, req.FromUserID)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
if req.HandleResult == constant.GroupResponseAgree {
|
||||
user, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
@@ -780,7 +846,8 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
member.OperatorUserID = req.OpUserID
|
||||
member.FaceURL = user.FaceURL
|
||||
member.Nickname = user.Nickname
|
||||
|
||||
member.JoinSource = request.JoinSource
|
||||
member.InviterUserID = request.InviterUserID
|
||||
err = imdb.InsertIntoGroupMember(member)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member)
|
||||
@@ -823,23 +890,36 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
|
||||
}
|
||||
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{OperationID: req.OperationID, GroupID: req.GroupID, UserIDList: []string{req.FromUserID}}
|
||||
|
||||
etcdCacheConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
if etcdCacheConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
||||
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
group, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
|
||||
}
|
||||
if group != nil {
|
||||
if group.GroupType != constant.SuperGroup {
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chat.GroupApplicationAcceptedNotification(req)
|
||||
chat.MemberEnterNotification(req)
|
||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||
@@ -872,24 +952,19 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
|
||||
if groupInfo.NeedVerification == constant.Directly {
|
||||
us, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
//to group member
|
||||
groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID}
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
|
||||
UserIDList: []string{req.OpUserID},
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
us, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
//to group member
|
||||
groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID}
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
@@ -898,20 +973,39 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
//for _, userID := range okUserIDList {
|
||||
// err = rocksCache.DelJoinedGroupIDListFromCache(userID)
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
|
||||
// }
|
||||
//}
|
||||
err = rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
|
||||
err = rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
|
||||
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
||||
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
} else {
|
||||
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType)
|
||||
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType, "not support directly")
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
}
|
||||
}
|
||||
@@ -920,6 +1014,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
groupRequest.UserID = req.OpUserID
|
||||
groupRequest.ReqMsg = req.ReqMessage
|
||||
groupRequest.GroupID = req.GroupID
|
||||
groupRequest.JoinSource = req.JoinSource
|
||||
err = imdb.InsertIntoGroupRequest(groupRequest)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
|
||||
@@ -994,25 +1089,23 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
}
|
||||
}
|
||||
|
||||
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
|
||||
UserIDList: []string{req.OpUserID},
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
}
|
||||
etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConnCache == nil {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConnCache)
|
||||
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
@@ -1021,6 +1114,12 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
} else {
|
||||
chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID)
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
if err := rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID)
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}})
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1092,7 +1191,24 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
}
|
||||
|
||||
if req.GroupInfoForSet.LookMemberInfo != nil {
|
||||
changedType = changedType | (1 << 5)
|
||||
m := make(map[string]interface{})
|
||||
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
}
|
||||
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
||||
changedType = changedType | (1 << 6)
|
||||
m := make(map[string]interface{})
|
||||
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
}
|
||||
//
|
||||
//if req.RoleLevel != nil {
|
||||
//
|
||||
@@ -1100,11 +1216,20 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
//only administrators can set group information
|
||||
var groupInfo db.Group
|
||||
utils.CopyStructFields(&groupInfo, req.GroupInfoForSet)
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
groupInfo.NotificationUserID = req.OpUserID
|
||||
groupInfo.NotificationUpdateTime = time.Now()
|
||||
}
|
||||
err = imdb.SetGroupInfo(groupInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
|
||||
if changedType != 0 {
|
||||
chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
|
||||
@@ -1187,8 +1312,10 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
||||
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
|
||||
}
|
||||
chat.GroupOwnerTransferredNotification(req)
|
||||
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
|
||||
}
|
||||
@@ -1379,7 +1506,7 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
log.NewInfo(req.OperationID, groupMembersCount)
|
||||
resp.MemberNums = groupMembersCount
|
||||
resp.MemberNums = int32(groupMembersCount)
|
||||
for _, groupMember := range groupMembers {
|
||||
resp.Members = append(resp.Members, &open_im_sdk.GroupMemberFullInfo{
|
||||
GroupID: req.GroupId,
|
||||
@@ -1443,27 +1570,28 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
|
||||
}
|
||||
}
|
||||
|
||||
reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
|
||||
UserIDList: resp.Success,
|
||||
GroupID: req.GroupId,
|
||||
OperationID: req.OperationID,
|
||||
}
|
||||
etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConnCache == nil {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return resp, http.WrapError(constant.ErrInternal)
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConnCache)
|
||||
cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupId,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId)
|
||||
}
|
||||
|
||||
chat.MemberKickedNotification(reqKick, resp.Success)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
@@ -1504,27 +1632,28 @@ func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGrou
|
||||
}
|
||||
}
|
||||
|
||||
addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{
|
||||
UserIDList: resp.Success,
|
||||
GroupID: req.GroupId,
|
||||
OperationID: req.OperationId,
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationId)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationId + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationId, errMsg)
|
||||
return resp, http.WrapError(constant.ErrInternal)
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupId,
|
||||
OperationID: req.OperationId,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationId, "AddGroupMemberToCache rpc call failed ", err.Error())
|
||||
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationId, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String())
|
||||
log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil {
|
||||
log.NewError(req.OperationId, utils.GetSelfFuncName(), err.Error(), req.GroupId)
|
||||
}
|
||||
|
||||
chat.MemberInvitedNotification(req.OperationId, req.GroupId, req.OpUserId, "admin add you to group", resp.Success)
|
||||
return resp, nil
|
||||
@@ -1627,6 +1756,28 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
|
||||
}
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
||||
GroupID: req.GroupID,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
@@ -1672,6 +1823,9 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
|
||||
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
|
||||
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1713,6 +1867,9 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
|
||||
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
|
||||
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1752,6 +1909,9 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
||||
log.Error(req.OperationID, "OperateGroupStatus failed ", err.Error(), req.GroupID, constant.GroupStatusMuted)
|
||||
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1791,6 +1951,9 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), req.GroupID)
|
||||
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1824,6 +1987,9 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -1856,13 +2022,16 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
||||
}
|
||||
if req.RoleLevel != nil {
|
||||
switch req.RoleLevel.Value {
|
||||
case constant.GroupOrdinaryUsers:
|
||||
//chat.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToOrdinaryUserNotification)
|
||||
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToOrdinaryUserNotification)
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
case constant.GroupAdmin, constant.GroupOwner:
|
||||
//chat.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToAdminNotification)
|
||||
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToAdminNotification)
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -10,14 +10,19 @@ import (
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetJoinedSuperGroupList(ctx context.Context, req *pbGroup.GetJoinedSuperGroupListReq) (*pbGroup.GetJoinedSuperGroupListResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbGroup.GetJoinedSuperGroupListResp{CommonResp: &pbGroup.CommonResp{}}
|
||||
userToSuperGroup, err := db.DB.GetSuperGroupByUserID(req.UserID)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed ", err.Error(), req.UserID)
|
||||
return resp, nil
|
||||
}
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed", err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetSuperGroupByUserID failed ", err.Error(), req.UserID)
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
http2 "net/http"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
@@ -15,7 +15,7 @@ func (rpc *rpcChat) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbCha
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID)
|
||||
err := db.DB.CleanUpOneUserAllMsgFromRedis(req.UserID, req.OperationID)
|
||||
@@ -36,3 +36,28 @@ func (rpc *rpcChat) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbCha
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) SetMsgMinSeq(_ context.Context, req *pbChat.SetMsgMinSeqReq) (*pbChat.SetMsgMinSeqResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if req.GroupID == "" {
|
||||
err := db.DB.SetUserMinSeq(req.UserID, req.MinSeq)
|
||||
if err != nil {
|
||||
errMsg := "SetUserMinSeq failed " + err.Error() + req.OperationID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
err := db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, req.MinSeq)
|
||||
if err != nil {
|
||||
errMsg := "SetGroupUserMinSeq failed " + err.Error() + req.OperationID + req.GroupID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
|
||||
}
|
||||
err = utils2.GroupDBCopyOpenIM(groupInfo, group)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupMemberNumByGroupID failed")
|
||||
log.NewWarn("", "GroupDBCopyOpenIM failed ", groupID, err.Error())
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -183,7 +184,16 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
n.SessionType = constant.GroupChatType
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
||||
}
|
||||
switch group.GroupType {
|
||||
case constant.NormalGroup:
|
||||
n.SessionType = constant.GroupChatType
|
||||
default:
|
||||
n.SessionType = constant.SuperGroupChatType
|
||||
}
|
||||
} else {
|
||||
n.RecvID = recvUserID
|
||||
n.SessionType = constant.SingleChatType
|
||||
@@ -223,6 +233,9 @@ func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberL
|
||||
continue
|
||||
}
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
if len(GroupCreatedTips.MemberList) == constant.MaxNotificationNum {
|
||||
break
|
||||
}
|
||||
}
|
||||
groupNotification(constant.GroupCreatedNotification, &GroupCreatedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
@@ -527,7 +540,6 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
|
||||
}
|
||||
MemberInvitedTips.InvitedUserList = append(MemberInvitedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
|
||||
groupNotification(constant.MemberInvitedNotification, &MemberInvitedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
|
||||
@@ -13,34 +14,33 @@ func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *open_im_sdk.GetMaxAnd
|
||||
log.NewInfo(in.OperationID, "rpc getMaxAndMinSeq is arriving", in.String())
|
||||
resp := new(open_im_sdk.GetMaxAndMinSeqResp)
|
||||
m := make(map[string]*open_im_sdk.MaxAndMinSeq)
|
||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
//minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
if err1 == nil {
|
||||
resp.MaxSeq = uint32(maxSeq)
|
||||
for _, v := range in.GroupIDList {
|
||||
x := new(open_im_sdk.MaxAndMinSeq)
|
||||
maxSeq, _ := commonDB.DB.GetUserMaxSeq(v)
|
||||
x.MaxSeq = uint32(maxSeq)
|
||||
m[v] = x
|
||||
var maxSeq, minSeq uint64
|
||||
var err1, err2 error
|
||||
maxSeq, err1 = commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
minSeq, err2 = commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
if (err1 != nil && err1 != go_redis.Nil) || (err2 != nil && err2 != go_redis.Nil) {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String())
|
||||
if err1 != nil {
|
||||
log.NewError(in.OperationID, utils.GetSelfFuncName(), err1.Error())
|
||||
}
|
||||
if err2 != nil {
|
||||
log.NewError(in.OperationID, utils.GetSelfFuncName(), err2.Error())
|
||||
}
|
||||
resp.GroupMaxAndMinSeq = m
|
||||
} else if err1 == go_redis.Nil {
|
||||
resp.MaxSeq = 0
|
||||
} else {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
|
||||
resp.ErrCode = 200
|
||||
resp.ErrMsg = "redis get err"
|
||||
return resp, nil
|
||||
}
|
||||
//if err2 == nil {
|
||||
// resp.MinSeq = uint32(minSeq)
|
||||
//} else if err2 == redis.ErrNil {
|
||||
// resp.MinSeq = 0
|
||||
//} else {
|
||||
// log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
|
||||
// resp.ErrCode = 201
|
||||
// resp.ErrMsg = "redis get err"
|
||||
//}
|
||||
resp.MaxSeq = uint32(maxSeq)
|
||||
resp.MinSeq = uint32(minSeq)
|
||||
for _, groupID := range in.GroupIDList {
|
||||
x := new(open_im_sdk.MaxAndMinSeq)
|
||||
maxSeq, _ := commonDB.DB.GetGroupMaxSeq(groupID)
|
||||
minSeq, _ := commonDB.DB.GetGroupUserMinSeq(groupID, in.UserID)
|
||||
x.MaxSeq = uint32(maxSeq)
|
||||
x.MinSeq = uint32(minSeq)
|
||||
m[groupID] = x
|
||||
}
|
||||
resp.GroupMaxAndMinSeq = m
|
||||
return resp, nil
|
||||
}
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
@@ -36,7 +36,7 @@ func NewRpcChatServer(port int) *rpcChat {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rc := rpcChat{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMsgName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (rpc *rpcChat) Run() {
|
||||
defer srv.GracefulStop()
|
||||
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
pbChat.RegisterChatServer(srv, rpc)
|
||||
msg.RegisterMsgServer(srv, rpc)
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
rpcRegisterIP, err = utils.GetLocalIP()
|
||||
if err != nil {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
cacheRpc "Open_IM/pkg/proto/cache"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -331,8 +331,8 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
}
|
||||
}
|
||||
log.Debug(pb.OperationID, "send msg cost time22 ", db.GetCurrentTimestampByMill()-newTime, pb.MsgData.ClientMsgID, "uidList : ", len(addUidList))
|
||||
wg.Add(1)
|
||||
go rpc.sendMsgToGroup(addUidList, *pb, constant.OnlineStatus, &sendTag, &wg)
|
||||
//wg.Add(1)
|
||||
//go rpc.sendMsgToGroup(addUidList, *pb, constant.OnlineStatus, &sendTag, &wg)
|
||||
wg.Wait()
|
||||
newTime = db.GetCurrentTimestampByMill()
|
||||
// callback
|
||||
@@ -830,14 +830,14 @@ func Notification(n *NotificationMsg) {
|
||||
offlineInfo.Ex = ex
|
||||
msg.OfflinePushInfo = &offlineInfo
|
||||
req.MsgData = &msg
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, req.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||
@@ -853,9 +853,9 @@ func getOnlineAndOfflineUserIDList(memberList []string, m map[string][]string, o
|
||||
req.OperationID = operationID
|
||||
req.OpUserID = config.Config.Manager.AppManagerUid[0]
|
||||
flag := false
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
client := pbRelay.NewRelayClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -33,14 +33,14 @@ func TagSendMessage(operationID string, user *db.User, recvID, content string, s
|
||||
msgData.SenderPlatformID = senderPlatformID
|
||||
req.MsgData = &msgData
|
||||
req.OperationID = operationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, operationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, operationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return
|
||||
}
|
||||
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
respPb, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
@@ -112,8 +113,12 @@ func (s *organizationServer) CreateDepartment(ctx context.Context, req *rpc.Crea
|
||||
resp := &rpc.CreateDepartmentResp{DepartmentInfo: &open_im_sdk.Department{}}
|
||||
utils.CopyStructFields(resp.DepartmentInfo, createdDepartment)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
@@ -169,11 +174,15 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
|
||||
utils.CopyStructFields(&department, req.DepartmentInfo)
|
||||
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
|
||||
if err := imdb.UpdateDepartment(&department, nil); err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, department)
|
||||
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
resp := &rpc.UpdateDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
@@ -182,12 +191,24 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda
|
||||
|
||||
func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
err, departmentList := imdb.GetSubDepartmentList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
var departmentList []db.Department
|
||||
var err error
|
||||
if req.DepartmentID == "-1" {
|
||||
departmentList, err = rocksCache.GetAllDepartmentsFromCache()
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
} else {
|
||||
departmentList, err = imdb.GetSubDepartmentList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug(req.OperationID, "GetSubDepartmentList ", req.DepartmentID, departmentList)
|
||||
resp := &rpc.GetSubDepartmentResp{}
|
||||
for _, v := range departmentList {
|
||||
@@ -224,6 +245,12 @@ func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.Dele
|
||||
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "DeleteDepartment ", req.DepartmentID)
|
||||
|
||||
if err := rocksCache.DelAllDepartmentsFromCache(); err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
resp := &rpc.DeleteDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
@@ -273,7 +300,7 @@ func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rp
|
||||
log.Debug(req.OperationID, "CreateOrganizationUser ", organizationUser)
|
||||
resp := &rpc.CreateOrganizationUserResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
//chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -353,7 +380,9 @@ func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rp
|
||||
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "UpdateOrganizationUser ", departmentMember)
|
||||
|
||||
if err := rocksCache.DelAllDepartmentMembersFromCache(); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
resp := &rpc.CreateDepartmentMemberResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
@@ -477,11 +506,22 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp
|
||||
|
||||
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
err, departmentMemberList := imdb.GetDepartmentMemberList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
var departmentMemberList []db.DepartmentMember
|
||||
var err error
|
||||
if req.DepartmentID == "-1" {
|
||||
departmentMemberList, err = rocksCache.GetAllDepartmentMembersFromCache()
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
} else {
|
||||
departmentMemberList, err = imdb.GetDepartmentMemberList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug(req.OperationID, "GetDepartmentMemberList ", departmentMemberList)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/db/rocks_cache"
|
||||
errors "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
@@ -112,7 +113,7 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo sdkws.UserInfo
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
user, err := rocksCache.GetUserInfoFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), userID)
|
||||
continue
|
||||
@@ -151,7 +152,7 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
|
||||
continue
|
||||
}
|
||||
resp.Success = append(resp.Success, v.ConversationID)
|
||||
// if is set private chat operation,then peer user need to sync and set tips\
|
||||
// if is set private msg operation,then peer user need to sync and set tips\
|
||||
if v.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
|
||||
if err := syncPeerUserConversation(v, req.OperationID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
@@ -378,6 +379,13 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
oldNickname := ""
|
||||
if req.UserInfo.Nickname != "" {
|
||||
u, err := imdb.GetUserByUserID(req.UserInfo.UserID)
|
||||
if err == nil {
|
||||
oldNickname = u.Nickname
|
||||
}
|
||||
}
|
||||
var user db.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.Birth != 0 {
|
||||
@@ -401,21 +409,27 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID},
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
rpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
for _, v := range RpcResp.FriendInfoList {
|
||||
for _, v := range rpcResp.FriendInfoList {
|
||||
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
}
|
||||
|
||||
if err := rocksCache.DelUserInfoFromCache(user.UserID); err != nil {
|
||||
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID)
|
||||
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID)
|
||||
if req.UserInfo.FaceURL != "" {
|
||||
go s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID)
|
||||
}
|
||||
if req.UserInfo.Nickname != "" {
|
||||
go s.SyncJoinedGroupMemberNickname(req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, req.OperationID, req.OpUserID)
|
||||
}
|
||||
//updateUserInfoToCacheReq := &cache.UpdateUserInfoToCacheReq{
|
||||
// OperationID: req.OperationID,
|
||||
// UserInfoList: []*sdkws.UserInfo{req.UserInfo},
|
||||
@@ -455,16 +469,51 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserID, req.UserID)
|
||||
return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, operationID string, opUserID string) {
|
||||
joinedGroupIDList, err := rocksCache.GetJoinedGroupIDListFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error())
|
||||
return
|
||||
}
|
||||
for _, groupID := range joinedGroupIDList {
|
||||
groupMemberInfo := db.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL}
|
||||
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
|
||||
continue
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(groupID); err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(operationID, opUserID, groupID, userID)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) SyncJoinedGroupMemberNickname(userID string, newNickname, oldNickname string, operationID string, opUserID string) {
|
||||
joinedGroupIDList, err := imdb.GetJoinedGroupIDListByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error())
|
||||
return
|
||||
}
|
||||
for _, v := range joinedGroupIDList {
|
||||
groupMemberInfo := db.GroupMember{UserID: userID, GroupID: v, FaceURL: faceURL}
|
||||
imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
|
||||
member, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(v, userID)
|
||||
if err != nil {
|
||||
log.NewWarn(operationID, "GetGroupMemberInfoByGroupIDAndUserID failed ", err.Error(), v, userID)
|
||||
continue
|
||||
}
|
||||
if member.Nickname == oldNickname {
|
||||
groupMemberInfo := db.GroupMember{UserID: userID, GroupID: v, Nickname: newNickname}
|
||||
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo)
|
||||
continue
|
||||
}
|
||||
if err := rocksCache.DelAllGroupMembersInfoFromCache(v); err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), v)
|
||||
continue
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ type GetBlackListResp struct {
|
||||
|
||||
type SetFriendRemarkReq struct {
|
||||
ParamsCommFriend
|
||||
Remark string `json:"remark" binding:"required"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
type SetFriendRemarkResp struct {
|
||||
CommResp
|
||||
|
||||
@@ -161,10 +161,13 @@ type ApplicationGroupResponseResp struct {
|
||||
}
|
||||
|
||||
type JoinGroupReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
JoinSource int32 `json:"joinSource"`
|
||||
InviterUserID string `json:"inviterUserID"`
|
||||
}
|
||||
|
||||
type JoinGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
@@ -178,14 +181,16 @@ type QuitGroupResp struct {
|
||||
}
|
||||
|
||||
type SetGroupInfoReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
Ex string `json:"ex"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NeedVerification *int32 `json:"needVerification" binding "oneof=0 1 2"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
Ex string `json:"ex"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NeedVerification *int32 `json:"needVerification" `
|
||||
LookMemberInfo *int32 `json:"lookMemberInfo"`
|
||||
ApplyMemberFriend *int32 `json:"applyMemberFriend"`
|
||||
}
|
||||
|
||||
type SetGroupInfoResp struct {
|
||||
|
||||
@@ -18,3 +18,34 @@ type CleanUpMsgReq struct {
|
||||
type CleanUpMsgResp struct {
|
||||
CommResp
|
||||
}
|
||||
type DelSuperGroupMsgReq struct {
|
||||
UserID string `json:"userID,omitempty" binding:"required"`
|
||||
GroupID string `json:"groupID,omitempty" binding:"required"`
|
||||
SeqList []uint32 `json:"seqList,omitempty"`
|
||||
IsAllDelete bool `json:"isAllDelete"`
|
||||
OperationID string `json:"operationID,omitempty" binding:"required"`
|
||||
}
|
||||
|
||||
type DelSuperGroupMsgResp struct {
|
||||
CommResp
|
||||
}
|
||||
type MsgDeleteNotificationElem struct {
|
||||
GroupID string `json:"groupID"`
|
||||
IsAllDelete bool `json:"isAllDelete"`
|
||||
SeqList []uint32 `json:"seqList"`
|
||||
}
|
||||
|
||||
//UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"`
|
||||
// GroupID string `protobuf:"bytes,2,opt,name=groupID" json:"groupID,omitempty"`
|
||||
// MinSeq uint32 `protobuf:"varint,3,opt,name=minSeq" json:"minSeq,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=operationID" json:"operationID,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,5,opt,name=opUserID" json:"opUserID,omitempty"`
|
||||
type SetMsgMinSeqReq struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
GroupID string `json:"groupID"`
|
||||
MinSeq uint32 `json:"minSeq" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type SetMsgMinSeqResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ type ApiUserInfo struct {
|
||||
|
||||
type GroupAddMemberInfo struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
RoleLevel int32 `json:"roleLevel" binding:"required"`
|
||||
RoleLevel int32 `json:"roleLevel" binding:"required,oneof= 1 3"`
|
||||
}
|
||||
|
||||
func SetErrCodeMsg(c *gin.Context, status int) *CommResp {
|
||||
|
||||
+25
-18
@@ -74,6 +74,10 @@ type config struct {
|
||||
} `yaml:"minio"`
|
||||
}
|
||||
|
||||
Dtm struct {
|
||||
ServerURL string `json:"serverURL"`
|
||||
}
|
||||
|
||||
Mysql struct {
|
||||
DBAddress []string `yaml:"dbMysqlAddress"`
|
||||
DBUserName string `yaml:"dbMysqlUserName"`
|
||||
@@ -102,6 +106,7 @@ type config struct {
|
||||
DBMaxIdle int `yaml:"dbMaxIdle"`
|
||||
DBMaxActive int `yaml:"dbMaxActive"`
|
||||
DBIdleTimeout int `yaml:"dbIdleTimeout"`
|
||||
DBUserName string `yaml:"dbUserName"`
|
||||
DBPassWord string `yaml:"dbPassWord"`
|
||||
EnableCluster bool `yaml:"enableCluster"`
|
||||
}
|
||||
@@ -122,21 +127,22 @@ type config struct {
|
||||
OpenImCachePort []int `yaml:"openImCachePort"`
|
||||
}
|
||||
RpcRegisterName struct {
|
||||
OpenImStatisticsName string `yaml:"openImStatisticsName"`
|
||||
OpenImUserName string `yaml:"openImUserName"`
|
||||
OpenImFriendName string `yaml:"openImFriendName"`
|
||||
OpenImOfflineMessageName string `yaml:"openImOfflineMessageName"`
|
||||
OpenImPushName string `yaml:"openImPushName"`
|
||||
OpenImOnlineMessageRelayName string `yaml:"openImOnlineMessageRelayName"`
|
||||
OpenImGroupName string `yaml:"openImGroupName"`
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
OpenImOrganizationName string `yaml:"openImOrganizationName"`
|
||||
OpenImConversationName string `yaml:"openImConversationName"`
|
||||
OpenImCacheName string `yaml:"openImCacheName"`
|
||||
OpenImRealTimeCommName string `yaml:"openImRealTimeCommName"`
|
||||
OpenImStatisticsName string `yaml:"openImStatisticsName"`
|
||||
OpenImUserName string `yaml:"openImUserName"`
|
||||
OpenImFriendName string `yaml:"openImFriendName"`
|
||||
// OpenImOfflineMessageName string `yaml:"openImOfflineMessageName"`
|
||||
OpenImMsgName string `yaml:"openImMsgName"`
|
||||
OpenImPushName string `yaml:"openImPushName"`
|
||||
OpenImRelayName string `yaml:"openImRelayName"`
|
||||
OpenImGroupName string `yaml:"openImGroupName"`
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
OpenImOrganizationName string `yaml:"openImOrganizationName"`
|
||||
OpenImConversationName string `yaml:"openImConversationName"`
|
||||
OpenImCacheName string `yaml:"openImCacheName"`
|
||||
OpenImRealTimeCommName string `yaml:"openImRealTimeCommName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
@@ -464,9 +470,10 @@ type config struct {
|
||||
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
|
||||
Enable bool `yaml:"enable"`
|
||||
}
|
||||
SuperCode string `yaml:"superCode"`
|
||||
CodeTTL int `yaml:"codeTTL"`
|
||||
Mail struct {
|
||||
SuperCode string `yaml:"superCode"`
|
||||
CodeTTL int `yaml:"codeTTL"`
|
||||
UseSuperCode bool `yaml:"useSuperCode"`
|
||||
Mail struct {
|
||||
Title string `yaml:"title"`
|
||||
SenderMail string `yaml:"senderMail"`
|
||||
SenderAuthorizationCode string `yaml:"senderAuthorizationCode"`
|
||||
|
||||
@@ -58,6 +58,7 @@ const (
|
||||
FriendRemarkSetNotification = 1206 //set_friend_remark?
|
||||
BlackAddedNotification = 1207 //add_black
|
||||
BlackDeletedNotification = 1208 //remove_black
|
||||
MsgDeleteNotification = 1209
|
||||
|
||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||
|
||||
@@ -161,9 +162,9 @@ const (
|
||||
GroupStatusMuted = 3
|
||||
|
||||
//GroupType
|
||||
NormalGroup = 0
|
||||
SuperGroup = 1
|
||||
DepartmentGroup = 2
|
||||
NormalGroup = 0
|
||||
SuperGroup = 1
|
||||
WorkingGroup = 2
|
||||
|
||||
GroupBaned = 3
|
||||
GroupBanPrivateChat = 4
|
||||
@@ -171,6 +172,10 @@ const (
|
||||
//UserJoinGroupSource
|
||||
JoinByAdmin = 1
|
||||
|
||||
JoinByInvitation = 2
|
||||
JoinBySearch = 3
|
||||
JoinByQRCode = 4
|
||||
|
||||
//Minio
|
||||
MinioDurationTimes = 3600
|
||||
|
||||
@@ -298,3 +303,5 @@ const BigVersion = "v2"
|
||||
const LogFileName = "OpenIM.log"
|
||||
|
||||
const StatisticsTimeInterval = 60
|
||||
|
||||
const MaxNotificationNum = 100
|
||||
|
||||
+61
-124
@@ -4,12 +4,11 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
log2 "Open_IM/pkg/common/log"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
accountTempCode = "ACCOUNT_TEMP_CODE"
|
||||
resetPwdTempCode = "RESET_PWD_TEMP_CODE"
|
||||
@@ -27,26 +27,17 @@ const (
|
||||
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
||||
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
|
||||
getuiToken = "GETUI_TOKEN"
|
||||
userInfoCache = "USER_INFO_CACHE:"
|
||||
friendRelationCache = "FRIEND_RELATION_CACHE:"
|
||||
blackListCache = "BLACK_LIST_CACHE:"
|
||||
groupCache = "GROUP_CACHE:"
|
||||
messageCache = "MESSAGE_CACHE:"
|
||||
SignalCache = "SIGNAL_CACHE:"
|
||||
SignalListCache = "SIGNAL_LIST_CACHE:"
|
||||
GlobalMsgRecvOpt = "GLOBAL_MSG_RECV_OPT"
|
||||
groupUserMinSeq = "GROUP_USER_MIN_SEQ:"
|
||||
groupMaxSeq = "GROUP_MAX_SEQ"
|
||||
)
|
||||
|
||||
|
||||
//func (d * DataBases)pubMessage(channel, msg string) {
|
||||
// d.rdb.Publish(context.Background(),channel,msg)
|
||||
//}
|
||||
//func (d * DataBases)pubMessage(channel, msg string) {
|
||||
// d.rdb.Publish(context.Background(),channel,msg)
|
||||
//}
|
||||
func (d *DataBases) JudgeAccountEXISTS(account string) (bool, error) {
|
||||
key := accountTempCode + account
|
||||
n, err := d.rdb.Exists(context.Background(), key).Result()
|
||||
n, err := d.RDB.Exists(context.Background(), key).Result()
|
||||
if n > 0 {
|
||||
return true, err
|
||||
} else {
|
||||
@@ -55,57 +46,84 @@ func (d *DataBases) JudgeAccountEXISTS(account string) (bool, error) {
|
||||
}
|
||||
func (d *DataBases) SetAccountCode(account string, code, ttl int) (err error) {
|
||||
key := accountTempCode + account
|
||||
return d.rdb.Set(context.Background(), key, code, time.Duration(ttl)*time.Second).Err()
|
||||
return d.RDB.Set(context.Background(), key, code, time.Duration(ttl)*time.Second).Err()
|
||||
}
|
||||
func (d *DataBases) GetAccountCode(account string) (string, error) {
|
||||
key := accountTempCode + account
|
||||
return d.rdb.Get(context.Background(), key).Result()
|
||||
return d.RDB.Get(context.Background(), key).Result()
|
||||
}
|
||||
|
||||
//Perform seq auto-increment operation of user messages
|
||||
func (d *DataBases) IncrUserSeq(uid string) (uint64, error) {
|
||||
key := userIncrSeq + uid
|
||||
seq, err := d.rdb.Incr(context.Background(), key).Result()
|
||||
seq, err := d.RDB.Incr(context.Background(), key).Result()
|
||||
return uint64(seq), err
|
||||
}
|
||||
|
||||
//Get the largest Seq
|
||||
func (d *DataBases) GetUserMaxSeq(uid string) (uint64, error) {
|
||||
key := userIncrSeq + uid
|
||||
seq, err := d.rdb.Get(context.Background(), key).Result()
|
||||
seq, err := d.RDB.Get(context.Background(), key).Result()
|
||||
return uint64(utils.StringToInt(seq)), err
|
||||
}
|
||||
|
||||
//set the largest Seq
|
||||
func (d *DataBases) SetUserMaxSeq(uid string, maxSeq uint64) error {
|
||||
key := userIncrSeq + uid
|
||||
return d.rdb.Set(context.Background(), key, maxSeq, 0).Err()
|
||||
return d.RDB.Set(context.Background(), key, maxSeq, 0).Err()
|
||||
}
|
||||
|
||||
//Set the user's minimum seq
|
||||
func (d *DataBases) SetUserMinSeq(uid string, minSeq uint32) (err error) {
|
||||
key := userMinSeq + uid
|
||||
return d.rdb.Set(context.Background(), key, minSeq, 0).Err()
|
||||
return d.RDB.Set(context.Background(), key, minSeq, 0).Err()
|
||||
}
|
||||
|
||||
//Get the smallest Seq
|
||||
func (d *DataBases) GetUserMinSeq(uid string) (uint64, error) {
|
||||
key := userMinSeq + uid
|
||||
seq, err := d.rdb.Get(context.Background(), key).Result()
|
||||
seq, err := d.RDB.Get(context.Background(), key).Result()
|
||||
return uint64(utils.StringToInt(seq)), err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetGroupUserMinSeq(groupID, userID string, minSeq uint32) (err error) {
|
||||
key := groupUserMinSeq + "g:" + groupID + "u:" + userID
|
||||
return d.RDB.Set(context.Background(), key, minSeq, 0).Err()
|
||||
}
|
||||
func (d *DataBases) GetGroupUserMinSeq(groupID, userID string) (uint64, error) {
|
||||
key := groupUserMinSeq + "g:" + groupID + "u:" + userID
|
||||
seq, err := d.RDB.Get(context.Background(), key).Result()
|
||||
return uint64(utils.StringToInt(seq)), err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetGroupMaxSeq(groupID string) (uint64, error) {
|
||||
key := groupMaxSeq + groupID
|
||||
seq, err := d.RDB.Get(context.Background(), key).Result()
|
||||
return uint64(utils.StringToInt(seq)), err
|
||||
}
|
||||
|
||||
func (d *DataBases) IncrGroupMaxSeq(groupID string) (uint64, error) {
|
||||
key := groupMaxSeq + groupID
|
||||
seq, err := d.RDB.Incr(context.Background(), key).Result()
|
||||
return uint64(seq), err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetGroupMaxSeq(groupID string, maxSeq uint64) error {
|
||||
key := groupMaxSeq + groupID
|
||||
return d.RDB.Set(context.Background(), key, maxSeq, 0).Err()
|
||||
}
|
||||
|
||||
//Store userid and platform class to redis
|
||||
func (d *DataBases) AddTokenFlag(userID string, platformID int, token string, flag int) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
log2.NewDebug("", "add token key is ", key)
|
||||
return d.rdb.HSet(context.Background(), key, token, flag).Err()
|
||||
return d.RDB.HSet(context.Background(), key, token, flag).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetTokenMapByUidPid(userID, platformID string) (map[string]int, error) {
|
||||
key := uidPidToken + userID + ":" + platformID
|
||||
log2.NewDebug("", "get token key is ", key)
|
||||
m, err := d.rdb.HGetAll(context.Background(), key).Result()
|
||||
m, err := d.RDB.HGetAll(context.Background(), key).Result()
|
||||
mm := make(map[string]int)
|
||||
for k, v := range m {
|
||||
mm[k] = utils.StringToInt(v)
|
||||
@@ -118,29 +136,29 @@ func (d *DataBases) SetTokenMapByUidPid(userID string, platformID int, m map[str
|
||||
for k, v := range m {
|
||||
mm[k] = v
|
||||
}
|
||||
return d.rdb.HSet(context.Background(), key, mm).Err()
|
||||
return d.RDB.HSet(context.Background(), key, mm).Err()
|
||||
}
|
||||
func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int, fields []string) error {
|
||||
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platformID)
|
||||
return d.rdb.HDel(context.Background(), key, fields...).Err()
|
||||
return d.RDB.HDel(context.Background(), key, fields...).Err()
|
||||
}
|
||||
func (d *DataBases) SetSingleConversationRecvMsgOpt(userID, conversationID string, opt int32) error {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
return d.rdb.HSet(context.Background(), key, conversationID, opt).Err()
|
||||
return d.RDB.HSet(context.Background(), key, conversationID, opt).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetSingleConversationRecvMsgOpt(userID, conversationID string) (int, error) {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
result, err := d.rdb.HGet(context.Background(), key, conversationID).Result()
|
||||
result, err := d.RDB.HGet(context.Background(), key, conversationID).Result()
|
||||
return utils.StringToInt(result), err
|
||||
}
|
||||
func (d *DataBases) SetUserGlobalMsgRecvOpt(userID string, opt int32) error {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
return d.rdb.HSet(context.Background(), key, GlobalMsgRecvOpt, opt).Err()
|
||||
return d.RDB.HSet(context.Background(), key, GlobalMsgRecvOpt, opt).Err()
|
||||
}
|
||||
func (d *DataBases) GetUserGlobalMsgRecvOpt(userID string) (int, error) {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
result, err := d.rdb.HGet(context.Background(), key, GlobalMsgRecvOpt).Result()
|
||||
result, err := d.RDB.HGet(context.Background(), key, GlobalMsgRecvOpt).Result()
|
||||
if err != nil {
|
||||
if err == go_redis.Nil {
|
||||
return 0, nil
|
||||
@@ -155,7 +173,7 @@ func (d *DataBases) GetMessageListBySeq(userID string, seqList []uint32, operati
|
||||
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
|
||||
key := messageCache + userID + "_" + strconv.Itoa(int(v))
|
||||
|
||||
result, err := d.rdb.Get(context.Background(), key).Result()
|
||||
result, err := d.RDB.Get(context.Background(), key).Result()
|
||||
if err != nil {
|
||||
errResult = err
|
||||
failedSeqList = append(failedSeqList, v)
|
||||
@@ -178,7 +196,7 @@ func (d *DataBases) GetMessageListBySeq(userID string, seqList []uint32, operati
|
||||
}
|
||||
func (d *DataBases) SetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string, operationID string) error {
|
||||
ctx := context.Background()
|
||||
pipe := d.rdb.Pipeline()
|
||||
pipe := d.RDB.Pipeline()
|
||||
var failedList []pbChat.MsgDataToMQ
|
||||
for _, msg := range msgList {
|
||||
key := messageCache + uid + "_" + strconv.Itoa(int(msg.MsgData.Seq))
|
||||
@@ -205,7 +223,7 @@ func (d *DataBases) SetMessageToCache(msgList []*pbChat.MsgDataToMQ, uid string,
|
||||
func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID string) error {
|
||||
ctx := context.Background()
|
||||
key := messageCache + userID + "_" + "*"
|
||||
vals, err := d.rdb.Keys(ctx, key).Result()
|
||||
vals, err := d.RDB.Keys(ctx, key).Result()
|
||||
log2.Debug(operationID, "vals: ", vals)
|
||||
if err == go_redis.Nil {
|
||||
return nil
|
||||
@@ -213,7 +231,7 @@ func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID str
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
if err = d.rdb.Del(ctx, vals...).Err(); err != nil {
|
||||
if err = d.RDB.Del(ctx, vals...).Err(); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
@@ -249,16 +267,16 @@ func (d *DataBases) HandleSignalInfo(operationID string, msg *pbCommon.MsgData)
|
||||
return err
|
||||
}
|
||||
keyList := SignalListCache + userID
|
||||
err = d.rdb.LPush(context.Background(), keyList, msg.ClientMsgID).Err()
|
||||
err = d.RDB.LPush(context.Background(), keyList, msg.ClientMsgID).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = d.rdb.Expire(context.Background(), keyList, time.Duration(timeout)*time.Second).Err()
|
||||
err = d.RDB.Expire(context.Background(), keyList, time.Duration(timeout)*time.Second).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key := SignalCache + msg.ClientMsgID
|
||||
err = d.rdb.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err()
|
||||
err = d.RDB.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -270,7 +288,7 @@ func (d *DataBases) HandleSignalInfo(operationID string, msg *pbCommon.MsgData)
|
||||
func (d *DataBases) GetSignalInfoFromCacheByClientMsgID(clientMsgID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
key := SignalCache + clientMsgID
|
||||
invitationInfo = &pbRtc.SignalInviteReq{}
|
||||
bytes, err := d.rdb.Get(context.Background(), key).Bytes()
|
||||
bytes, err := d.RDB.Get(context.Background(), key).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -291,7 +309,7 @@ func (d *DataBases) GetSignalInfoFromCacheByClientMsgID(clientMsgID string) (inv
|
||||
|
||||
func (d *DataBases) GetAvailableSignalInvitationInfo(userID string) (invitationInfo *pbRtc.SignalInviteReq, err error) {
|
||||
keyList := SignalListCache + userID
|
||||
result := d.rdb.LPop(context.Background(), keyList)
|
||||
result := d.RDB.LPop(context.Background(), keyList)
|
||||
if err = result.Err(); err != nil {
|
||||
return nil, utils.Wrap(err, "GetAvailableSignalInvitationInfo failed")
|
||||
}
|
||||
@@ -313,14 +331,14 @@ func (d *DataBases) GetAvailableSignalInvitationInfo(userID string) (invitationI
|
||||
|
||||
func (d *DataBases) DelUserSignalList(userID string) error {
|
||||
keyList := SignalListCache + userID
|
||||
err := d.rdb.Del(context.Background(), keyList).Err()
|
||||
err := d.RDB.Del(context.Background(), keyList).Err()
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) DelMsgFromCache(uid string, seqList []uint32, operationID string) {
|
||||
for _, seq := range seqList {
|
||||
key := messageCache + uid + "_" + strconv.Itoa(int(seq))
|
||||
result := d.rdb.Get(context.Background(), key).String()
|
||||
result := d.RDB.Get(context.Background(), key).String()
|
||||
var msg pbCommon.MsgData
|
||||
if err := utils.String2Pb(result, &msg); err != nil {
|
||||
log2.Error(operationID, utils.GetSelfFuncName(), "String2Pb failed", msg, err.Error())
|
||||
@@ -332,98 +350,17 @@ func (d *DataBases) DelMsgFromCache(uid string, seqList []uint32, operationID st
|
||||
log2.Error(operationID, utils.GetSelfFuncName(), "Pb2String failed", msg, err.Error())
|
||||
continue
|
||||
}
|
||||
if err := d.rdb.Set(context.Background(), key, s, time.Duration(config.Config.MsgCacheTimeout)*time.Second).Err(); err != nil {
|
||||
if err := d.RDB.Set(context.Background(), key, s, time.Duration(config.Config.MsgCacheTimeout)*time.Second).Err(); err != nil {
|
||||
log2.Error(operationID, utils.GetSelfFuncName(), "Set failed", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *DataBases) SetGetuiToken(token string, expireTime int64) error {
|
||||
return d.rdb.Set(context.Background(), getuiToken, token, time.Duration(expireTime)*time.Second).Err()
|
||||
return d.RDB.Set(context.Background(), getuiToken, token, time.Duration(expireTime)*time.Second).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetGetuiToken() (string, error) {
|
||||
result := d.rdb.Get(context.Background(), getuiToken)
|
||||
result := d.RDB.Get(context.Background(), getuiToken)
|
||||
return result.String(), result.Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) AddFriendToCache(userID string, friendIDList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range friendIDList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SAdd(context.Background(), friendRelationCache+userID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range friendIDList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SRem(context.Background(), friendRelationCache+userID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) {
|
||||
result := d.rdb.SMembers(context.Background(), friendRelationCache+userID)
|
||||
return result.Result()
|
||||
}
|
||||
|
||||
func (d *DataBases) AddBlackUserToCache(userID string, blackList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range blackList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SAdd(context.Background(), blackListCache+userID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range blackList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SRem(context.Background(), blackListCache+userID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetBlackListFromCache(userID string) ([]string, error) {
|
||||
result := d.rdb.SMembers(context.Background(), blackListCache+userID)
|
||||
return result.Result()
|
||||
}
|
||||
|
||||
func (d *DataBases) AddGroupMemberToCache(groupID string, userIDList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range userIDList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SAdd(context.Background(), groupCache+groupID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) ReduceGroupMemberFromCache(groupID string, userIDList ...string) error {
|
||||
var IDList []interface{}
|
||||
for _, id := range userIDList {
|
||||
IDList = append(IDList, id)
|
||||
}
|
||||
return d.rdb.SRem(context.Background(), groupCache+groupID, IDList...).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
|
||||
result := d.rdb.SMembers(context.Background(), groupCache+groupID)
|
||||
return result.Result()
|
||||
}
|
||||
|
||||
func (d *DataBases) SetUserInfoToCache(userID string, m map[string]interface{}) error {
|
||||
return d.rdb.HSet(context.Background(), userInfoCache+userID, m).Err()
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, error) {
|
||||
result, err := d.rdb.HGetAll(context.Background(), userInfoCache+userID).Result()
|
||||
bytes, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userInfo := &pbCommon.UserInfo{}
|
||||
if err := proto.Unmarshal(bytes, userInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(bytes, userInfo)
|
||||
return userInfo, err
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
@@ -104,21 +105,28 @@ func (d *DataBases) BatchInsertChat2DB(userID string, msgList []*pbMsg.MsgDataTo
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) BatchInsertChat2Cache(userID string, msgList []*pbMsg.MsgDataToMQ, operationID string) (error, uint64) {
|
||||
func (d *DataBases) BatchInsertChat2Cache(insertID string, msgList []*pbMsg.MsgDataToMQ, operationID string) (error, uint64) {
|
||||
newTime := getCurrentTimestampByMill()
|
||||
if len(msgList) > GetSingleGocMsgNum() {
|
||||
lenList := len(msgList)
|
||||
if lenList > GetSingleGocMsgNum() {
|
||||
return errors.New("too large"), 0
|
||||
}
|
||||
currentMaxSeq, err := d.GetUserMaxSeq(userID)
|
||||
if err == nil {
|
||||
|
||||
} else if err == go_redis.Nil {
|
||||
currentMaxSeq = 0
|
||||
if lenList < 1 {
|
||||
return errors.New("too short as 0"), 0
|
||||
}
|
||||
// judge sessionType to get seq
|
||||
var currentMaxSeq uint64
|
||||
var err error
|
||||
if msgList[0].MsgData.SessionType == constant.SuperGroupChatType {
|
||||
currentMaxSeq, err = d.GetGroupMaxSeq(insertID)
|
||||
} else {
|
||||
currentMaxSeq, err = d.GetUserMaxSeq(insertID)
|
||||
}
|
||||
if err != nil && err != go_redis.Nil {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
lastMaxSeq := currentMaxSeq
|
||||
|
||||
lastMaxSeq := currentMaxSeq
|
||||
for _, m := range msgList {
|
||||
log.Debug(operationID, "msg node ", m.String(), m.MsgData.ClientMsgID)
|
||||
currentMaxSeq++
|
||||
@@ -126,13 +134,18 @@ func (d *DataBases) BatchInsertChat2Cache(userID string, msgList []*pbMsg.MsgDat
|
||||
sMsg.SendTime = m.MsgData.SendTime
|
||||
m.MsgData.Seq = uint32(currentMaxSeq)
|
||||
}
|
||||
log.Debug(operationID, "SetMessageToCache ", userID, len(msgList))
|
||||
err = d.SetMessageToCache(msgList, userID, operationID)
|
||||
log.Debug(operationID, "SetMessageToCache ", insertID, len(msgList))
|
||||
err = d.SetMessageToCache(msgList, insertID, operationID)
|
||||
if err != nil {
|
||||
log.Error(operationID, "setMessageToCache failed, continue ", err.Error(), len(msgList), userID)
|
||||
log.Error(operationID, "setMessageToCache failed, continue ", err.Error(), len(msgList), insertID)
|
||||
}
|
||||
log.NewWarn(operationID, "batch to redis cost time ", getCurrentTimestampByMill()-newTime, userID, len(msgList))
|
||||
return utils.Wrap(d.SetUserMaxSeq(userID, uint64(currentMaxSeq)), ""), lastMaxSeq
|
||||
log.Debug(operationID, "batch to redis cost time ", getCurrentTimestampByMill()-newTime, insertID, len(msgList))
|
||||
if msgList[0].MsgData.SessionType == constant.SuperGroupChatType {
|
||||
err = d.SetGroupMaxSeq(insertID, currentMaxSeq)
|
||||
} else {
|
||||
err = d.SetUserMaxSeq(insertID, currentMaxSeq)
|
||||
}
|
||||
return utils.Wrap(err, ""), lastMaxSeq
|
||||
}
|
||||
|
||||
//func (d *DataBases) BatchInsertChatBoth(userID string, msgList []*pbMsg.MsgDataToMQ, operationID string) (error, uint64) {
|
||||
|
||||
+29
-9
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"github.com/dtm-labs/rockscache"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||
"strings"
|
||||
|
||||
@@ -28,14 +29,15 @@ type DataBases struct {
|
||||
mgoSession *mgo.Session
|
||||
//redisPool *redis.Pool
|
||||
mongoClient *mongo.Client
|
||||
rdb go_redis.UniversalClient
|
||||
RDB go_redis.UniversalClient
|
||||
Rc *rockscache.Client
|
||||
WeakRc *rockscache.Client
|
||||
}
|
||||
|
||||
type RedisClient struct {
|
||||
client *go_redis.Client
|
||||
cluster *go_redis.ClusterClient
|
||||
go_redis.UniversalClient
|
||||
enableCluster bool
|
||||
}
|
||||
|
||||
func key(dbAddress, dbName string) string {
|
||||
@@ -88,16 +90,14 @@ func init() {
|
||||
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
|
||||
fmt.Println("work_moment_id", "index create failed", err.Error())
|
||||
}
|
||||
|
||||
if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil {
|
||||
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
||||
}
|
||||
|
||||
if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil {
|
||||
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
||||
}
|
||||
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
|
||||
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
||||
fmt.Println("tag_id", "index create failed", err.Error())
|
||||
}
|
||||
fmt.Println("create index success")
|
||||
DB.mongoClient = mongoClient
|
||||
@@ -122,26 +122,46 @@ func init() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if config.Config.Redis.EnableCluster {
|
||||
DB.rdb = go_redis.NewClusterClient(&go_redis.ClusterOptions{
|
||||
DB.RDB = go_redis.NewClusterClient(&go_redis.ClusterOptions{
|
||||
Addrs: config.Config.Redis.DBAddress,
|
||||
Username: config.Config.Redis.DBUserName,
|
||||
Password: config.Config.Redis.DBPassWord, // no password set
|
||||
PoolSize: 50,
|
||||
})
|
||||
_, err = DB.rdb.Ping(ctx).Result()
|
||||
_, err = DB.RDB.Ping(ctx).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
} else {
|
||||
DB.rdb = go_redis.NewClient(&go_redis.Options{
|
||||
DB.RDB = go_redis.NewClient(&go_redis.Options{
|
||||
Addr: config.Config.Redis.DBAddress[0],
|
||||
Username: config.Config.Redis.DBUserName,
|
||||
Password: config.Config.Redis.DBPassWord, // no password set
|
||||
DB: 0, // use default DB
|
||||
PoolSize: 100, // 连接池大小
|
||||
})
|
||||
_, err = DB.rdb.Ping(ctx).Result()
|
||||
_, err = DB.RDB.Ping(ctx).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
// 强一致性缓存,当一个key被标记删除,其他请求线程会被锁住轮询直到新的key生成,适合各种同步的拉取, 如果弱一致可能导致拉取还是老数据,毫无意义
|
||||
DB.Rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
|
||||
Addr: config.Config.Redis.DBAddress[0],
|
||||
Password: config.Config.Redis.DBPassWord, // no password set
|
||||
DB: 0, // use default DB
|
||||
PoolSize: 100, // 连接池大小
|
||||
}), rockscache.NewDefaultOptions())
|
||||
DB.Rc.Options.StrongConsistency = true
|
||||
|
||||
// 弱一致性缓存,当一个key被标记删除,其他请求线程直接返回该key的value,适合高频并且生成很缓存很慢的情况 如大群发消息缓存的缓存
|
||||
DB.WeakRc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{
|
||||
Addr: config.Config.Redis.DBAddress[0],
|
||||
Password: config.Config.Redis.DBPassWord, // no password set
|
||||
DB: 0, // use default DB
|
||||
PoolSize: 100, // 连接池大小
|
||||
}), rockscache.NewDefaultOptions())
|
||||
DB.WeakRc.Options.StrongConsistency = false
|
||||
}
|
||||
|
||||
func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error {
|
||||
|
||||
@@ -77,17 +77,21 @@ func (FriendRequest) TableName() string {
|
||||
type Group struct {
|
||||
//`json:"operationID" binding:"required"`
|
||||
//`protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"` `json:"operationID" binding:"required"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
}
|
||||
|
||||
//message GroupMemberFullInfo {
|
||||
@@ -110,6 +114,7 @@ type GroupMember struct {
|
||||
RoleLevel int32 `gorm:"column:role_level"`
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
@@ -127,15 +132,17 @@ type GroupMember struct {
|
||||
//string Ex = 9;
|
||||
//}open_im_sdk.GroupRequest == imdb.GroupRequest
|
||||
type GroupRequest struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
ReqTime time.Time `gorm:"column:req_time"`
|
||||
HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
HandledTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:1024"`
|
||||
HandledMsg string `gorm:"column:handle_msg;size:1024"`
|
||||
ReqTime time.Time `gorm:"column:req_time"`
|
||||
HandleUserID string `gorm:"column:handle_user_id;size:64"`
|
||||
HandledTime time.Time `gorm:"column:handle_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
InviterUserID string `gorm:"column:inviter_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
//string UserID = 1;
|
||||
@@ -161,6 +168,7 @@ type User struct {
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
//message BlackInfo{
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
|
||||
+56
-71
@@ -2,18 +2,25 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type mysqlDB struct {
|
||||
sync.RWMutex
|
||||
dbMap map[string]*gorm.DB
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
type Writer struct{}
|
||||
|
||||
func (w Writer) Printf(format string, args ...interface{}) {
|
||||
fmt.Printf(format, args...)
|
||||
}
|
||||
|
||||
func initMysqlDB() {
|
||||
@@ -22,13 +29,13 @@ func initMysqlDB() {
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
||||
var db *gorm.DB
|
||||
var err1 error
|
||||
db, err := gorm.Open("mysql", dsn)
|
||||
db, err := gorm.Open(mysql.Open(dsn), nil)
|
||||
if err != nil {
|
||||
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||
}
|
||||
if err != nil {
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
db, err1 = gorm.Open("mysql", dsn)
|
||||
db, err1 = gorm.Open(mysql.Open(dsn), nil)
|
||||
if err1 != nil {
|
||||
fmt.Println("0", "Open failed ", err1.Error(), dsn)
|
||||
panic(err1.Error())
|
||||
@@ -42,11 +49,22 @@ func initMysqlDB() {
|
||||
fmt.Println("0", "Exec failed ", err.Error(), sql)
|
||||
panic(err.Error())
|
||||
}
|
||||
db.Close()
|
||||
|
||||
dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
db, err = gorm.Open("mysql", dsn)
|
||||
|
||||
newLogger := logger.New(
|
||||
Writer{},
|
||||
logger.Config{
|
||||
SlowThreshold: 200 * time.Millisecond, // Slow SQL threshold
|
||||
LogLevel: logger.Error, // Log level
|
||||
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
Colorful: true, // Disable color
|
||||
},
|
||||
)
|
||||
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: newLogger,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||
panic(err.Error())
|
||||
@@ -65,103 +83,70 @@ func initMysqlDB() {
|
||||
db.Set("gorm:table_options", "CHARSET=utf8")
|
||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
|
||||
if !db.HasTable(&Friend{}) {
|
||||
if !db.Migrator().HasTable(&Friend{}) {
|
||||
fmt.Println("CreateTable Friend")
|
||||
db.CreateTable(&Friend{})
|
||||
db.Migrator().CreateTable(&Friend{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&FriendRequest{}) {
|
||||
if !db.Migrator().HasTable(&FriendRequest{}) {
|
||||
fmt.Println("CreateTable FriendRequest")
|
||||
db.CreateTable(&FriendRequest{})
|
||||
db.Migrator().CreateTable(&FriendRequest{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&Group{}) {
|
||||
if !db.Migrator().HasTable(&Group{}) {
|
||||
fmt.Println("CreateTable Group")
|
||||
db.CreateTable(&Group{})
|
||||
db.Migrator().CreateTable(&Group{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&GroupMember{}) {
|
||||
if !db.Migrator().HasTable(&GroupMember{}) {
|
||||
fmt.Println("CreateTable GroupMember")
|
||||
db.CreateTable(&GroupMember{})
|
||||
db.Migrator().CreateTable(&GroupMember{})
|
||||
}
|
||||
if !db.HasTable(&GroupRequest{}) {
|
||||
if !db.Migrator().HasTable(&GroupRequest{}) {
|
||||
fmt.Println("CreateTable GroupRequest")
|
||||
db.CreateTable(&GroupRequest{})
|
||||
db.Migrator().CreateTable(&GroupRequest{})
|
||||
}
|
||||
if !db.HasTable(&User{}) {
|
||||
if !db.Migrator().HasTable(&User{}) {
|
||||
fmt.Println("CreateTable User")
|
||||
db.CreateTable(&User{})
|
||||
db.Migrator().CreateTable(&User{})
|
||||
}
|
||||
if !db.HasTable(&Black{}) {
|
||||
if !db.Migrator().HasTable(&Black{}) {
|
||||
fmt.Println("CreateTable Black")
|
||||
db.CreateTable(&Black{})
|
||||
db.Migrator().CreateTable(&Black{})
|
||||
}
|
||||
if !db.HasTable(&ChatLog{}) {
|
||||
if !db.Migrator().HasTable(&ChatLog{}) {
|
||||
fmt.Println("CreateTable ChatLog")
|
||||
db.CreateTable(&ChatLog{})
|
||||
db.Migrator().CreateTable(&ChatLog{})
|
||||
}
|
||||
if !db.HasTable(&Register{}) {
|
||||
if !db.Migrator().HasTable(&Register{}) {
|
||||
fmt.Println("CreateTable Register")
|
||||
db.CreateTable(&Register{})
|
||||
db.Migrator().CreateTable(&Register{})
|
||||
}
|
||||
if !db.HasTable(&Conversation{}) {
|
||||
if !db.Migrator().HasTable(&Conversation{}) {
|
||||
fmt.Println("CreateTable Conversation")
|
||||
db.CreateTable(&Conversation{})
|
||||
db.Migrator().CreateTable(&Conversation{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&Department{}) {
|
||||
if !db.Migrator().HasTable(&Department{}) {
|
||||
fmt.Println("CreateTable Department")
|
||||
db.CreateTable(&Department{})
|
||||
db.Migrator().CreateTable(&Department{})
|
||||
}
|
||||
if !db.HasTable(&OrganizationUser{}) {
|
||||
if !db.Migrator().HasTable(&OrganizationUser{}) {
|
||||
fmt.Println("CreateTable OrganizationUser")
|
||||
db.CreateTable(&OrganizationUser{})
|
||||
db.Migrator().CreateTable(&OrganizationUser{})
|
||||
}
|
||||
if !db.HasTable(&DepartmentMember{}) {
|
||||
if !db.Migrator().HasTable(&DepartmentMember{}) {
|
||||
fmt.Println("CreateTable DepartmentMember")
|
||||
db.CreateTable(&DepartmentMember{})
|
||||
db.Migrator().CreateTable(&DepartmentMember{})
|
||||
}
|
||||
if !db.HasTable(&AppVersion{}) {
|
||||
if !db.Migrator().HasTable(&AppVersion{}) {
|
||||
fmt.Println("CreateTable DepartmentMember")
|
||||
db.CreateTable(&AppVersion{})
|
||||
db.Migrator().CreateTable(&AppVersion{})
|
||||
}
|
||||
DB.MysqlDB.db = db
|
||||
return
|
||||
}
|
||||
|
||||
func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) {
|
||||
return m.GormDB(config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
}
|
||||
|
||||
func (m *mysqlDB) GormDB(dbAddress, dbName string) (*gorm.DB, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
k := key(dbAddress, dbName)
|
||||
if _, ok := m.dbMap[k]; !ok {
|
||||
if err := m.open(dbAddress, dbName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return m.dbMap[k], nil
|
||||
}
|
||||
|
||||
func (m *mysqlDB) open(dbAddress, dbName string) error {
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, dbAddress, dbName)
|
||||
db, err := gorm.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db.SingularTable(true)
|
||||
db.DB().SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
|
||||
db.DB().SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
|
||||
db.DB().SetConnMaxLifetime(time.Duration(config.Config.Mysql.DBMaxLifeTime) * time.Second)
|
||||
|
||||
if m.dbMap == nil {
|
||||
m.dbMap = make(map[string]*gorm.DB)
|
||||
}
|
||||
k := key(dbAddress, dbName)
|
||||
m.dbMap[k] = db
|
||||
return nil
|
||||
func (m *mysqlDB) DefaultGormDB() *gorm.DB {
|
||||
return DB.MysqlDB.db
|
||||
}
|
||||
|
||||
@@ -7,99 +7,65 @@ import (
|
||||
)
|
||||
|
||||
func SetConversation(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
|
||||
// if exist, then update record
|
||||
} else {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat,
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat,
|
||||
"group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error
|
||||
}
|
||||
}
|
||||
func SetOneConversation(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
|
||||
|
||||
}
|
||||
|
||||
func PeerUserSetConversation(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
|
||||
// if exist, then update record
|
||||
}
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Update(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error
|
||||
|
||||
}
|
||||
|
||||
func SetRecvMsgOpt(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
|
||||
// if exist, then update record
|
||||
} else {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
|
||||
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
|
||||
}
|
||||
}
|
||||
|
||||
func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resultArr []string
|
||||
err = dbConn.Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -108,38 +74,21 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
|
||||
|
||||
func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) {
|
||||
var conversation db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversation, err
|
||||
}
|
||||
err = dbConn.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
|
||||
return conversation, err
|
||||
}
|
||||
|
||||
func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
return dbConn.Debug().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error
|
||||
|
||||
}
|
||||
|
||||
@@ -2,17 +2,13 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
_ "github.com/jinzhu/gorm"
|
||||
_ "gorm.io/gorm"
|
||||
)
|
||||
|
||||
func GetRegister(account, areaCode string) (*db.Register, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func GetRegister(account, areaCode, userID string) (*db.Register, error) {
|
||||
var r db.Register
|
||||
return &r, dbConn.Table("registers").Where("account = ? or account =? and area_code=?",
|
||||
account, account, areaCode).Take(&r).Error
|
||||
return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
|
||||
userID, "", account, account, areaCode).Take(&r).Error
|
||||
}
|
||||
|
||||
func SetPassword(account, password, ex, userID, areaCode string) error {
|
||||
@@ -23,21 +19,12 @@ func SetPassword(account, password, ex, userID, areaCode string) error {
|
||||
UserID: userID,
|
||||
AreaCode: areaCode,
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("registers").Create(&r).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Create(&r).Error
|
||||
}
|
||||
|
||||
func ResetPassword(account, password string) error {
|
||||
r := db.Register{
|
||||
Password: password,
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
dbConn.LogMode(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("registers").Where("account = ?", account).Update(&r).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error
|
||||
}
|
||||
|
||||
@@ -6,10 +6,6 @@ import (
|
||||
)
|
||||
|
||||
func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateTime := int(time.Now().Unix())
|
||||
app := db.AppVersion{
|
||||
Version: version,
|
||||
@@ -20,24 +16,19 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y
|
||||
ForceUpdate: forceUpdate,
|
||||
UpdateLog: updateLog,
|
||||
}
|
||||
result := dbConn.Model(db.AppVersion{}).Where("type = ?", appType).Update(map[string]interface{}{"force_update": forceUpdate,
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate,
|
||||
"version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
err := dbConn.Create(&app).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Create(&app).Error
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetNewestVersion(appType int) (*db.AppVersion, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
app := db.AppVersion{}
|
||||
if err != nil {
|
||||
return &app, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
return &app, dbConn.Model(db.AppVersion{}).First(&app, appType).Error
|
||||
return &app, db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).First(&app, appType).Error
|
||||
}
|
||||
|
||||
@@ -7,13 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func InsertToFriend(toInsertFollow *db.Friend) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toInsertFollow.CreateTime = time.Now()
|
||||
|
||||
err = dbConn.Table("friends").Create(toInsertFollow).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -21,12 +16,8 @@ func InsertToFriend(toInsertFollow *db.Friend) error {
|
||||
}
|
||||
|
||||
func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Friend, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var friend db.Friend
|
||||
err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -34,15 +25,10 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie
|
||||
}
|
||||
|
||||
func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var friends []db.Friend
|
||||
var x db.Friend
|
||||
x.OwnerUserID = OwnerUserID
|
||||
err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
||||
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -50,12 +36,8 @@ func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
|
||||
}
|
||||
|
||||
func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var friendIDList []string
|
||||
err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -63,29 +45,9 @@ func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
|
||||
}
|
||||
|
||||
func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
|
||||
}
|
||||
|
||||
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
|
||||
}
|
||||
|
||||
//type Friend struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
||||
// FriendUserID string `gorm:"column:friend_user_id;primaryKey;"`
|
||||
// Remark string `gorm:"column:remark"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// AddSource int32 `gorm:"column:add_source"`
|
||||
// OperatorUserID string `gorm:"column:operator_user_id"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
@@ -20,12 +20,8 @@ import (
|
||||
|
||||
// who apply to add me
|
||||
func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequest, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var usersInfo []db.FriendRequest
|
||||
err = dbConn.Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -34,12 +30,8 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequ
|
||||
|
||||
//I apply to add somebody
|
||||
func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var usersInfo []db.FriendRequest
|
||||
err = dbConn.Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -48,12 +40,8 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest
|
||||
|
||||
//FromUserId apply to add ToUserID
|
||||
func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRequest, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var friendRequest db.FriendRequest
|
||||
err = dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,23 +49,13 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe
|
||||
}
|
||||
|
||||
func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
friendRequest.CreateTime = time.Now()
|
||||
|
||||
return dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error
|
||||
}
|
||||
|
||||
func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,7 +67,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in
|
||||
|
||||
friendRequest.CreateTime = time.Now()
|
||||
args["create_time"] = friendRequest.CreateTime
|
||||
u := dbConn.Model(friendRequest).Updates(args)
|
||||
u := db.DB.MysqlDB.DefaultGormDB().Model(friendRequest).Updates(args)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
@@ -104,7 +82,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in
|
||||
if friendRequest.HandleTime.Unix() < 0 {
|
||||
friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err = dbConn.Table("friend_requests").Create(friendRequest).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,16 +22,12 @@ import (
|
||||
//}
|
||||
|
||||
func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toInsertInfo.JoinTime = time.Now()
|
||||
if toInsertInfo.RoleLevel == 0 {
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
}
|
||||
toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
err = dbConn.Table("group_members").Create(toInsertInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -39,12 +35,8 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
|
||||
}
|
||||
|
||||
func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberList []db.GroupMember
|
||||
err = dbConn.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error
|
||||
//err = dbConn.Table("group_members").Where("user_id=?", userID).Take(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -53,13 +45,8 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) {
|
||||
}
|
||||
|
||||
func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberList []db.GroupMember
|
||||
err = dbConn.Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
|
||||
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,13 +54,8 @@ func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
|
||||
}
|
||||
|
||||
func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var groupMemberIDList []string
|
||||
err = dbConn.Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,12 +63,8 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
}
|
||||
|
||||
func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberList []db.GroupMember
|
||||
err = dbConn.Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -94,12 +72,8 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([
|
||||
}
|
||||
|
||||
func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMember db.GroupMember
|
||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -107,73 +81,33 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb
|
||||
}
|
||||
|
||||
func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error
|
||||
}
|
||||
|
||||
func DeleteGroupMemberByGroupID(groupID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Update(&groupMemberInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoByMap(groupMemberInfo db.GroupMember, m map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error
|
||||
}
|
||||
|
||||
func GetOwnerManagerByGroupID(groupID string) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberList []db.GroupMember
|
||||
err = dbConn.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupMemberList, nil
|
||||
}
|
||||
|
||||
func GetGroupMemberNumByGroupID(groupID string) (uint32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, utils.Wrap(err, "DefaultGormDB failed")
|
||||
}
|
||||
var number uint32
|
||||
err = dbConn.Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
func GetGroupMemberNumByGroupID(groupID string) (int64, error) {
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error
|
||||
if err != nil {
|
||||
return 0, utils.Wrap(err, "")
|
||||
}
|
||||
@@ -195,12 +129,8 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) {
|
||||
}
|
||||
|
||||
func IsExistGroupMember(groupID, userID string) bool {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
var number int32
|
||||
err = dbConn.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -248,7 +178,7 @@ func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupIDList []string = make([]string, len(memberList))
|
||||
var groupIDList []string
|
||||
for _, v := range memberList {
|
||||
groupIDList = append(groupIDList, v.GroupID)
|
||||
}
|
||||
@@ -270,36 +200,23 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool {
|
||||
|
||||
func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]db.GroupMember, error) {
|
||||
var groupMembers []db.GroupMember
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return groupMembers, err
|
||||
}
|
||||
err = dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groupMembers).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupMembers, nil
|
||||
}
|
||||
|
||||
func GetGroupMembersCount(groupId, userName string) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var count int32
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
func GetGroupMembersCount(groupId, userName string) (int64, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
|
||||
return count, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo db.GroupMember, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Model(groupMemberInfo).Updates(args).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/jinzhu/gorm"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -24,28 +24,25 @@ import (
|
||||
//}
|
||||
|
||||
func InsertIntoGroup(groupInfo db.Group) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if groupInfo.GroupName == "" {
|
||||
groupInfo.GroupName = "Group Chat"
|
||||
}
|
||||
groupInfo.CreateTime = time.Now()
|
||||
err = dbConn.Table("groups").Create(groupInfo).Error
|
||||
|
||||
if groupInfo.NotificationUpdateTime.Unix() < 0 {
|
||||
groupInfo.NotificationUpdateTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Create(groupInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetGroupInfoByGroupID(groupId string) (*db.Group, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var groupInfo db.Group
|
||||
err = dbConn.Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -53,33 +50,18 @@ func GetGroupInfoByGroupID(groupId string) (*db.Group, error) {
|
||||
}
|
||||
|
||||
func SetGroupInfo(groupInfo db.Group) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error
|
||||
}
|
||||
|
||||
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var groups []db.Group
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
|
||||
err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
|
||||
func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var groups []db.Group
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
|
||||
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||
return groups, err
|
||||
}
|
||||
return groups, nil
|
||||
@@ -97,27 +79,18 @@ func OperateGroupStatus(groupId string, groupStatus int32) error {
|
||||
}
|
||||
|
||||
func DeleteGroup(groupId string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var group db.Group
|
||||
var groupMembers []db.GroupMember
|
||||
if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
groupMember := db.GroupMember{
|
||||
UserID: userId,
|
||||
GroupID: groupId,
|
||||
@@ -126,10 +99,11 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
RoleLevel: roleLevel,
|
||||
}
|
||||
groupMaster := db.GroupMember{}
|
||||
var err error
|
||||
switch roleLevel {
|
||||
case constant.GroupOwner:
|
||||
err = dbConn.Transaction(func(tx *gorm.DB) error {
|
||||
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error {
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Updates(&db.GroupMember{
|
||||
RoleLevel: constant.GroupOrdinaryUsers,
|
||||
})
|
||||
if result.Error != nil {
|
||||
@@ -139,7 +113,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
|
||||
}
|
||||
|
||||
result = dbConn.Table("group_members").First(&groupMember).Update(updateInfo)
|
||||
result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").First(&groupMember).Updates(updateInfo)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
@@ -150,8 +124,8 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
})
|
||||
|
||||
case constant.GroupOrdinaryUsers:
|
||||
err = dbConn.Transaction(func(tx *gorm.DB) error {
|
||||
result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error {
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
@@ -161,7 +135,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
if groupMaster.UserID == userId {
|
||||
return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId))
|
||||
} else {
|
||||
result = dbConn.Table("group_members").Find(&groupMember).Update(updateInfo)
|
||||
result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").Find(&groupMember).Updates(updateInfo)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
@@ -172,64 +146,41 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return "", "", nil
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func GetGroupsCountNum(group db.Group) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var count int32
|
||||
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
return int32(count), nil
|
||||
}
|
||||
|
||||
func GetGroupById(groupId string) (db.Group, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
group := db.Group{
|
||||
GroupID: groupId,
|
||||
}
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
|
||||
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Find(&group).Error; err != nil {
|
||||
return group, err
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
|
||||
func GetGroupMaster(groupId string) (db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
groupMember := db.GroupMember{}
|
||||
if err != nil {
|
||||
return groupMember, err
|
||||
}
|
||||
|
||||
if err := dbConn.Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil {
|
||||
return groupMember, err
|
||||
}
|
||||
return groupMember, nil
|
||||
}
|
||||
|
||||
func UpdateGroupInfoDefaultZero(groupID string, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("groups").Where("group_id = ? ", groupID).Update(args).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id = ? ", groupID).Updates(args).Error
|
||||
}
|
||||
|
||||
func GetAllGroupIDList() ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupIDList []string
|
||||
err = dbConn.Table("groups").Pluck("group_id", &groupIDList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Pluck("group_id", &groupIDList).Error
|
||||
return groupIDList, err
|
||||
}
|
||||
|
||||
@@ -20,27 +20,18 @@ import (
|
||||
//}
|
||||
|
||||
func UpdateGroupRequest(groupRequest db.GroupRequest) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if groupRequest.HandledTime.Unix() < 0 {
|
||||
groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
return dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
u := dbConn.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Update(&toInsertInfo)
|
||||
u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -50,7 +41,7 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
|
||||
err = dbConn.Table("group_requests").Create(&toInsertInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -58,12 +49,8 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupRequest db.GroupRequest
|
||||
err = dbConn.Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -71,24 +58,12 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest
|
||||
}
|
||||
|
||||
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupRequestList []db.GroupRequest
|
||||
err = dbConn.Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,12 +94,7 @@ func GetGroupApplicationList(userID string) ([]db.GroupRequest, error) {
|
||||
|
||||
func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
|
||||
var groupRequestList []db.GroupRequest
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,15 +8,10 @@ import (
|
||||
)
|
||||
|
||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var chatLogs []db.ChatLog
|
||||
if err != nil {
|
||||
return chatLogs, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
db := dbConn.Table("chat_logs").
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
|
||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
}
|
||||
@@ -32,19 +27,14 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
err = db.Find(&chatLogs).Error
|
||||
err := db.Find(&chatLogs).Error
|
||||
return chatLogs, err
|
||||
}
|
||||
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var chatLogs []db.ChatLog
|
||||
var count int64
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
db := dbConn.Table("chat_logs").
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
@@ -63,6 +53,6 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
err = db.Find(&chatLogs).Count(&count).Error
|
||||
err := db.Find(&chatLogs).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
@@ -3,175 +3,116 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/jinzhu/gorm"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateDepartment(department *db.Department) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
department.CreateTime = time.Now()
|
||||
return dbConn.Table("departments").Create(department).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error
|
||||
}
|
||||
|
||||
func GetDepartment(departmentID string) (*db.Department, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var department db.Department
|
||||
err = dbConn.Table("departments").Where("department_id=?", departmentID).Find(&department).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error
|
||||
return &department, err
|
||||
}
|
||||
|
||||
func UpdateDepartment(department *db.Department, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetSubDepartmentList(departmentID string) (error, []db.Department) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
func GetSubDepartmentList(departmentID string) ([]db.Department, error) {
|
||||
var departmentList []db.Department
|
||||
var err error
|
||||
if departmentID == "-1" {
|
||||
err = dbConn.Table("departments").Find(&departmentList).Error
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error
|
||||
} else {
|
||||
err = dbConn.Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error
|
||||
}
|
||||
|
||||
return err, departmentList
|
||||
return departmentList, err
|
||||
}
|
||||
|
||||
func DeleteDepartment(departmentID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
var err error
|
||||
if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = dbConn.Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = dbConn.Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil {
|
||||
if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateOrganizationUser(organizationUser *db.OrganizationUser) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
organizationUser.CreateTime = time.Now()
|
||||
|
||||
return dbConn.Table("organization_users").Create(organizationUser).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error
|
||||
}
|
||||
|
||||
func GetOrganizationUser(userID string) (error, *db.OrganizationUser) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
organizationUser := db.OrganizationUser{}
|
||||
err = dbConn.Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error
|
||||
return err, &organizationUser
|
||||
}
|
||||
|
||||
func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateDepartmentMember(departmentMember *db.DepartmentMember) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
departmentMember.CreateTime = time.Now()
|
||||
return dbConn.Table("department_members").Create(departmentMember).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error
|
||||
}
|
||||
|
||||
func GetUserInDepartment(userID string) (error, []db.DepartmentMember) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
var departmentMemberList []db.DepartmentMember
|
||||
err = dbConn.Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error
|
||||
return err, departmentMemberList
|
||||
}
|
||||
|
||||
func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
Updates(departmentMember).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if args != nil {
|
||||
return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID).
|
||||
Updates(args).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteUserInDepartment(departmentID, userID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error
|
||||
}
|
||||
|
||||
func DeleteUserInAllDepartment(userID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error
|
||||
}
|
||||
|
||||
func DeleteOrganizationUser(OrganizationUserID string) error {
|
||||
if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error
|
||||
}
|
||||
|
||||
func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
var departmentMemberList []db.DepartmentMember
|
||||
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
@@ -182,77 +123,54 @@ func GetDepartmentMemberUserIDList(departmentID string) (error, []string) {
|
||||
return err, userIDList
|
||||
}
|
||||
|
||||
func GetDepartmentMemberList(departmentID string) (error, []db.DepartmentMember) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) {
|
||||
var departmentMemberList []db.DepartmentMember
|
||||
var err error
|
||||
if departmentID == "-1" {
|
||||
err = dbConn.Table("department_members").Find(&departmentMemberList).Error
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error
|
||||
} else {
|
||||
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err, nil
|
||||
return nil, err
|
||||
}
|
||||
return err, departmentMemberList
|
||||
return departmentMemberList, err
|
||||
}
|
||||
|
||||
func GetAllOrganizationUserID() (error, []string) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
var OrganizationUser db.OrganizationUser
|
||||
var result []string
|
||||
return dbConn.Model(&OrganizationUser).Pluck("user_id", &result).Error, result
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result
|
||||
}
|
||||
|
||||
func GetDepartmentMemberNum(departmentID string) (error, uint32) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "DefaultGormDB failed"), 0
|
||||
}
|
||||
var number uint32
|
||||
err = dbConn.Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Count(&number).Error
|
||||
if err != nil {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
return nil, number
|
||||
return nil, uint32(number)
|
||||
|
||||
}
|
||||
|
||||
func GetSubDepartmentNum(departmentID string) (error, uint32) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "DefaultGormDB failed"), 0
|
||||
}
|
||||
var number uint32
|
||||
err = dbConn.Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
|
||||
var number int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Count(&number).Error
|
||||
if err != nil {
|
||||
return utils.Wrap(err, ""), 0
|
||||
}
|
||||
return nil, number
|
||||
return nil, uint32(number)
|
||||
}
|
||||
|
||||
func SetDepartmentRelatedGroupID(groupID, departmentID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "DefaultGormDB failed")
|
||||
}
|
||||
department := &db.Department{RelatedGroupID: groupID}
|
||||
return dbConn.Model(&department).Where("department_id=?", departmentID).Update(department).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Updates(department).Error
|
||||
}
|
||||
|
||||
func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "DefaultGormDB failed")
|
||||
}
|
||||
var groupIDList []string
|
||||
err = dbConn.Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error
|
||||
return groupIDList, err
|
||||
}
|
||||
|
||||
@@ -260,8 +178,7 @@ func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department,
|
||||
var department db.Department
|
||||
var parentDepartment db.Department
|
||||
//var parentID string
|
||||
dbConn.LogMode(true)
|
||||
err := dbConn.Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
@@ -287,21 +204,14 @@ func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList *[]s
|
||||
}
|
||||
|
||||
func GetDepartmentParentIDList(departmentID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn := db.DB.MysqlDB.DefaultGormDB()
|
||||
var parentIDList []string
|
||||
err = GetDepartmentParent(departmentID, dbConn, &parentIDList)
|
||||
err := GetDepartmentParent(departmentID, dbConn, &parentIDList)
|
||||
return parentIDList, err
|
||||
}
|
||||
|
||||
func GetRandomDepartmentID() (string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
department := &db.Department{}
|
||||
err = dbConn.Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ?", "", "0").First(department).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error
|
||||
return department.DepartmentID, err
|
||||
}
|
||||
|
||||
@@ -6,102 +6,57 @@ import (
|
||||
)
|
||||
|
||||
func GetActiveUserNum(from, to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetIncreaseUserNum(from, to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalUserNum() (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalUserNumByDate(to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time <= ?", to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetPrivateMessageNum(from, to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetGroupMessageNum(from, to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetTotalGroupNum() (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetGroupNum(to time.Time) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
type activeGroup struct {
|
||||
@@ -111,18 +66,13 @@ type activeGroup struct {
|
||||
}
|
||||
|
||||
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var activeGroups []*activeGroup
|
||||
if err != nil {
|
||||
return activeGroups, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
for _, activeGroup := range activeGroups {
|
||||
group := db.Group{
|
||||
GroupID: activeGroup.Id,
|
||||
}
|
||||
dbConn.Table("groups").Where("group_id= ? ", group.GroupID).Find(&group)
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group)
|
||||
activeGroup.Name = group.GroupName
|
||||
}
|
||||
return activeGroups, err
|
||||
@@ -135,18 +85,13 @@ type activeUser struct {
|
||||
}
|
||||
|
||||
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var activeUsers []*activeUser
|
||||
if err != nil {
|
||||
return activeUsers, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
for _, activeUser := range activeUsers {
|
||||
user := db.User{
|
||||
UserID: activeUser.Id,
|
||||
}
|
||||
dbConn.Table("users").Select("user_id, name").Find(&user)
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user)
|
||||
activeUser.Name = user.Nickname
|
||||
}
|
||||
return activeUsers, err
|
||||
|
||||
@@ -7,13 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func InsertInToUserBlackList(black db.Black) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
black.CreateTime = time.Now()
|
||||
err = dbConn.Table("blacks").Create(black).Error
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
|
||||
}
|
||||
|
||||
//type Black struct {
|
||||
@@ -26,31 +21,18 @@ func InsertInToUserBlackList(black db.Black) error {
|
||||
//}
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var black db.Black
|
||||
err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
}
|
||||
|
||||
func RemoveBlackList(ownerUserID, blockUserID string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
|
||||
return utils.Wrap(err, "RemoveBlackList failed")
|
||||
}
|
||||
|
||||
func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var blackListUsersInfo []db.Black
|
||||
err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,12 +40,8 @@ func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
|
||||
}
|
||||
|
||||
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var blackIDList []string
|
||||
err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -37,10 +35,6 @@ func init() {
|
||||
}
|
||||
|
||||
func UserRegister(user db.User) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user.CreateTime = time.Now()
|
||||
if user.AppMangerLevel == 0 {
|
||||
user.AppMangerLevel = constant.AppOrdinaryUsers
|
||||
@@ -48,7 +42,7 @@ func UserRegister(user db.User) error {
|
||||
if user.Birth.Unix() < 0 {
|
||||
user.Birth = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err = dbConn.Table("users").Create(&user).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -56,31 +50,19 @@ func UserRegister(user db.User) error {
|
||||
}
|
||||
|
||||
func DeleteUser(userID string) (i int64) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
i = dbConn.Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected
|
||||
i = db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected
|
||||
return i
|
||||
}
|
||||
|
||||
func GetAllUser() ([]db.User, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var userList []db.User
|
||||
err = dbConn.Table("users").Find(&userList).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error
|
||||
return userList, err
|
||||
}
|
||||
|
||||
func GetUserByUserID(userID string) (*db.User, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var user db.User
|
||||
err = dbConn.Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -88,12 +70,8 @@ func GetUserByUserID(userID string) (*db.User, error) {
|
||||
}
|
||||
|
||||
func GetUserNameByUserID(userID string) (string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var user db.User
|
||||
err = dbConn.Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -101,33 +79,17 @@ func GetUserNameByUserID(userID string) (string, error) {
|
||||
}
|
||||
|
||||
func UpdateUserInfo(user db.User) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
|
||||
|
||||
return err
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(&user).Error
|
||||
}
|
||||
|
||||
func UpdateUserInfoByMap(user db.User, m map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Where("user_id=?", user.UserID).Updates(m).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func SelectAllUserID() ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resultArr []string
|
||||
err = dbConn.Table("users").Pluck("user_id", &resultArr).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Pluck("user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,14 +97,8 @@ func SelectAllUserID() ([]string, error) {
|
||||
}
|
||||
|
||||
func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
dbConn.LogMode(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resultArr []string
|
||||
err = dbConn.Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error
|
||||
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -150,13 +106,8 @@ func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||
}
|
||||
|
||||
func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var users []db.User
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
@@ -164,10 +115,6 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
||||
}
|
||||
|
||||
func AddUser(userId, phoneNumber, name string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user := db.User{
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: time.Now(),
|
||||
@@ -175,17 +122,13 @@ func AddUser(userId, phoneNumber, name string) error {
|
||||
UserID: userId,
|
||||
Nickname: name,
|
||||
}
|
||||
result := dbConn.Table("users").Create(&user)
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UserIsBlock(userId string) (bool, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var user db.BlackList
|
||||
rows := dbConn.Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
if rows >= 1 {
|
||||
return true, nil
|
||||
}
|
||||
@@ -197,10 +140,6 @@ func BlockUser(userId, endDisableTime string) error {
|
||||
if err != nil || user.UserID == "" {
|
||||
return err
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
end, err := time.Parse("2006-01-02 15:04:05", endDisableTime)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -209,9 +148,9 @@ func BlockUser(userId, endDisableTime string) error {
|
||||
return constant.ErrDB
|
||||
}
|
||||
var blockUser db.BlackList
|
||||
dbConn.Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
||||
if blockUser.UserId != "" {
|
||||
dbConn.Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
return nil
|
||||
}
|
||||
blockUser = db.BlackList{
|
||||
@@ -219,18 +158,12 @@ func BlockUser(userId, endDisableTime string) error {
|
||||
BeginDisableTime: time.Now(),
|
||||
EndDisableTime: end,
|
||||
}
|
||||
result := dbConn.Create(&blockUser)
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UnBlockUser(userId string) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
|
||||
return result.Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
|
||||
}
|
||||
|
||||
type BlockUserInfo struct {
|
||||
@@ -240,21 +173,17 @@ type BlockUserInfo struct {
|
||||
}
|
||||
|
||||
func GetBlockUserById(userId string) (BlockUserInfo, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var blockUserInfo BlockUserInfo
|
||||
blockUser := db.BlackList{
|
||||
UserId: userId,
|
||||
}
|
||||
if err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
if err = dbConn.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
user := db.User{
|
||||
UserID: blockUser.UserId,
|
||||
}
|
||||
if err := dbConn.Find(&user).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil {
|
||||
return blockUserInfo, err
|
||||
}
|
||||
blockUserInfo.User.UserID = user.UserID
|
||||
@@ -266,19 +195,14 @@ func GetBlockUserById(userId string) (BlockUserInfo, error) {
|
||||
}
|
||||
|
||||
func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var blockUserInfos []BlockUserInfo
|
||||
var blockUsers []db.BlackList
|
||||
if err != nil {
|
||||
return blockUserInfos, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil {
|
||||
return blockUserInfos, err
|
||||
}
|
||||
for _, blockUser := range blockUsers {
|
||||
var user db.User
|
||||
if err := dbConn.Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil {
|
||||
blockUserInfos = append(blockUserInfos, BlockUserInfo{
|
||||
User: db.User{
|
||||
UserID: user.UserID,
|
||||
@@ -294,38 +218,23 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
||||
}
|
||||
|
||||
func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
var users []db.User
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error
|
||||
return users, err
|
||||
}
|
||||
|
||||
func GetUsersCount(user db.User) (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var count int32
|
||||
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
return int32(count), nil
|
||||
}
|
||||
|
||||
func GetBlockUsersNumCount() (int32, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Model(&db.BlackList{}).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(false)
|
||||
var count int32
|
||||
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
return int32(count), nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
@@ -19,10 +19,6 @@ import (
|
||||
)
|
||||
|
||||
func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chatLog := new(db.ChatLog)
|
||||
copier.Copy(chatLog, msg.MsgData)
|
||||
switch msg.MsgData.SessionType {
|
||||
@@ -47,5 +43,5 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime)
|
||||
chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime)
|
||||
log.NewDebug("test", "this is ", chatLog)
|
||||
return dbConn.Table("chat_logs").Create(chatLog).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Create(chatLog).Error
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package im_mysql_msg_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db"
|
||||
"hash/crc32"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func getHashMsgDBAddr(userID string) string {
|
||||
@@ -16,21 +14,3 @@ func getHashMsgTableIndex(userID string) int {
|
||||
hCode := crc32.ChecksumIEEE([]byte(userID))
|
||||
return int(hCode % uint32(config.Config.Mysql.DBMsgTableNum))
|
||||
}
|
||||
|
||||
func QueryUserMsgID(userID string) ([]string, error) {
|
||||
dbAddress, dbTableIndex := getHashMsgDBAddr(userID), getHashMsgTableIndex(userID)
|
||||
dbTableName := "receive" + strconv.Itoa(dbTableIndex)
|
||||
|
||||
dbConn, _ := db.DB.MysqlDB.GormDB(dbAddress, config.Config.Mysql.DBTableName)
|
||||
|
||||
var msgID string
|
||||
var msgIDList []string
|
||||
rows, _ := dbConn.Raw("select msg_id from ? where user_id = ?", dbTableName, userID).Rows()
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
rows.Scan(&msgID)
|
||||
msgIDList = append(msgIDList, msgID)
|
||||
}
|
||||
|
||||
return msgIDList, nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"flag"
|
||||
@@ -119,3 +119,9 @@ func Test_GetAccountCode(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(code)
|
||||
}
|
||||
func Test_GetGroupMemberList(t *testing.T) {
|
||||
groupID := "3791742301"
|
||||
list, err := DB.GetGroupMemberIDListFromCache(groupID)
|
||||
assert.Nil(t, err)
|
||||
fmt.Println(list)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
package rocksCache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
userInfoCache = "USER_INFO_CACHE:"
|
||||
friendRelationCache = "FRIEND_RELATION_CACHE:"
|
||||
blackListCache = "BLACK_LIST_CACHE:"
|
||||
groupCache = "GROUP_CACHE:"
|
||||
groupInfoCache = "GROUP_INFO_CACHE:"
|
||||
groupOwnerIDCache = "GROUP_OWNER_ID:"
|
||||
joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
|
||||
groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
|
||||
groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
|
||||
allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
|
||||
allDepartmentCache = "ALL_DEPARTMENT_CACHE:"
|
||||
allDepartmentMemberCache = "ALL_DEPARTMENT_MEMBER_CACHE:"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("init to del old keys")
|
||||
for _, key := range []string{groupCache, friendRelationCache, blackListCache, userInfoCache, groupInfoCache, groupOwnerIDCache, joinedGroupListCache,
|
||||
groupMemberInfoCache, groupAllMemberInfoCache, allFriendInfoCache} {
|
||||
var cursor uint64
|
||||
var n int
|
||||
for {
|
||||
var keys []string
|
||||
var err error
|
||||
keys, cursor, err = db.DB.RDB.Scan(context.Background(), cursor, key+"*", 3000).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
n += len(keys)
|
||||
//fmt.Printf("\n %s key found %d keys: %v, current cursor %d\n", key, n, keys, cursor)
|
||||
if len(keys) > 0 {
|
||||
err = db.DB.RDB.Del(context.Background(), keys...).Err()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetFriendIDListFromCache(userID string) ([]string, error) {
|
||||
getFriendIDList := func() (string, error) {
|
||||
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(friendIDList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second*30*60, getFriendIDList)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var friendIDList []string
|
||||
err = json.Unmarshal([]byte(friendIDListStr), &friendIDList)
|
||||
return friendIDList, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelFriendIDListFromCache(userID string) error {
|
||||
err := db.DB.Rc.TagAsDeleted(friendRelationCache + userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetBlackListFromCache(userID string) ([]string, error) {
|
||||
getBlackIDList := func() (string, error) {
|
||||
blackIDList, err := imdb.GetBlackIDListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(blackIDList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second*30*60, getBlackIDList)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var blackIDList []string
|
||||
err = json.Unmarshal([]byte(blackIDListStr), &blackIDList)
|
||||
return blackIDList, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelBlackIDListFromCache(userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(blackListCache + userID)
|
||||
}
|
||||
|
||||
func GetJoinedGroupIDListFromCache(userID string) ([]string, error) {
|
||||
getJoinedGroupIDList := func() (string, error) {
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(joinedGroupList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second*30*60, getJoinedGroupIDList)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var joinedGroupList []string
|
||||
err = json.Unmarshal([]byte(joinedGroupIDListStr), &joinedGroupList)
|
||||
return joinedGroupList, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelJoinedGroupIDListFromCache(userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID)
|
||||
}
|
||||
|
||||
func GetGroupMemberIDListFromCache(groupID string) ([]string, error) {
|
||||
getGroupMemberIDList := func() (string, error) {
|
||||
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(groupMemberIDList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second*30*60, getGroupMemberIDList)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var groupMemberIDList []string
|
||||
err = json.Unmarshal([]byte(groupIDListStr), &groupMemberIDList)
|
||||
return groupMemberIDList, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelGroupMemberIDListFromCache(userID string) error {
|
||||
err := db.DB.Rc.TagAsDeleted(groupCache + userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserInfoFromCache(userID string) (*db.User, error) {
|
||||
getUserInfo := func() (string, error) {
|
||||
userInfo, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(userInfo)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second*30*60, getUserInfo)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
userInfo := &db.User{}
|
||||
err = json.Unmarshal([]byte(userInfoStr), userInfo)
|
||||
return userInfo, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelUserInfoFromCache(userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(userInfoCache + userID)
|
||||
}
|
||||
|
||||
func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error) {
|
||||
getGroupMemberInfo := func() (string, error) {
|
||||
groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(groupMemberInfo)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second*30*60, getGroupMemberInfo)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
groupMember := &db.GroupMember{}
|
||||
err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember)
|
||||
return groupMember, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelGroupMemberInfoFromCache(groupID, userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID)
|
||||
}
|
||||
|
||||
func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) {
|
||||
getGroupMemberInfo := func() (string, error) {
|
||||
groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(groupMembers)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
groupMembersStr, err := db.DB.Rc.Fetch(groupAllMemberInfoCache+groupID, time.Second*30*60, getGroupMemberInfo)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var groupMembers []*db.GroupMember
|
||||
err = json.Unmarshal([]byte(groupMembersStr), &groupMembers)
|
||||
return groupMembers, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelAllGroupMembersInfoFromCache(groupID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID)
|
||||
}
|
||||
|
||||
func GetGroupInfoFromCache(groupID string) (*db.Group, error) {
|
||||
getGroupInfo := func() (string, error) {
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(groupInfo)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second*30*60, getGroupInfo)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
groupInfo := &db.Group{}
|
||||
err = json.Unmarshal([]byte(groupInfoStr), groupInfo)
|
||||
return groupInfo, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelGroupInfoFromCache(groupID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID)
|
||||
}
|
||||
|
||||
func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) {
|
||||
getAllFriendInfo := func() (string, error) {
|
||||
friendInfoList, err := imdb.GetFriendListByUserID(userID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(friendInfoList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second*30*60, getAllFriendInfo)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var friendInfoList []*db.Friend
|
||||
err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList)
|
||||
return friendInfoList, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelAllFriendsInfoFromCache(userID string) error {
|
||||
return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID)
|
||||
}
|
||||
|
||||
func GetAllDepartmentsFromCache() ([]db.Department, error) {
|
||||
getAllDepartments := func() (string, error) {
|
||||
departmentList, err := imdb.GetSubDepartmentList("-1")
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(departmentList)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
allDepartmentsStr, err := db.DB.Rc.Fetch(allDepartmentCache, time.Second*30*60, getAllDepartments)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var allDepartments []db.Department
|
||||
err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments)
|
||||
return allDepartments, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelAllDepartmentsFromCache() error {
|
||||
return db.DB.Rc.TagAsDeleted(allDepartmentCache)
|
||||
}
|
||||
|
||||
func GetAllDepartmentMembersFromCache() ([]db.DepartmentMember, error) {
|
||||
getAllDepartmentMembers := func() (string, error) {
|
||||
departmentMembers, err := imdb.GetDepartmentMemberList("-1")
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
bytes, err := json.Marshal(departmentMembers)
|
||||
return string(bytes), utils.Wrap(err, "")
|
||||
}
|
||||
allDepartmentMembersStr, err := db.DB.Rc.Fetch(allDepartmentMemberCache, time.Second*30*60, getAllDepartmentMembers)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
var allDepartmentMembers []db.DepartmentMember
|
||||
err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers)
|
||||
return allDepartmentMembers, utils.Wrap(err, "")
|
||||
}
|
||||
|
||||
func DelAllDepartmentMembersFromCache() error {
|
||||
return db.DB.Rc.TagAsDeleted(allDepartmentMemberCache)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user