mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 22:39:18 +08:00
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c7cb274b4 | |||
| a08c499c95 | |||
| a879bbce59 | |||
| f11f8b3e0e | |||
| 7842545627 | |||
| 2a0f8f5ce3 | |||
| 4ae3ad7abd | |||
| a16025ca95 | |||
| fdefe09187 | |||
| 06370a763c | |||
| 691e2580e5 | |||
| f40369d061 | |||
| 046c523880 | |||
| b3b7ae26cf | |||
| 49424b8b56 | |||
| 68ff4a52dc | |||
| 07c932e9e6 | |||
| cbe3abeab0 | |||
| 3d5e3ce6cf | |||
| 4efdabc1ff | |||
| 8ca495ec50 | |||
| 69aba02c9a | |||
| 42225dd35e | |||
| ad4c9fcc83 | |||
| ef4d0c3c42 | |||
| 59cc45eaab | |||
| f64c40e91f | |||
| 46d7d30089 | |||
| 48f15bb71c | |||
| ac70b1d11b | |||
| d720082644 | |||
| 1f45b642e9 | |||
| 83228d8aa6 | |||
| 34f1e50f90 | |||
| b0c518a0d6 | |||
| aa673a3a5c | |||
| 40d58f6bc2 | |||
| 7604b24ffc | |||
| a47c0c91a3 | |||
| 0232f52281 | |||
| 08eba71c8a | |||
| 577a9249d1 | |||
| ea6461bd0a | |||
| f58c94146a | |||
| 6efe13d142 | |||
| 0a8fdc6cc8 | |||
| b91b298174 | |||
| f87038622b | |||
| 8b077848bb | |||
| 2945e6f8bf | |||
| 0f760dc388 | |||
| 5a9b5db99b | |||
| 6ba51fb338 | |||
| 146aa497f9 | |||
| e7bc82d152 | |||
| 26f8172b1a | |||
| 634584400a | |||
| 7d6be79ba8 | |||
| cef208f6ef | |||
| f4921d1317 | |||
| 7f1a74b576 | |||
| 3dc11777c6 | |||
| b536165910 | |||
| 7c7aa9e7a7 |
+1
-1
Submodule cmd/Open-IM-SDK-Core updated: 7b66c0ab78...9d67999cec
+17
-4
@@ -10,20 +10,30 @@ import (
|
||||
"Open_IM/internal/api/office"
|
||||
apiThird "Open_IM/internal/api/third"
|
||||
"Open_IM/internal/api/user"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
//"syscall"
|
||||
"Open_IM/pkg/common/constant"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
f, _ := os.Create("../logs/api.log")
|
||||
gin.DefaultWriter = io.MultiWriter(f)
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(utils.CorsHandler())
|
||||
|
||||
log.Info("load config: ", config.Config)
|
||||
// user routing group, which handles user registration and login services
|
||||
userRouterGroup := r.Group("/user")
|
||||
{
|
||||
@@ -126,9 +136,12 @@ func main() {
|
||||
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
|
||||
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
||||
}
|
||||
apiThird.MinioInit()
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
go apiThird.MinioInit()
|
||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||
flag.Parse()
|
||||
r.Run(":" + strconv.Itoa(*ginPort))
|
||||
fmt.Println("start api server, port: ", *ginPort)
|
||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||
if err != nil {
|
||||
log.Error("", "run failed ", *ginPort, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/cms_api"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -11,5 +12,6 @@ func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := cms_api.NewGinRouter()
|
||||
router.Use(utils.CorsHandler())
|
||||
fmt.Println("start cms api server, port: ", 8000)
|
||||
router.Run(":" + "8000")
|
||||
}
|
||||
|
||||
@@ -2,16 +2,23 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/demo/register"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
f, _ := os.Create("../logs/api.log")
|
||||
gin.DefaultWriter = io.MultiWriter(f)
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(utils.CorsHandler())
|
||||
@@ -24,8 +31,12 @@ func main() {
|
||||
authRouterGroup.POST("/login", register.Login)
|
||||
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||
}
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
|
||||
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
||||
flag.Parse()
|
||||
r.Run(":" + strconv.Itoa(*ginPort))
|
||||
fmt.Println("start demo api server, port: ", *ginPort)
|
||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||
if err != nil {
|
||||
log.Error("", "run failed ", *ginPort, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,21 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_gateway/gate"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rpcPort := flag.Int("rpc_port", 10400, "rpc listening port")
|
||||
wsPort := flag.Int("ws_port", 17778, "ws listening port")
|
||||
flag.Parse()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort)
|
||||
gate.Init(*rpcPort, *wsPort)
|
||||
gate.Run()
|
||||
wg.Wait()
|
||||
|
||||
@@ -2,13 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_transfer/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
logic.Init()
|
||||
fmt.Println("start msg_transfer server")
|
||||
logic.Run()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -11,6 +14,8 @@ func main() {
|
||||
flag.Parse()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
fmt.Println("start push rpc server, port: ", *rpcPort)
|
||||
logic.Init(*rpcPort)
|
||||
logic.Run()
|
||||
wg.Wait()
|
||||
|
||||
@@ -2,10 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -40,27 +37,27 @@ func main() {
|
||||
// time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
// }
|
||||
//}
|
||||
for {
|
||||
uidList, err := im_mysql_model.SelectAllUserID()
|
||||
if err != nil {
|
||||
//log.NewError("999999", err.Error())
|
||||
} else {
|
||||
for _, v := range uidList {
|
||||
minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||
if err != nil {
|
||||
//log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||
continue
|
||||
} else {
|
||||
err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||
if err != nil {
|
||||
//log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//for {
|
||||
// uidList, err := im_mysql_model.SelectAllUserID()
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", err.Error())
|
||||
// } else {
|
||||
// for _, v := range uidList {
|
||||
// minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||
// continue
|
||||
// } else {
|
||||
// err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||
// }
|
||||
// }
|
||||
// time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package main
|
||||
import (
|
||||
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11000, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start cms rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcAuth "Open_IM/internal/rpc/auth"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
|
||||
flag.Parse()
|
||||
fmt.Println("start auth rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/friend"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start friend rpc server, port: ", *rpcPort)
|
||||
rpcServer := friend.NewFriendServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/group"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10500, "get RpcGroupPort from cmd,default 16000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start group rpc server, port: ", *rpcPort)
|
||||
rpcServer := group.NewGroupServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10900, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start msg cms rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcChat "Open_IM/internal/rpc/msg"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10300, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start msg rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpc "Open_IM/internal/rpc/office"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11100, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start office rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpc.NewOfficeServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/statistics"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10800, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start statistics rpc server, port: ", *rpcPort)
|
||||
rpcServer := statistics.NewStatisticsServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/user"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start user rpc server, port: ", *rpcPort)
|
||||
rpcServer := user.NewUserServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
+16
-3
@@ -92,7 +92,7 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申
|
||||
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
||||
bucket: openim
|
||||
location: us-east-1
|
||||
endpoint: http://127.0.0.1:9000
|
||||
endpoint: http://121.37.25.71:9000
|
||||
accessKeyID: user12345
|
||||
secretAccessKey: key12345
|
||||
ali: # ali oss
|
||||
@@ -165,6 +165,7 @@ longconnsvr:
|
||||
websocketMaxMsgLen: 4096
|
||||
websocketTimeOut: 10
|
||||
|
||||
## 推送只能开启一个
|
||||
push:
|
||||
tpns: #腾讯推送,暂未测试 暂不要使用
|
||||
ios:
|
||||
@@ -173,11 +174,22 @@ push:
|
||||
android:
|
||||
accessID: 111
|
||||
secretKey: 111
|
||||
enable: false
|
||||
jpns: #极光推送 在极光后台申请后,修改以下四项,必须修改
|
||||
appKey: cf47465a368f24c659608e7e
|
||||
masterSecret: 02204efe3f3832947a236ee5
|
||||
pushUrl: "https://api.jpush.cn/v3/push"
|
||||
pushIntent: "intent:#Intent;component=io.openim.app.enterprisechat/io.openim.app.enterprisechat.MainActivity;end"
|
||||
enable: true
|
||||
getui: #个推推送,暂未测试 暂不要使用
|
||||
pushUrl: "https://restapi.getui.com/v2/$appId"
|
||||
masterSecret: ""
|
||||
appKey: ""
|
||||
intent: ""
|
||||
enable: false
|
||||
|
||||
|
||||
|
||||
manager:
|
||||
#app管理员userID和对应的secret 建议修改。 用于管理后台登录,也可以用户管理后台对应的api
|
||||
appManagerUid: [ "openIM123456","openIM654321", "openIM333", "openIMAdmin"]
|
||||
@@ -588,5 +600,6 @@ demo:
|
||||
smtpAddr: "smtp.qq.com"
|
||||
smtpPort: 25 #需开放此端口 出口方向
|
||||
|
||||
|
||||
|
||||
rtc:
|
||||
port: 11300
|
||||
address: 127.0.0.1
|
||||
+1
-1
@@ -94,7 +94,7 @@ services:
|
||||
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
|
||||
|
||||
open_im_server:
|
||||
image: openim/open_im_server:v2.0.5
|
||||
image: openim/open_im_server:v2.0.7
|
||||
container_name: open_im_server
|
||||
volumes:
|
||||
- ./logs:/Open-IM-Server/logs
|
||||
|
||||
@@ -35,10 +35,16 @@ func UserRegister(c *gin.Context) {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := rpc.NewAuthClient(etcdConn)
|
||||
reply, err := client.UserRegister(context.Background(), req)
|
||||
if err != nil || reply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err, reply.CommonResp.ErrCode)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "call rpc err ", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "internal service err"})
|
||||
return
|
||||
}
|
||||
if reply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": reply.CommonResp.ErrMsg})
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
||||
|
||||
@@ -15,18 +15,21 @@ var (
|
||||
)
|
||||
|
||||
func MinioInit() {
|
||||
log.NewInfo("", utils.GetSelfFuncName())
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio)
|
||||
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "Parse ok ", config.Config.Credential.Minio)
|
||||
minioClient, err = minio.New(minioUrl.Host, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
|
||||
Secure: false,
|
||||
})
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "new ok ", config.Config.Credential.Minio)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
return
|
||||
}
|
||||
opt := minio.MakeBucketOptions{
|
||||
@@ -35,15 +38,15 @@ func MinioInit() {
|
||||
}
|
||||
err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
|
||||
if err != nil {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error())
|
||||
exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||
if err == nil && exists {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket)
|
||||
log.NewWarn(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket)
|
||||
} else {
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -53,5 +56,5 @@ func MinioInit() {
|
||||
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||
// return
|
||||
//}
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success")
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio create and set policy success")
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func GetGroupById(c *gin.Context) {
|
||||
resp.ProfilePhoto = respPb.CMSGroup.GroupInfo.FaceURL
|
||||
resp.GroupMasterName = respPb.CMSGroup.GroupMasterName
|
||||
resp.GroupMasterId = respPb.CMSGroup.GroupMasterId
|
||||
resp.IsBanChat = constant.GroupIsBanChat(respPb.CMSGroup.GroupInfo.Status)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ func GetGroups(c *gin.Context) {
|
||||
GroupMasterName: v.GroupMasterName,
|
||||
GroupMasterId: v.GroupMasterId,
|
||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||
IsBanChat: false,
|
||||
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||
IsBanPrivateChat: false,
|
||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||
})
|
||||
@@ -114,7 +115,7 @@ func GetGroupByName(c *gin.Context) {
|
||||
GroupMasterName: v.GroupMasterName,
|
||||
GroupMasterId: v.GroupMasterId,
|
||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||
IsBanChat: false,
|
||||
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||
IsBanPrivateChat: false,
|
||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||
})
|
||||
|
||||
@@ -2,8 +2,7 @@ package gate
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
||||
"Open_IM/pkg/statistics"
|
||||
"fmt"
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -21,7 +20,7 @@ var (
|
||||
|
||||
func Init(rpcPort, wsPort int) {
|
||||
//log initialization
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
|
||||
rwLock = new(sync.RWMutex)
|
||||
validate = validator.New()
|
||||
statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300)
|
||||
|
||||
@@ -6,13 +6,17 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/gorilla/websocket"
|
||||
"google.golang.org/grpc"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -200,38 +204,61 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||
nReply := new(pbChat.SendMsgResp)
|
||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg)
|
||||
if isPass {
|
||||
isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
||||
if isPass2 {
|
||||
signalResp := pbRtc.SignalResp{}
|
||||
//isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
||||
connGrpc, err := grpc.Dial(config.Config.Rtc.Address+":"+strconv.Itoa(config.Config.Rtc.Port), grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), "grpc.Dial failed", err.Error())
|
||||
ws.sendSignalMsgResp(conn, 204, "create grpc failed"+err.Error(), m, nil)
|
||||
return
|
||||
}
|
||||
rtcClient := pbRtc.NewRtcServiceClient(connGrpc)
|
||||
req := &pbRtc.SignalMessageAssembleReq{
|
||||
SignalReq: pData.(*pbRtc.SignalReq),
|
||||
OperationID: m.OperationID,
|
||||
}
|
||||
respPb, err := rtcClient.SignalMessageAssemble(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), "SignalMessageAssemble", err.Error(), config.Config.Rtc.Address+":"+strconv.Itoa(config.Config.Rtc.Port))
|
||||
ws.sendSignalMsgResp(conn, 204, "grpc SignalMessageAssemble failed: "+err.Error(), m, &signalResp)
|
||||
return
|
||||
}
|
||||
signalResp.Payload = respPb.SignalResp.Payload
|
||||
msgData := sdk_ws.MsgData{}
|
||||
utils.CopyStructFields(&msgData, respPb.MsgData)
|
||||
log.NewInfo(m.OperationID, utils.GetSelfFuncName(), respPb.String())
|
||||
if respPb.IsPass {
|
||||
pbData := pbChat.SendMsgReq{
|
||||
Token: m.Token,
|
||||
OperationID: m.OperationID,
|
||||
MsgData: msgData,
|
||||
MsgData: &msgData,
|
||||
}
|
||||
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)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, "rpc sendMsg err", err.Error())
|
||||
log.NewError(pbData.OperationID, utils.GetSelfFuncName(), "rpc sendMsg err", err.Error())
|
||||
nReply.ErrCode = 200
|
||||
nReply.ErrMsg = err.Error()
|
||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, signalResp)
|
||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, &signalResp)
|
||||
} else {
|
||||
log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String())
|
||||
ws.sendSignalMsgResp(conn, 0, "", m, signalResp)
|
||||
ws.sendSignalMsgResp(conn, 0, "", m, &signalResp)
|
||||
}
|
||||
} else {
|
||||
log.NewError(m.OperationID, isPass2, errCode2, errMsg2)
|
||||
ws.sendSignalMsgResp(conn, errCode2, errMsg2, m, signalResp)
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), respPb.IsPass, respPb.CommonResp.ErrCode, respPb.CommonResp.ErrMsg)
|
||||
ws.sendSignalMsgResp(conn, respPb.CommonResp.ErrCode, respPb.CommonResp.ErrMsg, m, &signalResp)
|
||||
}
|
||||
} else {
|
||||
ws.sendSignalMsgResp(conn, errCode, errMsg, m, nil)
|
||||
}
|
||||
|
||||
}
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, errCode int32, errMsg string, m *Req, pb *sdk_ws.SignalResp) {
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, errCode int32, errMsg string, m *Req, pb *pbRtc.SignalResp) {
|
||||
// := make(map[string]interface{})
|
||||
|
||||
log.Debug(m.OperationID, "SignalMsgResp is", pb.String())
|
||||
b, _ := proto.Marshal(pb)
|
||||
mReply := Resp{
|
||||
ReqIdentifier: m.ReqIdentifier,
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
package open_im_media
|
||||
|
||||
import (
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/jinzhu/copier"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
// Address gRPC服务地址
|
||||
Address = "127.0.0.1:11300"
|
||||
@@ -23,35 +14,35 @@ func NewMedia() *Media {
|
||||
return &Media{}
|
||||
}
|
||||
|
||||
func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
||||
var newData pbRtc.ParticipantMetaData
|
||||
copier.Copy(&newData, data)
|
||||
conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
defer conn.Close()
|
||||
c := pbRtc.NewRtcServiceClient(conn)
|
||||
req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
||||
resp, err := c.GetJoinToken(context.Background(), req)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if resp.CommonResp.ErrCode != 0 {
|
||||
return "", "", errors.New(resp.CommonResp.ErrMsg)
|
||||
}
|
||||
return resp.Jwt, resp.LiveURL, nil
|
||||
//at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
||||
//grant := &auth.VideoGrant{
|
||||
// RoomJoin: true,
|
||||
// Room: room,
|
||||
//}
|
||||
//at.AddGrant(grant).
|
||||
// SetIdentity(identity).
|
||||
// SetValidFor(time.Hour)
|
||||
//
|
||||
//return at.ToJWT()
|
||||
}
|
||||
//func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
||||
// var newData pbRtc.ParticipantMetaData
|
||||
// copier.Copy(&newData, data)
|
||||
// conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// defer conn.Close()
|
||||
// c := pbRtc.NewRtcServiceClient(conn)
|
||||
// req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
||||
// resp, err := c.GetJoinToken(context.Background(), req)
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// if resp.CommonResp.ErrCode != 0 {
|
||||
// return "", "", errors.New(resp.CommonResp.ErrMsg)
|
||||
// }
|
||||
// return resp.Jwt, resp.LiveURL, nil
|
||||
// //at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
||||
// //grant := &auth.VideoGrant{
|
||||
// // RoomJoin: true,
|
||||
// // Room: room,
|
||||
// //}
|
||||
// //at.AddGrant(grant).
|
||||
// // SetIdentity(identity).
|
||||
// // SetValidFor(time.Hour)
|
||||
// //
|
||||
// //return at.ToJWT()
|
||||
//}
|
||||
|
||||
func init() {
|
||||
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
package gate
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_gateway/gate/open_im_media"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -74,7 +72,7 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
}
|
||||
return true, 0, "", data
|
||||
case constant.WSSendSignalMsg:
|
||||
data := open_im_sdk.SignalReq{}
|
||||
data := pbRtc.SignalReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||
return false, 203, err.Error(), nil
|
||||
@@ -117,139 +115,139 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
|
||||
}
|
||||
|
||||
func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq, operationID string) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) {
|
||||
var msg open_im_sdk.MsgData
|
||||
var resp open_im_sdk.SignalResp
|
||||
media := open_im_media.NewMedia()
|
||||
msg.MsgFrom = constant.UserMsgType
|
||||
msg.ContentType = constant.SignalingNotification
|
||||
reqData, e := proto.Marshal(s)
|
||||
if e != nil {
|
||||
return false, 201, e.Error(), nil, nil
|
||||
}
|
||||
msg.Content = reqData
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
options := make(map[string]bool, 6)
|
||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||
msg.Options = options
|
||||
switch payload := s.Payload.(type) {
|
||||
case *open_im_sdk.SignalReq_Invite:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
||||
if err2 != nil {
|
||||
return false, 202, err2.Error(), nil, nil
|
||||
}
|
||||
invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||
Token: token,
|
||||
RoomID: payload.Invite.Invitation.RoomID,
|
||||
LiveURL: liveURL,
|
||||
}}
|
||||
resp.Payload = &invite
|
||||
msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||
msg.SessionType = payload.Invite.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||
msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||
if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||
} else {
|
||||
return false, 203, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_InviteInGroup:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
||||
if err2 != nil {
|
||||
return false, 204, err2.Error(), nil, nil
|
||||
}
|
||||
inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||
RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||
Token: token,
|
||||
LiveURL: liveURL,
|
||||
}}
|
||||
resp.Payload = &inviteGroup
|
||||
msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||
msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||
msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||
if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||
} else {
|
||||
return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_Cancel:
|
||||
cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
||||
resp.Payload = &cancel
|
||||
msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
||||
msg.SendID = payload.Cancel.Invitation.InviterUserID
|
||||
msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
||||
msg.SessionType = payload.Cancel.Invitation.SessionType
|
||||
if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Cancel.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Cancel.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_Accept:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
||||
if err2 != nil {
|
||||
return false, 207, err2.Error(), nil, nil
|
||||
}
|
||||
accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
||||
Token: token,
|
||||
LiveURL: liveURL,
|
||||
RoomID: payload.Accept.Invitation.RoomID,
|
||||
}}
|
||||
resp.Payload = &accept
|
||||
msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
||||
msg.SendID = payload.Accept.OpUserID
|
||||
msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
||||
msg.SessionType = payload.Accept.Invitation.SessionType
|
||||
if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Accept.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Accept.Invitation.InviterUserID
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Accept.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_HungUp:
|
||||
case *open_im_sdk.SignalReq_Reject:
|
||||
reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
||||
resp.Payload = &reject
|
||||
msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
||||
msg.SendID = payload.Reject.OpUserID
|
||||
msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
||||
msg.SessionType = payload.Reject.Invitation.SessionType
|
||||
if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Reject.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Reject.Invitation.InviterUserID
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Reject.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
}
|
||||
return false, 210, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
//func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq, operationID string) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) {
|
||||
// var msg open_im_sdk.MsgData
|
||||
// var resp open_im_sdk.SignalResp
|
||||
// media := open_im_media.NewMedia()
|
||||
// msg.MsgFrom = constant.UserMsgType
|
||||
// msg.ContentType = constant.SignalingNotification
|
||||
// reqData, e := proto.Marshal(s)
|
||||
// if e != nil {
|
||||
// return false, 201, e.Error(), nil, nil
|
||||
// }
|
||||
// msg.Content = reqData
|
||||
// msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
// options := make(map[string]bool, 6)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||
// msg.Options = options
|
||||
// switch payload := s.Payload.(type) {
|
||||
// case *open_im_sdk.SignalReq_Invite:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 202, err2.Error(), nil, nil
|
||||
// }
|
||||
// invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||
// Token: token,
|
||||
// RoomID: payload.Invite.Invitation.RoomID,
|
||||
// LiveURL: liveURL,
|
||||
// }}
|
||||
// resp.Payload = &invite
|
||||
// msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Invite.Invitation.SessionType
|
||||
// msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||
// msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||
// if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||
// msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||
// } else {
|
||||
// return false, 203, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_InviteInGroup:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 204, err2.Error(), nil, nil
|
||||
// }
|
||||
// inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||
// RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||
// Token: token,
|
||||
// LiveURL: liveURL,
|
||||
// }}
|
||||
// resp.Payload = &inviteGroup
|
||||
// msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||
// msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||
// msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||
// msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||
// if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||
// msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||
// } else {
|
||||
// return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||
//
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_Cancel:
|
||||
// cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
||||
// resp.Payload = &cancel
|
||||
// msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
||||
// msg.SendID = payload.Cancel.Invitation.InviterUserID
|
||||
// msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Cancel.Invitation.SessionType
|
||||
// if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Cancel.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Cancel.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_Accept:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 207, err2.Error(), nil, nil
|
||||
// }
|
||||
// accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
||||
// Token: token,
|
||||
// LiveURL: liveURL,
|
||||
// RoomID: payload.Accept.Invitation.RoomID,
|
||||
// }}
|
||||
// resp.Payload = &accept
|
||||
// msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
||||
// msg.SendID = payload.Accept.OpUserID
|
||||
// msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Accept.Invitation.SessionType
|
||||
// if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Accept.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Accept.Invitation.InviterUserID
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Accept.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_HungUp:
|
||||
// case *open_im_sdk.SignalReq_Reject:
|
||||
// reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
||||
// resp.Payload = &reject
|
||||
// msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
||||
// msg.SendID = payload.Reject.OpUserID
|
||||
// msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Reject.Invitation.SessionType
|
||||
// if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Reject.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Reject.Invitation.InviterUserID
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Reject.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// }
|
||||
// return false, 210, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
//}
|
||||
|
||||
@@ -2,9 +2,8 @@ package logic
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -14,7 +13,7 @@ var (
|
||||
)
|
||||
|
||||
func Init() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
|
||||
persistentCH.Init()
|
||||
historyCH.Init()
|
||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
package getui
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
//"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
GetuiClient *Getui
|
||||
)
|
||||
|
||||
const (
|
||||
PushURL = "/push/single/cid"
|
||||
AuthURL = "/auth"
|
||||
)
|
||||
|
||||
func init() {
|
||||
GetuiClient = newGetuiClient()
|
||||
}
|
||||
|
||||
type Getui struct{}
|
||||
|
||||
type GetuiCommonResp struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type AuthReq struct {
|
||||
Sign string `json:"sign"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Appkey string `json:"appkey"`
|
||||
}
|
||||
|
||||
type AuthResp struct {
|
||||
ExpireTime string `json:"expire_time"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type PushReq struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Audience struct {
|
||||
Cid []string `json:"cid"`
|
||||
} `json:"audience"`
|
||||
PushMssage struct {
|
||||
Notification Notification `json:"notification"`
|
||||
} `json:"push_message"`
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
ClickType string `json:"click_type"`
|
||||
Intent string `json:"intent"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type PushResp struct {
|
||||
}
|
||||
|
||||
func newGetuiClient() *Getui {
|
||||
return &Getui{}
|
||||
}
|
||||
|
||||
func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error) {
|
||||
token, err := db.DB.GetGetuiToken()
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error())
|
||||
}
|
||||
if token == "" || err != nil {
|
||||
token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Auth failed")
|
||||
}
|
||||
log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err)
|
||||
err = db.DB.SetGetuiToken(token, 60*60*23)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Auth failed")
|
||||
}
|
||||
}
|
||||
pushReq := PushReq{
|
||||
RequestID: utils.OperationIDGenerator(),
|
||||
Audience: struct {
|
||||
Cid []string `json:"cid"`
|
||||
}{Cid: []string{userIDList[0]}},
|
||||
}
|
||||
pushReq.PushMssage.Notification = Notification{
|
||||
Title: alert,
|
||||
Body: alert,
|
||||
ClickType: "none",
|
||||
}
|
||||
if config.Config.Push.Getui.Intent != "" {
|
||||
pushReq.PushMssage.Notification.Intent = config.Config.Push.Getui.Intent
|
||||
pushReq.PushMssage.Notification.ClickType = "intent"
|
||||
}
|
||||
pushResp := PushResp{}
|
||||
err = g.request(PushURL, pushReq, token, &pushResp, operationID)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "push failed")
|
||||
}
|
||||
respBytes, err := json.Marshal(pushResp)
|
||||
return string(respBytes), err
|
||||
}
|
||||
|
||||
func (g *Getui) Auth(operationID string, timeStamp int64) (token string, expireTime int64, err error) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), config.Config.Push.Getui.AppKey, timeStamp, config.Config.Push.Getui.MasterSecret)
|
||||
h := sha256.New()
|
||||
h.Write([]byte(config.Config.Push.Getui.AppKey + strconv.Itoa(int(timeStamp)) + config.Config.Push.Getui.MasterSecret))
|
||||
sum := h.Sum(nil)
|
||||
sign := hex.EncodeToString(sum)
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "sha256 result", sign)
|
||||
reqAuth := AuthReq{
|
||||
Sign: sign,
|
||||
Timestamp: strconv.Itoa(int(timeStamp)),
|
||||
Appkey: config.Config.Push.Getui.AppKey,
|
||||
}
|
||||
respAuth := AuthResp{}
|
||||
err = g.request(AuthURL, reqAuth, "", &respAuth, operationID)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "result: ", respAuth)
|
||||
expire, err := strconv.Atoi(respAuth.ExpireTime)
|
||||
return respAuth.Token, int64(expire), err
|
||||
}
|
||||
|
||||
func (g *Getui) request(url string, content interface{}, token string, returnStruct interface{}, operationID string) error {
|
||||
con, err := json.Marshal(content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := &http.Client{}
|
||||
log.Debug(operationID, utils.GetSelfFuncName(), "json:", string(con))
|
||||
req, err := http.NewRequest("POST", config.Config.Push.Getui.PushUrl+url, bytes.NewBuffer(con))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if token != "" {
|
||||
req.Header.Set(token, token)
|
||||
}
|
||||
req.Header.Set("content-type", "application/json")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), "resp, ", string(result))
|
||||
if err := json.Unmarshal(result, returnStruct); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -10,11 +10,29 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type JPushResp struct {
|
||||
var (
|
||||
JPushClient *JPush
|
||||
)
|
||||
|
||||
func init() {
|
||||
JPushClient = newGetuiClient()
|
||||
}
|
||||
|
||||
func JGAccountListPush(accounts []string, alert, detailContent, platform string) ([]byte, error) {
|
||||
type JPush struct{}
|
||||
|
||||
func newGetuiClient() *JPush {
|
||||
return &JPush{}
|
||||
}
|
||||
|
||||
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (j *JPush) Push(accounts []string, alert, detailContent, platform, operationID string) (string, error) {
|
||||
var pf requestBody.Platform
|
||||
_ = pf.SetPlatform(platform)
|
||||
var au requestBody.Audience
|
||||
@@ -34,25 +52,23 @@ func JGAccountListPush(accounts []string, alert, detailContent, platform string)
|
||||
|
||||
con, err := json.Marshal(po)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", common.GetAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret))
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return result, nil
|
||||
return string(result), nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/statistics"
|
||||
"fmt"
|
||||
)
|
||||
@@ -24,7 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func Init(rpcPort int) {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
|
||||
rpcServer.Init(rpcPort)
|
||||
pushCh.Init()
|
||||
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
push "Open_IM/internal/push/jpush"
|
||||
pusher "Open_IM/internal/push"
|
||||
"Open_IM/internal/push/getui"
|
||||
jpush "Open_IM/internal/push/jpush"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
@@ -99,12 +101,22 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
||||
content = constant.ContentType2PushContent[constant.Common]
|
||||
}
|
||||
}
|
||||
|
||||
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
|
||||
var offlinePusher pusher.OfflinePusher
|
||||
if config.Config.Push.Getui.Enable {
|
||||
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
|
||||
offlinePusher = getui.GetuiClient
|
||||
}
|
||||
if config.Config.Push.Jpns.Enable {
|
||||
offlinePusher = jpush.JPushClient
|
||||
}
|
||||
if offlinePusher == nil {
|
||||
offlinePusher = jpush.JPushClient
|
||||
}
|
||||
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t), pushMsg.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
|
||||
} else {
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t))
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData, constant.PlatformIDToName(t))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package push
|
||||
|
||||
type OfflinePusher interface {
|
||||
Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error)
|
||||
}
|
||||
@@ -7,3 +7,7 @@ import (
|
||||
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func callbackAfterCreateGroup(req *pbGroup.CreateGroupReq) {
|
||||
|
||||
}
|
||||
|
||||
@@ -668,6 +668,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
||||
Status: group.Status,
|
||||
CreatorUserID: group.CreatorUserID,
|
||||
GroupType: group.GroupType,
|
||||
CreateTime: uint32(group.CreateTime.Unix()),
|
||||
}
|
||||
groupMember, err := imdb.GetGroupMaster(group.GroupID)
|
||||
if err != nil {
|
||||
@@ -677,6 +678,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
||||
resp.CMSGroup.GroupMasterName = groupMember.Nickname
|
||||
resp.CMSGroup.GroupMasterId = groupMember.UserID
|
||||
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -704,6 +706,7 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
groupMember, err := imdb.GetGroupMaster(v.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
|
||||
GroupInfo: &open_im_sdk.GroupInfo{
|
||||
@@ -713,11 +716,13 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
OwnerUserID: v.CreatorUserID,
|
||||
Status: v.Status,
|
||||
CreatorUserID: v.CreatorUserID,
|
||||
CreateTime: uint32(v.CreateTime.Unix()),
|
||||
},
|
||||
GroupMasterName: groupMember.Nickname,
|
||||
GroupMasterId: groupMember.UserID,
|
||||
})
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func (rpc *rpcChat) Run() {
|
||||
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", address)
|
||||
log.Info("", "", "listen network success, address = ", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
|
||||
@@ -3,6 +3,7 @@ package msg
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
@@ -10,23 +11,24 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TagSendMessage(operationID, sendID, recvID, content string, senderPlatformID int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", sendID, recvID, content)
|
||||
func TagSendMessage(operationID string, user *db.User, recvID, content string, senderPlatformID int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content)
|
||||
var req pbChat.SendMsgReq
|
||||
var msgData pbCommon.MsgData
|
||||
msgData.SendID = sendID
|
||||
msgData.SendID = user.UserID
|
||||
msgData.RecvID = recvID
|
||||
msgData.ContentType = constant.Custom
|
||||
msgData.SessionType = constant.SingleChatType
|
||||
msgData.MsgFrom = constant.UserMsgType
|
||||
msgData.Content = []byte(content)
|
||||
msgData.SenderFaceURL = user.FaceURL
|
||||
msgData.SenderNickname = user.Nickname
|
||||
msgData.Options = map[string]bool{}
|
||||
msgData.Options[constant.IsSenderConversationUpdate] = false
|
||||
msgData.SendTime = time.Now().Unix()
|
||||
msgData.CreateTime = time.Now().Unix()
|
||||
msgData.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
|
||||
msgData.SenderPlatformID = senderPlatformID
|
||||
req.MsgData = &msgData
|
||||
req.OperationID = operationID
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
@@ -179,8 +180,12 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList)
|
||||
us, err := imdb.GetUserByUserID(req.SendID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.SendID)
|
||||
}
|
||||
for _, userID := range userIDList {
|
||||
msg.TagSendMessage(req.OperationID, req.SendID, userID, req.Content, req.SenderPlatformID)
|
||||
msg.TagSendMessage(req.OperationID, us, userID, req.Content, req.SenderPlatformID)
|
||||
}
|
||||
var tagSendLogs db.TagSendLog
|
||||
for _, userID := range userIDList {
|
||||
|
||||
+13
-15
@@ -8,7 +8,7 @@ type GroupResponse struct {
|
||||
CreateTime string `json:"create_time"`
|
||||
IsBanChat bool `json:"is_ban_chat"`
|
||||
IsBanPrivateChat bool `json:"is_ban_private_chat"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
}
|
||||
|
||||
type GetGroupByIdRequest struct {
|
||||
@@ -63,7 +63,6 @@ type SetGroupMemberRequest struct {
|
||||
}
|
||||
|
||||
type SetGroupMemberRespones struct {
|
||||
|
||||
}
|
||||
|
||||
type BanGroupChatRequest struct {
|
||||
@@ -88,7 +87,7 @@ type DeleteGroupResponse struct {
|
||||
}
|
||||
|
||||
type GetGroupMembersRequest struct {
|
||||
GroupId string `form:"group_id" binding:"required"`
|
||||
GroupId string `form:"group_id" binding:"required"`
|
||||
UserName string `form:"user_name"`
|
||||
RequestPagination
|
||||
}
|
||||
@@ -96,24 +95,24 @@ type GetGroupMembersRequest struct {
|
||||
type GroupMemberResponse struct {
|
||||
MemberPosition int `json:"member_position"`
|
||||
MemberNickName string `json:"member_nick_name"`
|
||||
MemberId string `json:"member_id"`
|
||||
MemberId string `json:"member_id"`
|
||||
JoinTime string `json:"join_time"`
|
||||
}
|
||||
|
||||
type GetGroupMembersResponse struct {
|
||||
GroupMembers []GroupMemberResponse `json:"group_members"`
|
||||
GroupMembers []GroupMemberResponse `json:"group_members"`
|
||||
ResponsePagination
|
||||
MemberNums int `json:"member_nums"`
|
||||
}
|
||||
|
||||
type GroupMemberRequest struct {
|
||||
GroupId string `json:"group_id" binding:"required"`
|
||||
GroupId string `json:"group_id" binding:"required"`
|
||||
Members []string `json:"members" binding:"required"`
|
||||
}
|
||||
|
||||
type GroupMemberOperateResponse struct {
|
||||
Success []string `json:"success"`
|
||||
Failed []string `json:"failed"`
|
||||
Failed []string `json:"failed"`
|
||||
}
|
||||
|
||||
type AddGroupMembersRequest struct {
|
||||
@@ -128,19 +127,18 @@ type RemoveGroupMembersRequest struct {
|
||||
GroupMemberRequest
|
||||
}
|
||||
|
||||
type RemoveGroupMembersResponse struct{
|
||||
type RemoveGroupMembersResponse struct {
|
||||
GroupMemberOperateResponse
|
||||
}
|
||||
|
||||
type AlterGroupInfoRequest struct {
|
||||
GroupID string `json:"group_id"`
|
||||
GroupName string `json:"group_name"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
GroupType int `json:"group_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
GroupName string `json:"group_name"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
GroupType int `json:"group_type"`
|
||||
}
|
||||
|
||||
type AlterGroupInfoResponse struct {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -153,12 +152,21 @@ type config struct {
|
||||
AccessID string `yaml:"accessID"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
Enable bool `yaml:"enable"`
|
||||
}
|
||||
Jpns struct {
|
||||
AppKey string `yaml:"appKey"`
|
||||
MasterSecret string `yaml:"masterSecret"`
|
||||
PushUrl string `yaml:"pushUrl"`
|
||||
PushIntent string `yaml:"pushIntent"`
|
||||
Enable bool `yaml:"enable"`
|
||||
}
|
||||
Getui struct {
|
||||
PushUrl string `yaml:"pushUrl"`
|
||||
AppKey string `yaml:"appKey"`
|
||||
Enable bool `yaml:"enable"`
|
||||
Intent string `yaml:"intent"`
|
||||
MasterSecret string `yaml:"masterSecret"`
|
||||
}
|
||||
}
|
||||
Manager struct {
|
||||
@@ -377,6 +385,10 @@ type config struct {
|
||||
SmtpPort int `yaml:"smtpPort"`
|
||||
}
|
||||
}
|
||||
Rtc struct {
|
||||
Port int `yaml:"port"`
|
||||
Address string `yaml:"address"`
|
||||
} `yaml:"rtc"`
|
||||
}
|
||||
type PConversation struct {
|
||||
ReliabilityLevel int `yaml:"reliabilityLevel"`
|
||||
@@ -416,5 +428,4 @@ func init() {
|
||||
if err = yaml.Unmarshal(bytes, &Config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Println("load config: ", Config)
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ const (
|
||||
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
||||
|
||||
func GroupIsBanChat(status int32) bool {
|
||||
if status != GroupBanChat {
|
||||
if status != GroupStatusMuted {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -2,8 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
//"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@@ -34,7 +33,7 @@ func key(dbAddress, dbName string) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
//log.NewPrivateLog(constant.LogFileName)
|
||||
//var mgoSession *mgo.Session
|
||||
var mongoClient *mongo.Client
|
||||
var err1 error
|
||||
@@ -54,15 +53,16 @@ func init() {
|
||||
|
||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||
fmt.Println(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
if err1 != nil {
|
||||
log.NewError(" mongo.Connect retry failed, panic", err.Error(), uri)
|
||||
fmt.Println(" mongo.Connect retry failed, panic", err.Error(), uri)
|
||||
panic(err1.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "mongo driver client init success")
|
||||
fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success")
|
||||
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
//mgoDailInfo := &mgo.DialInfo{
|
||||
|
||||
+16
-16
@@ -2,7 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -24,13 +24,13 @@ func initMysqlDB() {
|
||||
var err1 error
|
||||
db, err := gorm.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
log.NewError("0", "Open failed ", err.Error(), dsn)
|
||||
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||
}
|
||||
if err != nil {
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
db, err1 = gorm.Open("mysql", dsn)
|
||||
if err1 != nil {
|
||||
log.NewError("0", "Open failed ", err1.Error(), dsn)
|
||||
fmt.Println("0", "Open failed ", err1.Error(), dsn)
|
||||
panic(err1.Error())
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func initMysqlDB() {
|
||||
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
||||
err = db.Exec(sql).Error
|
||||
if err != nil {
|
||||
log.NewError("0", "Exec failed ", err.Error(), sql)
|
||||
fmt.Println("0", "Exec failed ", err.Error(), sql)
|
||||
panic(err.Error())
|
||||
}
|
||||
db.Close()
|
||||
@@ -48,11 +48,11 @@ func initMysqlDB() {
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
db, err = gorm.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
log.NewError("0", "Open failed ", err.Error(), dsn)
|
||||
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
log.NewInfo("open db ok ", dsn)
|
||||
fmt.Println("open db ok ", dsn)
|
||||
db.AutoMigrate(&Friend{},
|
||||
&FriendRequest{},
|
||||
&Group{},
|
||||
@@ -64,49 +64,49 @@ func initMysqlDB() {
|
||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
|
||||
if !db.HasTable(&Friend{}) {
|
||||
log.NewInfo("CreateTable Friend")
|
||||
fmt.Println("CreateTable Friend")
|
||||
db.CreateTable(&Friend{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&FriendRequest{}) {
|
||||
log.NewInfo("CreateTable FriendRequest")
|
||||
fmt.Println("CreateTable FriendRequest")
|
||||
db.CreateTable(&FriendRequest{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&Group{}) {
|
||||
log.NewInfo("CreateTable Group")
|
||||
fmt.Println("CreateTable Group")
|
||||
db.CreateTable(&Group{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&GroupMember{}) {
|
||||
log.NewInfo("CreateTable GroupMember")
|
||||
fmt.Println("CreateTable GroupMember")
|
||||
db.CreateTable(&GroupMember{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&GroupRequest{}) {
|
||||
log.NewInfo("CreateTable GroupRequest")
|
||||
fmt.Println("CreateTable GroupRequest")
|
||||
db.CreateTable(&GroupRequest{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&User{}) {
|
||||
log.NewInfo("CreateTable User")
|
||||
fmt.Println("CreateTable User")
|
||||
db.CreateTable(&User{})
|
||||
}
|
||||
|
||||
if !db.HasTable(&Black{}) {
|
||||
log.NewInfo("CreateTable Black")
|
||||
fmt.Println("CreateTable Black")
|
||||
db.CreateTable(&Black{})
|
||||
}
|
||||
if !db.HasTable(&ChatLog{}) {
|
||||
log.NewInfo("CreateTable Black")
|
||||
fmt.Println("CreateTable Black")
|
||||
db.CreateTable(&ChatLog{})
|
||||
}
|
||||
if !db.HasTable(&Register{}) {
|
||||
log.NewInfo("CreateTable Black")
|
||||
fmt.Println("CreateTable Black")
|
||||
db.CreateTable(&Register{})
|
||||
}
|
||||
if !db.HasTable(&Conversation{}) {
|
||||
log.NewInfo("CreateTable Black")
|
||||
fmt.Println("CreateTable Black")
|
||||
db.CreateTable(&Conversation{})
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func ResetPassword(account, password string) error {
|
||||
Password: password,
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var groupMembers []db.GroupMember
|
||||
err = dbConn.Table("group_members").Select("user_id").Where("group_id=?", groupID).Find(&groupMembers).Error
|
||||
if err != nil {
|
||||
@@ -279,7 +279,7 @@ func GetGroupMembersCount(groupId, userName string) (int32, error) {
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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 {
|
||||
return count, err
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
if err != nil {
|
||||
return chatLogs, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
db := dbConn.Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
|
||||
@@ -43,7 +43,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
if err != nil {
|
||||
return count, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
db := dbConn.Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||
if chatLog.SessionType != 0 {
|
||||
@@ -65,4 +65,4 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
|
||||
err = db.Find(&chatLogs).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ func GetActiveUserNum(from, to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
@@ -21,7 +21,7 @@ func GetIncreaseUserNum(from, to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
@@ -32,7 +32,7 @@ func GetTotalUserNum() (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Count(&num).Error
|
||||
return num, err
|
||||
@@ -43,7 +43,7 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
@@ -54,7 +54,7 @@ func GetPrivateMessageNum(from, to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
@@ -65,7 +65,7 @@ func GetGroupMessageNum(from, to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
@@ -76,7 +76,7 @@ func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
return num, err
|
||||
@@ -87,7 +87,7 @@ func GetTotalGroupNum() (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Count(&num).Error
|
||||
return num, err
|
||||
@@ -98,7 +98,7 @@ func GetGroupNum(to time.Time) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var num int32
|
||||
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
||||
return num, err
|
||||
@@ -116,7 +116,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
||||
if err != nil {
|
||||
return activeGroups, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
for _, activeGroup := range activeGroups {
|
||||
group := db.Group{
|
||||
@@ -140,7 +140,7 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
|
||||
if err != nil {
|
||||
return activeUsers, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
for _, activeUser := range activeUsers {
|
||||
user := db.User{
|
||||
|
||||
@@ -92,7 +92,7 @@ func UpdateUserInfo(user db.User) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
|
||||
return err
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func SelectAllUserID() ([]string, error) {
|
||||
|
||||
func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||
if err != nil {
|
||||
return users, err
|
||||
@@ -204,7 +204,7 @@ func UnBlockUser(userId string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
|
||||
return result.Error
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
||||
if err != nil {
|
||||
return blockUserInfos, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
|
||||
return blockUserInfos, err
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, er
|
||||
if err != nil {
|
||||
return users, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||
return users, err
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func GetUsersCount(user db.User) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
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
|
||||
@@ -298,7 +298,7 @@ func GetBlockUsersNumCount() (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
var count int32
|
||||
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
@@ -311,7 +311,7 @@ func SetConversation(conversation db.Conversation) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
@@ -330,7 +330,7 @@ func PeerUserSetConversation(conversation db.Conversation) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
@@ -349,7 +349,7 @@ func SetRecvMsgOpt(conversation db.Conversation) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
@@ -369,7 +369,7 @@ func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
dbConn.LogMode(false)
|
||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ const (
|
||||
userMinSeq = "REDIS_USER_MIN_SEQ:"
|
||||
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
||||
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
|
||||
GetuiToken = "GETUI"
|
||||
)
|
||||
|
||||
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
|
||||
@@ -144,3 +145,13 @@ func (d *DataBases) GetMultiConversationMsgOpt(userID string, conversationIDs []
|
||||
return m, nil
|
||||
|
||||
}
|
||||
|
||||
func (d *DataBases) SetGetuiToken(token string, expireTime int64) error {
|
||||
_, err := d.Exec("SET", GetuiToken, token, "ex", expireTime)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetGetuiToken() (string, error) {
|
||||
result, err := redis.String(d.Exec("GET", GetuiToken))
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ func RespHttp200(ctx *gin.Context, err error, data interface{}) {
|
||||
}
|
||||
|
||||
// warp error
|
||||
func WrapError(err constant.ErrInfo) error {
|
||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
|
||||
func WrapError(err constant.ErrInfo, msg ...string) error {
|
||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg+msg[0])
|
||||
}
|
||||
|
||||
+2232
-177
File diff suppressed because it is too large
Load Diff
+153
-3
@@ -1,12 +1,34 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "./rtc;rtc";
|
||||
package rtc;
|
||||
package proto;
|
||||
|
||||
message CommonResp{
|
||||
int32 errCode = 1;
|
||||
string errMsg = 2;
|
||||
}
|
||||
|
||||
message MsgData {
|
||||
string sendID = 1;
|
||||
string recvID = 2;
|
||||
string groupID = 3;
|
||||
string clientMsgID = 4;
|
||||
string serverMsgID = 5;
|
||||
int32 senderPlatformID = 6;
|
||||
string senderNickname = 7;
|
||||
string senderFaceURL = 8;
|
||||
int32 sessionType = 9;
|
||||
int32 msgFrom = 10;
|
||||
int32 contentType = 11;
|
||||
bytes content = 12;
|
||||
uint32 seq = 14;
|
||||
int64 sendTime = 15;
|
||||
int64 createTime = 16;
|
||||
int32 status = 17;
|
||||
map<string, bool> options = 18;
|
||||
OfflinePushInfo offlinePushInfo = 19;
|
||||
}
|
||||
|
||||
|
||||
message GroupInfo{
|
||||
string groupID = 1;
|
||||
string groupName = 2;
|
||||
@@ -62,8 +84,136 @@ message GetJoinTokenResp{
|
||||
string liveURL = 3;
|
||||
}
|
||||
|
||||
service RtcService {
|
||||
rpc GetJoinToken(GetJoinTokenReq) returns(GetJoinTokenResp);
|
||||
message OfflinePushInfo{
|
||||
string title = 1;
|
||||
string desc = 2;
|
||||
string ex = 3;
|
||||
string iOSPushSound = 4;
|
||||
bool iOSBadgeCount = 5;
|
||||
}
|
||||
|
||||
message SignalReq {
|
||||
oneof payload {
|
||||
SignalInviteReq invite = 1;
|
||||
SignalInviteInGroupReq inviteInGroup= 2;
|
||||
SignalCancelReq cancel = 3;
|
||||
SignalAcceptReq accept = 4;
|
||||
SignalHungUpReq hungUp = 5;
|
||||
SignalRejectReq reject = 6;
|
||||
}
|
||||
}
|
||||
|
||||
message SignalResp {
|
||||
oneof payload {
|
||||
SignalInviteReply invite = 1;
|
||||
SignalInviteInGroupReply inviteInGroup= 2;
|
||||
SignalCancelReply cancel = 3;
|
||||
SignalAcceptReply accept = 4;
|
||||
SignalHungUpReply hungUp = 5;
|
||||
SignalRejectReply reject = 6;
|
||||
}
|
||||
}
|
||||
|
||||
message InvitationInfo {
|
||||
string inviterUserID = 1;
|
||||
repeated string inviteeUserIDList = 2;
|
||||
string customData = 3;
|
||||
string groupID = 4;
|
||||
string roomID = 5;
|
||||
int32 timeout = 6;
|
||||
string mediaType = 7;
|
||||
int32 platformID = 8;
|
||||
int32 sessionType = 9;
|
||||
}
|
||||
|
||||
|
||||
message SignalInviteReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
ParticipantMetaData participant = 4;
|
||||
|
||||
}
|
||||
|
||||
message SignalInviteReply {
|
||||
string token = 1;
|
||||
string roomID = 2;
|
||||
string liveURL = 3;
|
||||
}
|
||||
|
||||
message SignalInviteInGroupReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
ParticipantMetaData participant = 4;
|
||||
}
|
||||
|
||||
message SignalInviteInGroupReply {
|
||||
string token = 1;
|
||||
string roomID = 2;
|
||||
string liveURL = 3;
|
||||
}
|
||||
|
||||
message SignalCancelReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
ParticipantMetaData participant = 4;
|
||||
}
|
||||
|
||||
message SignalCancelReply {
|
||||
|
||||
}
|
||||
|
||||
message SignalAcceptReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
ParticipantMetaData participant = 4;
|
||||
int32 opUserPlatformID = 5;
|
||||
}
|
||||
|
||||
message SignalAcceptReply {
|
||||
string token = 1;
|
||||
string roomID = 2;
|
||||
string liveURL = 3;
|
||||
}
|
||||
|
||||
message SignalHungUpReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
}
|
||||
|
||||
message SignalHungUpReply {
|
||||
|
||||
}
|
||||
|
||||
|
||||
message SignalRejectReq {
|
||||
string opUserID = 1;
|
||||
InvitationInfo invitation = 2;
|
||||
OfflinePushInfo offlinePushInfo = 3;
|
||||
ParticipantMetaData participant = 4;
|
||||
int32 opUserPlatformID = 5;
|
||||
}
|
||||
|
||||
message SignalRejectReply {
|
||||
|
||||
}
|
||||
|
||||
message SignalMessageAssembleReq {
|
||||
SignalReq signalReq = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message SignalMessageAssembleResp {
|
||||
CommonResp commonResp = 1;
|
||||
bool isPass = 2;
|
||||
SignalResp signalResp = 3;
|
||||
MsgData msgData = 4;
|
||||
}
|
||||
|
||||
service RtcService {
|
||||
rpc SignalMessageAssemble(SignalMessageAssembleReq) returns(SignalMessageAssembleResp);
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ message DelMsgListReq{
|
||||
}
|
||||
|
||||
message DelMsgListResp{
|
||||
int32 errCode = 1;
|
||||
int32 errCode = 1;
|
||||
string errMsg = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ func cleanUpFuncName(funcName string) string {
|
||||
}
|
||||
return funcName[end+1:]
|
||||
}
|
||||
|
||||
//Get the intersection of two slices
|
||||
func Intersect(slice1, slice2 []uint32) []uint32 {
|
||||
m := make(map[uint32]bool)
|
||||
n := make([]uint32, 0)
|
||||
@@ -53,6 +55,8 @@ func Intersect(slice1, slice2 []uint32) []uint32 {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
//Get the diff of two slices
|
||||
func Difference(slice1, slice2 []uint32) []uint32 {
|
||||
m := make(map[uint32]bool)
|
||||
n := make([]uint32, 0)
|
||||
|
||||
@@ -24,7 +24,13 @@ begin_path=$PWD
|
||||
for ((i = 0; i < ${#service_source_root[*]}; i++)); do
|
||||
cd $begin_path
|
||||
service_path=${service_source_root[$i]}
|
||||
cd $service_path && echo -e "${SKY_BLUE_PREFIX}Current directory: $PWD $COLOR_SUFFIX"
|
||||
make install && echo -e "${SKY_BLUE_PREFIX}build ${service_names[$i]} success,moving binary file to the bin directory${COLOR_SUFFIX}" &&
|
||||
echo -e "${SKY_BLUE_PREFIX}Successful moved ${service_names[$i]} to the bin directory${COLOR_SUFFIX}\n"
|
||||
cd $service_path
|
||||
make install
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${RED_PREFIX}${service_names[$i]} build failed ${COLOR_SUFFIX}\n"
|
||||
exit -1
|
||||
else
|
||||
echo -e "${GREEN_PREFIX}${service_names[$i]} successfully be built ${COLOR_SUFFIX}\n"
|
||||
fi
|
||||
done
|
||||
echo -e ${YELLOW_PREFIX}"all services build success"${COLOR_SUFFIX}
|
||||
|
||||
@@ -9,14 +9,20 @@ need_to_start_server_shell=(
|
||||
push_start.sh
|
||||
msg_transfer_start.sh
|
||||
sdk_svr_start.sh
|
||||
timer_start.sh
|
||||
demo_svr_start.sh
|
||||
)
|
||||
|
||||
#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started
|
||||
|
||||
sleep 10
|
||||
|
||||
time=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========server start time:${time}===========">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
for i in ${need_to_start_server_shell[*]}; do
|
||||
chmod +x $i
|
||||
./$i
|
||||
|
||||
+27
-3
@@ -1,12 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
source ./style_info.cfg
|
||||
echo -e "check environment......................................."
|
||||
|
||||
echo -e "check login user........................................"
|
||||
user=`whoami`
|
||||
if [ $user == "root" ] ; then
|
||||
echo -e ${GREEN_PREFIX} "ok: login user is root" ${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${RED_PREFIX}"Warning: The current user is not root "${COLOR_SUFFIX}
|
||||
fi
|
||||
|
||||
|
||||
|
||||
echo -e "check docker............................................"
|
||||
docker_running=`systemctl status docker | grep running | grep active | wc -l`
|
||||
|
||||
docker_version=`docker-compose -v; docker -v`
|
||||
|
||||
if [ $docker_running -gt 0 ]; then
|
||||
echo -e ${GREEN_PREFIX} "ok: docker is running" ${COLOR_SUFFIX}
|
||||
echo -e ${GREEN_PREFIX} $docker_version ${COLOR_SUFFIX}
|
||||
|
||||
else
|
||||
echo -e ${RED_PREFIX}"docker not running"${COLOR_SUFFIX}
|
||||
fi
|
||||
|
||||
|
||||
echo -e "check environment......................................."
|
||||
SYSTEM=`uname -s`
|
||||
if [ $SYSTEM != "Linux" ] ; then
|
||||
echo -e ${RED_PREFIX}"Warning: Currently only Linux is supported"${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${GREEN_PREFIX} "Linux system is ok"${COLOR_SUFFIX}
|
||||
echo -e ${GREEN_PREFIX} "ok: system is linux"${COLOR_SUFFIX}
|
||||
fi
|
||||
|
||||
echo -e "check memory............................................"
|
||||
@@ -15,5 +39,5 @@ if [ $available -lt 2000 ] ; then
|
||||
echo -e ${RED_PREFIX}"Warning: Your memory not enough, available is: " "$available"m${COLOR_SUFFIX}"\c"
|
||||
echo -e ${RED_PREFIX}", must be greater than 2000m"${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${GREEN_PREFIX} "Memory is ok, available is: "$available"m${COLOR_SUFFIX}"
|
||||
echo -e ${GREEN_PREFIX} "ok: available memory is: "$available"m${COLOR_SUFFIX}"
|
||||
fi
|
||||
|
||||
@@ -14,7 +14,7 @@ ws_ports=($ports_array)
|
||||
if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then
|
||||
|
||||
echo -e ${RED_PREFIX}"ws_ports does not match push_rpc_ports in quantity!!!"${COLOR_SUFFIX}
|
||||
exit 0
|
||||
exit -1
|
||||
|
||||
fi
|
||||
#Check if the service exists
|
||||
|
||||
@@ -11,8 +11,19 @@ need_to_start_server_shell=(
|
||||
sdk_svr_start.sh
|
||||
demo_svr_start.sh
|
||||
)
|
||||
time=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========server start time:${time}===========">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>../logs/openIM.log 2>&1 &
|
||||
|
||||
for i in ${need_to_start_server_shell[*]}; do
|
||||
chmod +x $i
|
||||
./$i
|
||||
if [ $? -ne 0 ]; then
|
||||
exit -1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -45,24 +45,23 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
|
||||
|
||||
if [ $(eval ${count}) -gt 0 ]; then
|
||||
pid="${service_name}| awk '{print \$2}'"
|
||||
echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} service has been started,pid:$(eval $pid)$COLOR_SUFFIX"
|
||||
echo -e "${SKY_BLUE_PREFIX}Killing the service ${service_filename[$i]} pid:$(eval $pid)${COLOR_SUFFIX}"
|
||||
echo "${service_filename[$i]} service has been started,pid:$(eval $pid)"
|
||||
echo "killing the service ${service_filename[$i]} pid:$(eval $pid)"
|
||||
#kill the service that existed
|
||||
kill -9 $(eval $pid)
|
||||
sleep 0.5
|
||||
fi
|
||||
cd ../bin && echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} service is starting${COLOR_SUFFIX}"
|
||||
cd ../bin
|
||||
#Get the rpc port in the configuration file
|
||||
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||
list_to_string ${portList}
|
||||
#Start related rpc services based on the number of ports
|
||||
for j in ${ports_array}; do
|
||||
echo -e "${SKY_BLUE_PREFIX}${service_filename[$i]} Service is starting,port number:$j $COLOR_SUFFIX"
|
||||
#Start the service in the background
|
||||
# ./${service_filename[$i]} -port $j &
|
||||
nohup ./${service_filename[$i]} -port $j >>../logs/openIM.log 2>&1 &
|
||||
sleep 1
|
||||
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
|
||||
echo -e "${RED_PREFIX}${service_filename[$i]} Service is started,port number:$j pid:$(eval $pid)$COLOR_SUFFIX"
|
||||
echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:$j pid:$(eval $pid)$COLOR_SUFFIX"
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user