mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-29 14:59:19 +08:00
Compare commits
184 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 | |||
| 2b03b57b5c | |||
| 77c6120014 | |||
| b82ff7b88d | |||
| a16a75230c | |||
| 0e27b302bc | |||
| c369ab9b1c | |||
| bb267ccae7 | |||
| efe24658a4 | |||
| 5cdf9e7551 | |||
| 4390302384 | |||
| dab00e7fb2 | |||
| 929c5e7a5b | |||
| d600042110 | |||
| 0a58e7433e | |||
| 5639c985df | |||
| 9fbfbfb23b | |||
| ecd2f0e2bf | |||
| 60418276bd | |||
| 170392f0bc | |||
| 6744745152 | |||
| 009ae6a235 | |||
| bf5f72c00b | |||
| 84aca5b9e1 | |||
| 6164266870 | |||
| cc9df9c586 | |||
| 29a268d476 | |||
| 18d7aab703 | |||
| 373e6b6c8e | |||
| 71fab4f6be | |||
| de55c14a16 | |||
| e8517e954d | |||
| 78281fc82c | |||
| bc260fffde | |||
| db00a08bdc | |||
| 85cf7f26ce | |||
| acca147ff2 | |||
| d53da0e422 | |||
| 11eaaab72d | |||
| 475e64fc5b | |||
| 1bd8154ac4 | |||
| d2fa0e7852 | |||
| f2b324abc2 | |||
| d2225dd841 | |||
| 8d26aa86b9 | |||
| 7e937d7d29 | |||
| fe4b534b78 | |||
| d0a65c7c68 | |||
| 416f87f4bb | |||
| 7eeb67be28 | |||
| 7ed6ee5075 | |||
| d3c8215e15 | |||
| 30bc6c274e | |||
| ecb1068f0b | |||
| f6eef21b45 | |||
| 1aeff25316 | |||
| 6de569537f | |||
| 764bc3fead | |||
| a89d617532 | |||
| fef33795d0 | |||
| d2c04b761d | |||
| c5828aba91 | |||
| 1286f9dcb6 | |||
| 391e525fc5 | |||
| afc32b1cfa | |||
| 0797181967 | |||
| 14c5e631ff | |||
| 5cdb039c33 | |||
| a11c4fcb58 | |||
| c67a937d40 | |||
| 03fa7137b9 | |||
| e95400988e | |||
| 942c9c6a63 | |||
| 6c45665fde | |||
| d92ac8f588 | |||
| 169665da32 | |||
| c4d80b4844 | |||
| 7827749453 | |||
| 5e78697a69 | |||
| a0e6a78496 | |||
| af99a93536 | |||
| e9ea117985 | |||
| b9ddb0140f | |||
| dae70371d1 | |||
| 228cbb4082 | |||
| 679c913f3a | |||
| 03fb7947c3 | |||
| c39f5a27b2 | |||
| dbdb516f3c | |||
| c1a97b7356 | |||
| a6d8f7ea24 | |||
| 574c7600e0 | |||
| d1c0205d77 | |||
| 13c29d2c1e | |||
| dc1a0f050e | |||
| e252a00d55 | |||
| 5bedbb7c7d | |||
| e510418152 | |||
| 8197ae6aa7 | |||
| 9d619d520d | |||
| 46605479e9 | |||
| 6d20eddd43 | |||
| c1ee2a0adb | |||
| a4788a95af | |||
| c1a210313e | |||
| ab0ed67f81 | |||
| 5d54d5b7d6 | |||
| a2b65f52f6 | |||
| c16d8da784 | |||
| a55582a018 | |||
| ea6d472002 | |||
| 3dc4290f2a | |||
| 6c43f75f9f | |||
| e0c6972bed | |||
| 1ab3e04cba | |||
| 1b8f664c8a | |||
| 7637b2bec2 | |||
| cfab49a7dd | |||
| 91b9e50fd0 | |||
| ebf7a1d40d | |||
| d3a38963ae |
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: "\U0001F41E Bug"
|
||||
about: File a bug/issue
|
||||
title: "[BUG] <title>"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Note: Please search to see if an issue already exists for the bug you encountered.
|
||||
-->
|
||||
|
||||
### Environment:
|
||||
<!-- linux? windows? or Mac?
|
||||
Example:
|
||||
- OS: Ubuntu 20.04 -->
|
||||
|
||||
### Physical Memory Capacity:
|
||||
<!-- 8G or above is better -->
|
||||
|
||||
### Docker Image:
|
||||
<!-- Did you pull the docker image before execute docker images -->
|
||||
|
||||
### Code Version:
|
||||
<!-- Did you pull code from github? Make sure the code is up to date-->
|
||||
|
||||
### Component installation:
|
||||
<!-- Has etcd, mysql, mongodb, redis or Kafka been installed on the server before Open-IM-Server deployment-->
|
||||
|
||||
|
||||
### Log File:
|
||||
<!-- view log file(logs/openIM.log) content. -->
|
||||
|
||||
|
||||
### screenshot:
|
||||
<!---->
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: Deployment issues
|
||||
about: Deployment issues
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
If you are deploying OpenIM for the first time
|
||||
|
||||
|
||||
|
||||
```
|
||||
git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd Open-IM-Server/script ; chmod +x *.sh ; ./env_check.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd .. ; docker-compose up -d
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd script ; ./docker_check_service.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: 'update '
|
||||
about: update docker image
|
||||
title: update docker image
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
```
|
||||
cd Open-IM-Server ; docker-compose down
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
git pull
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
docker-compose pull
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
chmod +x script/*.sh ; docker-compose up -d
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd script ; ./docker_check_service.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
@@ -7,6 +7,7 @@ out-test
|
||||
.github
|
||||
.idea
|
||||
|
||||
|
||||
deploy/open_im_demo
|
||||
deploy/open_im_api
|
||||
deploy/open_im_msg_gateway
|
||||
|
||||
@@ -92,6 +92,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
|
||||
4. Start docker-compose with one click(Docker automatically pulls all images)
|
||||
|
||||
```
|
||||
cd Open-IM-Server
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
@@ -99,6 +100,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
|
||||
|
||||
```
|
||||
./docker_check_service.sh
|
||||
./check_all.sh
|
||||
```
|
||||
|
||||

|
||||
|
||||
+1
-1
Submodule cmd/Open-IM-SDK-Core updated: a06dfeeda5...9d67999cec
+32
-4
@@ -7,21 +7,33 @@ import (
|
||||
"Open_IM/internal/api/friend"
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/api/manage"
|
||||
"Open_IM/internal/api/office"
|
||||
apiThird "Open_IM/internal/api/third"
|
||||
"Open_IM/internal/api/user"
|
||||
"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")
|
||||
{
|
||||
@@ -66,7 +78,11 @@ func main() {
|
||||
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
|
||||
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
|
||||
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList) //1
|
||||
groupRouterGroup.POST("/dismiss_group", group.DismissGroup)
|
||||
groupRouterGroup.POST("/dismiss_group", group.DismissGroup) //
|
||||
groupRouterGroup.POST("/mute_group_member", group.MuteGroupMember)
|
||||
groupRouterGroup.POST("/cancel_mute_group_member", group.CancelMuteGroupMember) //MuteGroup
|
||||
groupRouterGroup.POST("/mute_group", group.MuteGroup)
|
||||
groupRouterGroup.POST("/cancel_mute_group", group.CancelMuteGroup)
|
||||
}
|
||||
//certificate
|
||||
authRouterGroup := r.Group("/auth")
|
||||
@@ -78,6 +94,7 @@ func main() {
|
||||
thirdGroup := r.Group("/third")
|
||||
{
|
||||
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
|
||||
thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential)
|
||||
thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential)
|
||||
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
|
||||
}
|
||||
@@ -108,12 +125,23 @@ func main() {
|
||||
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
||||
}
|
||||
apiThird.MinioInit()
|
||||
log.NewPrivateLog("api")
|
||||
// office
|
||||
officeGroup := r.Group("/office")
|
||||
{
|
||||
officeGroup.POST("/get_user_tags", office.GetUserTags)
|
||||
officeGroup.POST("/get_user_tag_by_id", office.GetUserTagByID)
|
||||
officeGroup.POST("/create_tag", office.CreateTag)
|
||||
officeGroup.POST("/delete_tag", office.DeleteTag)
|
||||
officeGroup.POST("/set_tag", office.SetTag)
|
||||
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
|
||||
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
||||
}
|
||||
go apiThird.MinioInit()
|
||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start api server, port: ", *ginPort)
|
||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "start gin failed", err.Error())
|
||||
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,15 +2,23 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/demo/register"
|
||||
"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())
|
||||
@@ -23,8 +31,12 @@ func main() {
|
||||
authRouterGroup.POST("/login", register.Login)
|
||||
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||
}
|
||||
log.NewPrivateLog("demo")
|
||||
|
||||
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()
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog("timer")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
//for {
|
||||
// fmt.Println("start delete mongodb expired record")
|
||||
// timeUnixBegin := time.Now().Unix()
|
||||
@@ -39,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()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_office
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
||||
@@ -0,0 +1,15 @@
|
||||
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()
|
||||
}
|
||||
|
||||
+95
-4
@@ -19,7 +19,8 @@ mysql:
|
||||
dbMaxLifeTime: 120
|
||||
|
||||
mongo:
|
||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||
dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可
|
||||
dbDirect: false
|
||||
dbTimeout: 10
|
||||
dbDatabase: openIM #mongo db 默认即可
|
||||
@@ -72,6 +73,7 @@ endpoints:
|
||||
rpc_statistic: openim_rpc_statistic
|
||||
rpc_admin_cms: openim_rpc_admin_cms
|
||||
rpc_message_cms: openim_rpc_admin_cms
|
||||
rpc_office: openim_rpc_office
|
||||
|
||||
api:
|
||||
openImApiPort: [ 10000 ] #api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
@@ -90,9 +92,20 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申
|
||||
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
||||
bucket: openim
|
||||
location: us-east-1
|
||||
endpoint: http://43.128.5.63:9000
|
||||
endpoint: http://121.37.25.71:9000
|
||||
accessKeyID: user12345
|
||||
secretAccessKey: key12345
|
||||
ali: # ali oss
|
||||
regionID: "oss-cn-beijing"
|
||||
accessKeyID: ""
|
||||
accessKeySecret: ""
|
||||
stsEndpoint: "sts.cn-beijing.aliyun.com"
|
||||
ossEndpoint: "oss-cn-beijing.aliyuncs.com"
|
||||
bucket: "bucket1"
|
||||
finalHost: "http://bucket1.oss-cn-beijing.aliyuncs.com"
|
||||
stsDurationSeconds: 3600
|
||||
OssRoleArn: "acs:ram::xxx:role/xxx"
|
||||
|
||||
|
||||
|
||||
rpcport: #rpc服务端口 默认即可
|
||||
@@ -106,6 +119,7 @@ rpcport: #rpc服务端口 默认即可
|
||||
openImStatisticsPort: [ 10800 ]
|
||||
openImMessageCmsPort: [ 10900 ]
|
||||
openImAdminCmsPort: [ 11000 ]
|
||||
openImOfficePort: [ 11100 ]
|
||||
c2c:
|
||||
callbackBeforeSendMsg:
|
||||
switch: false
|
||||
@@ -127,6 +141,7 @@ rpcregistername: #rpc注册服务名,默认即可
|
||||
OpenImStatisticsName: Statistics
|
||||
OpenImMessageCMSName: MessageCMS
|
||||
openImAdminCMSName: AdminCMS
|
||||
openImOfficeName: Office
|
||||
|
||||
log:
|
||||
storageLocation: ../logs/
|
||||
@@ -150,6 +165,7 @@ longconnsvr:
|
||||
websocketMaxMsgLen: 4096
|
||||
websocketTimeOut: 10
|
||||
|
||||
## 推送只能开启一个
|
||||
push:
|
||||
tpns: #腾讯推送,暂未测试 暂不要使用
|
||||
ios:
|
||||
@@ -158,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"]
|
||||
@@ -351,6 +378,56 @@ notification:
|
||||
ext: "groupDismissed ext"
|
||||
defaultTips:
|
||||
tips: "group dismissed"
|
||||
|
||||
|
||||
groupMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMuted title"
|
||||
desc: "groupMuted desc"
|
||||
ext: "groupMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Muted"
|
||||
|
||||
groupCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupCancelMuted title"
|
||||
desc: "groupCancelMuted desc"
|
||||
ext: "groupCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Cancel Muted"
|
||||
|
||||
|
||||
groupMemberMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberMuted title"
|
||||
desc: "groupMemberMuted desc"
|
||||
ext: "groupMemberMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Muted"
|
||||
|
||||
groupMemberCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberCancelMuted title"
|
||||
desc: "groupMemberCancelMuted desc"
|
||||
ext: "groupMemberCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Cancel Muted"
|
||||
#############################friend#################################
|
||||
|
||||
friendApplicationAdded:
|
||||
@@ -486,6 +563,19 @@ notification:
|
||||
defaultTips:
|
||||
tips: "conversation opt update"
|
||||
|
||||
conversationSetPrivate:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: true
|
||||
title: "burn after reading"
|
||||
desc: "burn after reading"
|
||||
ext: "burn after reading"
|
||||
defaultTips:
|
||||
openTips: "burn after reading was opened"
|
||||
closeTips: "burn after reading was closed"
|
||||
|
||||
|
||||
|
||||
#---------------demo configuration---------------------#
|
||||
@@ -510,5 +600,6 @@ demo:
|
||||
smtpAddr: "smtp.qq.com"
|
||||
smtpPort: 25 #需开放此端口 出口方向
|
||||
|
||||
|
||||
|
||||
rtc:
|
||||
port: 11300
|
||||
address: 127.0.0.1
|
||||
@@ -19,6 +19,7 @@ mysql:
|
||||
dbMaxLifeTime: 120
|
||||
|
||||
mongo:
|
||||
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||
dbAddress: [ openim_mongo:27017 ]
|
||||
dbDirect: false
|
||||
dbTimeout: 10
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ services:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=openIM
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=openIM
|
||||
|
||||
|
||||
#TZ: Asia/Shanghai
|
||||
restart: always
|
||||
|
||||
@@ -93,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.2
|
||||
image: openim/open_im_server:v2.0.7
|
||||
container_name: open_im_server
|
||||
volumes:
|
||||
- ./logs:/Open-IM-Server/logs
|
||||
|
||||
@@ -7,6 +7,7 @@ require (
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0
|
||||
github.com/alibabacloud-go/tea v1.1.17
|
||||
github.com/antonfisher/nested-logrus-formatter v1.3.0
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
@@ -21,7 +22,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.7.0
|
||||
github.com/go-playground/validator/v10 v10.4.1
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // 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/golang/snappy v0.0.4 // indirect
|
||||
@@ -59,6 +60,7 @@ require (
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
|
||||
@@ -53,6 +53,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.7/go.mod h1:6FV1Bt1AItYIlC2rVopPTumrRNtkfPBmrPVAZ8v2bLk=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU=
|
||||
github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA=
|
||||
@@ -62,8 +63,11 @@ github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 h1:KXMiCg99Jx7B6V+DlRFbWw
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8/go.mod h1:8aL6tSyQIWJygF7W/Vqxdf/QDbN2S+u57k36bEA8hD8=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.8/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0 h1:1yVyKz02ES6aKo3xVjmoPLBH1OAmmSqPkhKRdjEkmYs=
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0/go.mod h1:QW4O/c7Hp4krHYt+6xwnoG8EyZW3V9GYkl6EgIBmxJc=
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
@@ -1095,6 +1099,8 @@ gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
|
||||
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
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/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -128,7 +128,7 @@ func GetConversation(c *gin.Context) {
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func SetRecvMsgOpt(c *gin.Context) {
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetRecvMsgOpt rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -201,3 +201,18 @@ func SetRecvMsgOpt(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func SetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
+129
-1
@@ -259,7 +259,7 @@ func CreateGroup(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.OwnerUserID = req.OpUserID
|
||||
req.OwnerUserID = params.OwnerUserID
|
||||
req.OperationID = params.OperationID
|
||||
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
||||
|
||||
@@ -568,3 +568,131 @@ func DismissGroup(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func MuteGroupMember(c *gin.Context) {
|
||||
params := api.MuteGroupMemberReq{}
|
||||
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.MuteGroupMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
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.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.MuteGroupMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.MuteGroupMemberResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CancelMuteGroupMember(c *gin.Context) {
|
||||
params := api.CancelMuteGroupMemberReq{}
|
||||
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.CancelMuteGroupMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
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.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.CancelMuteGroupMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CancelMuteGroupMemberResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func MuteGroup(c *gin.Context) {
|
||||
params := api.MuteGroupReq{}
|
||||
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.MuteGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
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.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.MuteGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.MuteGroupResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CancelMuteGroup(c *gin.Context) {
|
||||
params := api.CancelMuteGroupReq{}
|
||||
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.CancelMuteGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
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.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.CancelMuteGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CancelMuteGroupResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -29,6 +30,7 @@ var validate *validator.Validate
|
||||
|
||||
func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
var newContent string
|
||||
var err error
|
||||
switch params.ContentType {
|
||||
case constant.Text:
|
||||
newContent = params.Content["text"].(string)
|
||||
@@ -42,6 +44,7 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
newContent = utils.StructToJsonString(params.Content)
|
||||
case constant.Revoke:
|
||||
newContent = params.Content["revokeMsgClientID"].(string)
|
||||
|
||||
default:
|
||||
}
|
||||
var options map[string]bool
|
||||
@@ -72,6 +75,14 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
OfflinePushInfo: params.OfflinePushInfo,
|
||||
},
|
||||
}
|
||||
if params.ContentType == constant.OANotification {
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.JsonDetail = utils.StructToJsonString(params.Content)
|
||||
pbData.MsgData.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(params.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
}
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
func init() {
|
||||
@@ -107,6 +118,9 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
data = CustomElem{}
|
||||
case constant.Revoke:
|
||||
data = RevokeElem{}
|
||||
case constant.OANotification:
|
||||
data = OANotificationElem{}
|
||||
params.SessionType = constant.NotificationChatType
|
||||
//case constant.HasReadReceipt:
|
||||
//case constant.Typing:
|
||||
//case constant.Quote:
|
||||
@@ -126,7 +140,7 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
}
|
||||
log.NewInfo("", data, params)
|
||||
token := c.Request.Header.Get("token")
|
||||
claims, err := token_verify.ParseToken(token)
|
||||
claims, err := token_verify.ParseToken(token, params.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||
@@ -204,16 +218,16 @@ type ManagementSendMsgReq struct {
|
||||
|
||||
type PictureBaseInfo struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
Type string `mapstructure:"type" validate:"required"`
|
||||
Size int64 `mapstructure:"size" validate:"required"`
|
||||
Width int32 `mapstructure:"width" validate:"required"`
|
||||
Height int32 `mapstructure:"height" validate:"required"`
|
||||
Url string `mapstructure:"url" validate:"required"`
|
||||
Type string `mapstructure:"type" `
|
||||
Size int64 `mapstructure:"size" `
|
||||
Width int32 `mapstructure:"width" `
|
||||
Height int32 `mapstructure:"height"`
|
||||
Url string `mapstructure:"url" `
|
||||
}
|
||||
|
||||
type PictureElem struct {
|
||||
SourcePath string `mapstructure:"sourcePath"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
|
||||
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
||||
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
||||
}
|
||||
@@ -267,3 +281,16 @@ type TextElem struct {
|
||||
type RevokeElem struct {
|
||||
RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"`
|
||||
}
|
||||
type OANotificationElem struct {
|
||||
NotificationName string `mapstructure:"notificationName" validate:"required"`
|
||||
NotificationFaceURL string `mapstructure:"notificationFaceURL" validate:"required"`
|
||||
NotificationType int32 `mapstructure:"notificationType" validate:"required"`
|
||||
Text string `mapstructure:"text" validate:"required"`
|
||||
Url string `mapstructure:"url"`
|
||||
MixType int32 `mapstructure:"mixType"`
|
||||
PictureElem PictureElem `mapstructure:"pictureElem"`
|
||||
SoundElem SoundElem `mapstructure:"soundElem"`
|
||||
VideoElem VideoElem `mapstructure:"videoElem"`
|
||||
FileElem FileElem `mapstructure:"fileElem"`
|
||||
Ex string `mapstructure:"ex"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
apistruct "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserTags(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetUserTagsReq
|
||||
resp apistruct.GetUserTagsResp
|
||||
reqPb pbOffice.GetUserTagsReq
|
||||
respPb *pbOffice.GetUserTagsResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTags(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserTags rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
if respPb.Tags != nil {
|
||||
resp.Data.Tags = respPb.Tags
|
||||
} else {
|
||||
resp.Data.Tags = []*pbOffice.Tag{}
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CreateTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.CreateTagReq
|
||||
resp apistruct.CreateTagResp
|
||||
reqPb pbOffice.CreateTagReq
|
||||
respPb *pbOffice.CreateTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.CreateTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.DeleteTagReq
|
||||
resp apistruct.DeleteTagResp
|
||||
reqPb pbOffice.DeleteTagReq
|
||||
respPb *pbOffice.DeleteTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.DeleteTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SetTagReq
|
||||
resp apistruct.SetTagResp
|
||||
reqPb pbOffice.SetTagReq
|
||||
respPb *pbOffice.SetTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SetTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SendMsg2Tag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SendMsg2TagReq
|
||||
resp apistruct.SendMsg2TagResp
|
||||
reqPb pbOffice.SendMsg2TagReq
|
||||
respPb *pbOffice.SendMsg2TagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.SendID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SendMsg2Tag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetTagSendLogs(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetTagSendLogsReq
|
||||
resp apistruct.GetTagSendLogsResp
|
||||
reqPb pbOffice.GetTagSendLogsReq
|
||||
respPb *pbOffice.GetTagSendLogsResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetTagSendLogs(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
if respPb.TagSendLogs != nil {
|
||||
resp.Data.Logs = respPb.TagSendLogs
|
||||
} else {
|
||||
resp.Data.Logs = []*pbOffice.TagSendLog{}
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserTagByID(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetUserTagByIDReq
|
||||
resp apistruct.GetUserTagByIDResp
|
||||
reqPb pbOffice.GetUserTagByIDReq
|
||||
respPb *pbOffice.GetUserTagByIDResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.TagID = req.TagID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTagByID(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTagByID failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.Tag = respPb.Tag
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package apiThird
|
||||
|
||||
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"
|
||||
"fmt"
|
||||
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
|
||||
sts20150401 "github.com/alibabacloud-go/sts-20150401/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/fatih/structs"
|
||||
|
||||
//"github.com/fatih/structs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var stsClient *sts20150401.Client
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId
|
||||
* @param accessKeySecret
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
func getStsClient() *sts20150401.Client {
|
||||
if stsClient != nil {
|
||||
return stsClient
|
||||
}
|
||||
conf := &openapi.Config{
|
||||
// 您的AccessKey ID
|
||||
AccessKeyId: tea.String(config.Config.Credential.Ali.AccessKeyID),
|
||||
// 您的AccessKey Secret
|
||||
AccessKeySecret: tea.String(config.Config.Credential.Ali.AccessKeySecret),
|
||||
// Endpoint
|
||||
Endpoint: tea.String(config.Config.Credential.Ali.StsEndpoint),
|
||||
}
|
||||
result, err := sts20150401.NewClient(conf)
|
||||
if err != nil {
|
||||
log.NewError("", "alists client初始化失败 ", err)
|
||||
}
|
||||
stsClient = result
|
||||
return stsClient
|
||||
}
|
||||
|
||||
func AliOSSCredential(c *gin.Context) {
|
||||
req := api.OSSCredentialReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "AliOSSCredential args ", userID)
|
||||
|
||||
stsResp, err := getStsClient().AssumeRole(&sts20150401.AssumeRoleRequest{
|
||||
DurationSeconds: tea.Int64(config.Config.Credential.Ali.StsDurationSeconds),
|
||||
Policy: nil,
|
||||
RoleArn: tea.String(config.Config.Credential.Ali.OssRoleArn),
|
||||
RoleSessionName: tea.String(fmt.Sprintf("%s-%d", userID, time.Now().Unix())),
|
||||
})
|
||||
|
||||
resp := api.OSSCredentialResp{}
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrTencentCredential.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
} else {
|
||||
resp = api.OSSCredentialResp{
|
||||
CommResp: api.CommResp{},
|
||||
OssData: api.OSSCredentialRespData{
|
||||
Endpoint: config.Config.Credential.Ali.OssEndpoint,
|
||||
AccessKeyId: *stsResp.Body.Credentials.AccessKeyId,
|
||||
AccessKeySecret: *stsResp.Body.Credentials.AccessKeySecret,
|
||||
Token: *stsResp.Body.Credentials.SecurityToken,
|
||||
Bucket: config.Config.Credential.Ali.Bucket,
|
||||
FinalHost: config.Config.Credential.Ali.FinalHost,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
|
||||
resp.Data = structs.Map(&resp.OssData)
|
||||
log.NewInfo(req.OperationID, "AliOSSCredential return ", resp)
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -33,8 +33,15 @@ func MinioUploadFile(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
switch req.FileType {
|
||||
// videoType upload snapShot
|
||||
case constant.VideoType:
|
||||
snapShotFile, err := c.FormFile("snapShot")
|
||||
if err != nil {
|
||||
@@ -74,7 +81,7 @@ func MinioUploadFile(c *gin.Context) {
|
||||
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error")
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.NewName = newName
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
type ParamsSetPassword struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Password string `json:"password"`
|
||||
VerificationCode string `json:"verificationCode"`
|
||||
@@ -38,6 +39,9 @@ func SetPassword(c *gin.Context) {
|
||||
} else {
|
||||
account = params.PhoneNumber
|
||||
}
|
||||
if params.Name == "" {
|
||||
params.Name = account
|
||||
}
|
||||
if params.VerificationCode != config.Config.Demo.SuperCode {
|
||||
accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
@@ -54,7 +58,7 @@ func SetPassword(c *gin.Context) {
|
||||
openIMRegisterReq.OperationID = params.OperationID
|
||||
openIMRegisterReq.Platform = params.Platform
|
||||
openIMRegisterReq.UserID = account
|
||||
openIMRegisterReq.Nickname = account
|
||||
openIMRegisterReq.Nickname = params.Name
|
||||
openIMRegisterReq.Secret = config.Config.Secret
|
||||
openIMRegisterResp := api.UserRegisterResp{}
|
||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||
@@ -69,7 +73,7 @@ func SetPassword(c *gin.Context) {
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: "+openIMRegisterResp.ErrMsg})
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
||||
|
||||
@@ -2,7 +2,7 @@ package gate
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
||||
"Open_IM/pkg/statistics"
|
||||
"fmt"
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
|
||||
func Init(rpcPort, wsPort int) {
|
||||
//log initialization
|
||||
log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName)
|
||||
|
||||
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,138 +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.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
|
||||
//}
|
||||
|
||||
@@ -80,6 +80,22 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
|
||||
mc.groupMsgCount++
|
||||
}
|
||||
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
|
||||
case constant.NotificationChatType:
|
||||
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = NotificationChatType", isHistory, isPersist)
|
||||
if isHistory {
|
||||
err := saveUserChat(msgKey, &msgFromMQ)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
|
||||
return
|
||||
}
|
||||
mc.singleMsgCount++
|
||||
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||
}
|
||||
if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID {
|
||||
} else {
|
||||
go sendMessageToPush(&msgFromMQ, msgKey)
|
||||
}
|
||||
log.NewDebug(operationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||
default:
|
||||
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
||||
return
|
||||
|
||||
@@ -2,8 +2,8 @@ package logic
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -13,7 +13,7 @@ var (
|
||||
)
|
||||
|
||||
func Init() {
|
||||
log.NewPrivateLog(config.Config.ModuleName.MsgTransferName)
|
||||
|
||||
persistentCH.Init()
|
||||
historyCH.Init()
|
||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
||||
|
||||
@@ -34,26 +34,31 @@ func (pc *PersistentConsumerHandler) Init() {
|
||||
|
||||
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
|
||||
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
||||
var tag bool
|
||||
msgFromMQ := pbMsg.MsgDataToMQ{}
|
||||
err := proto.Unmarshal(msg, &msgFromMQ)
|
||||
if err != nil {
|
||||
log.ErrorByKv("msg_transfer Unmarshal msg err", "", "msg", string(msg), "err", err.Error())
|
||||
log.NewError(msgFromMQ.OperationID, "msg_transfer Unmarshal msg err", "msg", string(msg), "err", err.Error())
|
||||
return
|
||||
}
|
||||
//Control whether to store history messages (mysql)
|
||||
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
||||
//Only process receiver data
|
||||
if isPersist {
|
||||
if msgKey == msgFromMQ.MsgData.RecvID && msgFromMQ.MsgData.SessionType == constant.SingleChatType {
|
||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
||||
return
|
||||
switch msgFromMQ.MsgData.SessionType {
|
||||
case constant.SingleChatType, constant.NotificationChatType:
|
||||
if msgKey == msgFromMQ.MsgData.RecvID {
|
||||
tag = true
|
||||
}
|
||||
} else if msgFromMQ.MsgData.SessionType == constant.GroupChatType && msgKey == msgFromMQ.MsgData.SendID {
|
||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
||||
case constant.GroupChatType:
|
||||
if msgKey == msgFromMQ.MsgData.SendID || utils.IsContain(msgFromMQ.MsgData.SendID, config.Config.Manager.AppManagerUid) {
|
||||
tag = true
|
||||
}
|
||||
}
|
||||
if tag {
|
||||
log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg))
|
||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
||||
log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(config.Config.ModuleName.PushName)
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ type adminCMSServer struct {
|
||||
}
|
||||
|
||||
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||
log.NewPrivateLog("AdminCMS")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &adminCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
||||
@@ -66,12 +66,12 @@ func (s *adminCMSServer) Run() {
|
||||
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbAdminCMS.AdminLoginResp{}
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid{
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid {
|
||||
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||
}
|
||||
resp.Token = token
|
||||
@@ -84,4 +84,4 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ type rpcAuth struct {
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
|
||||
@@ -29,7 +29,7 @@ type friendServer struct {
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
|
||||
@@ -7,3 +7,7 @@ import (
|
||||
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func callbackAfterCreateGroup(req *pbGroup.CreateGroupReq) {
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type groupServer struct {
|
||||
}
|
||||
|
||||
func NewGroupServer(port int) *groupServer {
|
||||
log.NewPrivateLog("group")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &groupServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
@@ -41,16 +41,16 @@ func NewGroupServer(port int) *groupServer {
|
||||
}
|
||||
|
||||
func (s *groupServer) Run() {
|
||||
log.NewInfo("0", "group rpc start ")
|
||||
log.NewInfo("", "group rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
log.NewError("", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
log.NewInfo("", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
@@ -59,15 +59,15 @@ func (s *groupServer) Run() {
|
||||
pbGroup.RegisterGroupServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
log.NewError("", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
log.NewError("", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "group rpc success")
|
||||
log.NewInfo("", "group rpc success")
|
||||
}
|
||||
|
||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||
@@ -273,8 +273,11 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
log.Debug(req.OperationID, v)
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
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)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", resp.String())
|
||||
@@ -355,7 +358,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
//remove
|
||||
var resp pbGroup.KickGroupMemberResp
|
||||
for _, v := range req.KickedUserIDList {
|
||||
//owner cant kicked
|
||||
//owner can‘t kicked
|
||||
if v == groupOwnerUserID {
|
||||
log.NewError(req.OperationID, "failed, can't kick owner ", v)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
||||
@@ -665,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 {
|
||||
@@ -674,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
|
||||
}
|
||||
|
||||
@@ -701,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{
|
||||
@@ -710,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
|
||||
}
|
||||
|
||||
@@ -961,3 +969,78 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
|
||||
// rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
|
||||
// rpc CancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
|
||||
// rpc MuteGroup(MuteGroupReq) returns(MuteGroupResp);
|
||||
// rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
|
||||
|
||||
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||
if !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.Error(req.OperationID, "verify failed ", req.GroupID, req.UserID)
|
||||
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
|
||||
|
||||
groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano())
|
||||
err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
|
||||
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||
if !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.Error(req.OperationID, "verify failed ", req.OpUserID, req.GroupID)
|
||||
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
|
||||
groupMemberInfo.MuteEndTime = time.Unix(0, 0)
|
||||
err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
|
||||
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (*pbGroup.MuteGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||
if !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.Error(req.OperationID, "verify failed ", req.GroupID, req.GroupID)
|
||||
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
err := imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusMuted)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||
if !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.Error(req.OperationID, "verify failed ", req.OpUserID, req.GroupID)
|
||||
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err := imdb.UpdateGroupInfoDefaultZero(req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type messageCMSServer struct {
|
||||
}
|
||||
|
||||
func NewMessageCMSServer(port int) *messageCMSServer {
|
||||
log.NewPrivateLog("MessageCMS")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &messageCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
||||
@@ -84,8 +84,8 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||
}
|
||||
chatLog := db.ChatLog{
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
ContentType: req.ContentType,
|
||||
SessionType: req.SessionType,
|
||||
}
|
||||
@@ -101,20 +101,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
||||
}
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||
return resp, errors.WrapError(constant.ErrDB)
|
||||
}
|
||||
for _, chatLog := range chatLogs {
|
||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
||||
SessionType: chatLog.SessionType,
|
||||
ContentType: chatLog.ContentType,
|
||||
SearchContent: req.Content,
|
||||
WholeContent: chatLog.Content,
|
||||
Date: chatLog.CreateTime.String(),
|
||||
SessionType: chatLog.SessionType,
|
||||
ContentType: chatLog.ContentType,
|
||||
SearchContent: req.Content,
|
||||
WholeContent: chatLog.Content,
|
||||
Date: chatLog.CreateTime.String(),
|
||||
SenderNickName: chatLog.SenderNickname,
|
||||
SenderId: chatLog.SendID,
|
||||
SenderId: chatLog.SendID,
|
||||
}
|
||||
if chatLog.SenderNickname == "" {
|
||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func conversationNotification(contentType int32, m proto.Message, operationID, userID string) {
|
||||
func SetConversationNotification(operationID, sendID, recvID string, contentType int, m proto.Message, tips open_im_sdk.TipsComm) {
|
||||
log.NewInfo(operationID, "args: ", sendID, recvID, contentType, m.String(), tips.String())
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, utils.GetSelfFuncName(), "Marshal failed ", err.Error(), m.String())
|
||||
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
@@ -24,15 +24,10 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.ConversationOptChangeNotification:
|
||||
tips.DefaultTips = cn.ConversationOptUpdate.DefaultTips.Tips
|
||||
}
|
||||
var n NotificationMsg
|
||||
n.SendID = userID
|
||||
n.RecvID = userID
|
||||
n.ContentType = contentType
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = int32(contentType)
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
@@ -44,10 +39,38 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func SetConversationNotification(operationID, userID string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "userID: ", userID)
|
||||
conversationUpdateTips := open_im_sdk.ConversationUpdateTips{
|
||||
// SetPrivate调用
|
||||
func ConversationSetPrivateNotification(operationID, sendID, recvID string, isPrivateChat bool) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName())
|
||||
conversationSetPrivateTips := &open_im_sdk.ConversationSetPrivateTips{
|
||||
RecvID: recvID,
|
||||
SendID: sendID,
|
||||
IsPrivate: isPrivateChat,
|
||||
}
|
||||
var tips open_im_sdk.TipsComm
|
||||
var tipsMsg string
|
||||
//var senderName string
|
||||
//senderName, err := im_mysql_model.GetUserNameByUserID(sendID)
|
||||
//if err != nil {
|
||||
// log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
// senderName = sendID
|
||||
//}
|
||||
if isPrivateChat == true {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
|
||||
} else {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
|
||||
}
|
||||
tips.DefaultTips = tipsMsg
|
||||
SetConversationNotification(operationID, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
|
||||
}
|
||||
|
||||
// 会话改变
|
||||
func ConversationChangeNotification(operationID, userID string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName())
|
||||
ConversationChangedTips := &open_im_sdk.ConversationUpdateTips{
|
||||
UserID: userID,
|
||||
}
|
||||
conversationNotification(constant.ConversationOptChangeNotification, &conversationUpdateTips, operationID, userID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
||||
SetConversationNotification(operationID, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (rpc *rpcChat) DelMsgList(_ context.Context, req *commonPb.DelMsgListReq) (
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsg failed", err.Error())
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, err
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
|
||||
@@ -160,6 +160,14 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberEnter.DefaultTips.Tips
|
||||
case constant.GroupDismissedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupDismissed.DefaultTips.Tips
|
||||
case constant.GroupMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMuted.DefaultTips.Tips
|
||||
case constant.GroupCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberCancelMuted.DefaultTips.Tips
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
@@ -227,6 +235,71 @@ func GroupInfoSetNotification(operationID, opUserID, groupID string) {
|
||||
groupNotification(constant.GroupInfoSetNotification, &GroupInfoChangedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := open_im_sdk.GroupMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupCancelMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := open_im_sdk.GroupCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberMutedNotification(operationID, opUserID, groupID, groupMemberUserID string, mutedSeconds uint32) {
|
||||
tips := open_im_sdk.GroupMemberMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
tips.MutedSeconds = mutedSeconds
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMemberUserID string) {
|
||||
tips := open_im_sdk.GroupMemberCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
|
||||
@@ -2,6 +2,7 @@ package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
@@ -22,7 +23,7 @@ type rpcChat struct {
|
||||
}
|
||||
|
||||
func NewRpcChatServer(port int) *rpcChat {
|
||||
log.NewPrivateLog("msg")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rc := rpcChat{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
||||
@@ -42,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()
|
||||
|
||||
@@ -116,6 +116,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
case constant.HasReadReceipt:
|
||||
log.Info("", "this is a test start", msg, msg.Options)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
log.Info("", "this is a test end", msg, msg.Options)
|
||||
@@ -124,6 +125,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
|
||||
@@ -279,6 +281,23 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error())
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
case constant.NotificationChatType:
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
log.NewInfo(msgToMQ.OperationID, msgToMQ)
|
||||
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
||||
if err1 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
|
||||
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
||||
if err2 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
}
|
||||
@@ -511,14 +530,48 @@ func Notification(n *NotificationMsg) {
|
||||
ex = config.Config.Notification.GroupDismissed.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupDismissed.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupDismissed.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberCancelMuted.Conversation.UnreadCount
|
||||
}
|
||||
switch reliabilityLevel {
|
||||
case constant.UnreliableNotification:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationNoMsg:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationMsg:
|
||||
|
||||
}
|
||||
@@ -535,6 +588,6 @@ func Notification(n *NotificationMsg) {
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||
} else if reply.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String())
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), reply.ErrCode, reply.ErrMsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
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"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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 = 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.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
|
||||
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)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
respPb, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
|
||||
return
|
||||
}
|
||||
if respPb.ErrCode != 0 {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send tag msg failed ", respPb)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"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"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type officeServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewOfficeServer(port int) *officeServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &officeServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *officeServer) Run() {
|
||||
log.NewInfo("0", "officeServer rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbOffice.RegisterOfficeServiceServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "message cms rpc success")
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserTags(_ context.Context, req *pbOffice.GetUserTagsReq) (resp *pbOffice.GetUserTagsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req ", req.String())
|
||||
resp = &pbOffice.GetUserTagsResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
Tags: []*pbOffice.Tag{},
|
||||
}
|
||||
tags, err := db.DB.GetUserTags(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "tags: ", tags)
|
||||
for _, v := range tags {
|
||||
tag := &pbOffice.Tag{
|
||||
TagID: v.TagID,
|
||||
TagName: v.TagName,
|
||||
}
|
||||
for _, userID := range v.UserList {
|
||||
UserName, err := im_mysql_model.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tag.UserList = append(tag.UserList, &pbOffice.TagUser{
|
||||
UserID: userID,
|
||||
UserName: UserName,
|
||||
})
|
||||
}
|
||||
resp.Tags = append(resp.Tags, tag)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) CreateTag(_ context.Context, req *pbOffice.CreateTagReq) (resp *pbOffice.CreateTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "CreateTag req", req.String())
|
||||
userIDList := utils.RemoveRepeatedStringInList(req.UserIDList)
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
||||
resp = &pbOffice.CreateTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.CreateTag(req.UserID, req.TagName, userIDList); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) DeleteTag(_ context.Context, req *pbOffice.DeleteTagReq) (resp *pbOffice.DeleteTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.DeleteTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.DeleteTag(req.UserID, req.TagID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteTag failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp *pbOffice.SetTagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SetTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
IncreaseUserIDList := utils.RemoveRepeatedStringInList(req.IncreaseUserIDList)
|
||||
reduceUserIDList := utils.RemoveRepeatedStringInList(req.ReduceUserIDList)
|
||||
if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, IncreaseUserIDList, reduceUserIDList); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagReq) (resp *pbOffice.SendMsg2TagResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SendMsg2TagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
var tagUserIDList []string
|
||||
for _, tagID := range req.TagList {
|
||||
userIDList, err := db.DB.GetUserIDListByTagID(req.SendID, tagID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserIDListByTagID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tagUserIDList = append(tagUserIDList, userIDList...)
|
||||
}
|
||||
var groupUserIDList []string
|
||||
for _, groupID := range req.GroupList {
|
||||
userIDList, err := im_mysql_model.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), userIDList)
|
||||
groupUserIDList = append(groupUserIDList, userIDList...)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), groupUserIDList, req.GroupList)
|
||||
var userIDList []string
|
||||
userIDList = append(userIDList, tagUserIDList...)
|
||||
userIDList = append(userIDList, groupUserIDList...)
|
||||
userIDList = append(userIDList, req.UserList...)
|
||||
userIDList = utils.RemoveRepeatedStringInList(userIDList)
|
||||
for i, userID := range userIDList {
|
||||
if userID == req.SendID || userID == "" {
|
||||
userIDList = append(userIDList[:i], userIDList[i+1:]...)
|
||||
}
|
||||
}
|
||||
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, us, userID, req.Content, req.SenderPlatformID)
|
||||
}
|
||||
var tagSendLogs db.TagSendLog
|
||||
for _, userID := range userIDList {
|
||||
userName, err := im_mysql_model.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
tagSendLogs.UserList = append(tagSendLogs.UserList, db.TagUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
}
|
||||
tagSendLogs.SendID = req.SendID
|
||||
tagSendLogs.Content = req.Content
|
||||
tagSendLogs.SenderPlatformID = req.SenderPlatformID
|
||||
tagSendLogs.SendTime = time.Now().Unix()
|
||||
if err := db.DB.SaveTagSendLog(&tagSendLogs); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SaveTagSendLog 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())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetTagSendLogs(_ context.Context, req *pbOffice.GetTagSendLogsReq) (resp *pbOffice.GetTagSendLogsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetTagSendLogsResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
Pagination: &pbCommon.ResponsePagination{
|
||||
CurrentPage: req.Pagination.PageNumber,
|
||||
ShowNumber: req.Pagination.ShowNumber,
|
||||
},
|
||||
TagSendLogs: []*pbOffice.TagSendLog{},
|
||||
}
|
||||
tagSendLogs, err := db.DB.GetTagSendLogs(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTagSendLogs", err.Error())
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.TagSendLogs, tagSendLogs); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserTagByID(_ context.Context, req *pbOffice.GetUserTagByIDReq) (resp *pbOffice.GetUserTagByIDResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserTagByIDResp{
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
Tag: &pbOffice.Tag{},
|
||||
}
|
||||
tag, err := db.DB.GetTagByID(req.UserID, req.TagID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTagByID failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
for _, userID := range tag.UserList {
|
||||
userName, err := im_mysql_model.GetUserNameByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.Tag.UserList = append(resp.Tag.UserList, &pbOffice.TagUser{
|
||||
UserID: userID,
|
||||
UserName: userName,
|
||||
})
|
||||
}
|
||||
resp.Tag.TagID = tag.TagID
|
||||
resp.Tag.TagName = tag.TagName
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
//"context"
|
||||
errors "Open_IM/pkg/common/http"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
errors "Open_IM/pkg/common/http"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@@ -35,7 +35,7 @@ type statisticsServer struct {
|
||||
}
|
||||
|
||||
func NewStatisticsServer(port int) *statisticsServer {
|
||||
log.NewPrivateLog("Statistics")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &statisticsServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
||||
@@ -164,7 +164,7 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
|
||||
}
|
||||
// month
|
||||
case !isInOneMonth(from, to):
|
||||
if to.Sub(from) < time.Hour * 24 * 30 {
|
||||
if to.Sub(from) < time.Hour*24*30 {
|
||||
for i := 0; ; i++ {
|
||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||
@@ -251,7 +251,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Date: v[0].String(),
|
||||
Num: num,
|
||||
}
|
||||
}(wg, i, v)
|
||||
|
||||
@@ -32,7 +32,7 @@ type userServer struct {
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
@@ -72,6 +72,30 @@ func (s *userServer) Run() {
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func syncPeerUserConversation(conversation *pbUser.Conversation, operationID string) error {
|
||||
peerUserConversation := db.Conversation{
|
||||
OwnerUserID: conversation.UserID,
|
||||
ConversationID: "single_" + conversation.OwnerUserID,
|
||||
ConversationType: constant.SingleChatType,
|
||||
UserID: conversation.OwnerUserID,
|
||||
GroupID: "",
|
||||
RecvMsgOpt: 0,
|
||||
UnreadCount: 0,
|
||||
DraftTextTime: 0,
|
||||
IsPinned: false,
|
||||
IsPrivateChat: conversation.IsPrivateChat,
|
||||
AttachedInfo: "",
|
||||
Ex: "",
|
||||
}
|
||||
err := imdb.PeerUserSetConversation(peerUserConversation)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
return err
|
||||
}
|
||||
chat.ConversationSetPrivateNotification(operationID, conversation.OwnerUserID, conversation.UserID, conversation.IsPrivateChat)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||
var userInfoList []*sdkws.UserInfo
|
||||
@@ -96,6 +120,9 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
|
||||
|
||||
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
if req.NotificationType == 0 {
|
||||
req.NotificationType = constant.ConversationOptChangeNotification
|
||||
}
|
||||
resp := &pbUser.BatchSetConversationsResp{}
|
||||
for _, v := range req.Conversations {
|
||||
conversation := db.Conversation{}
|
||||
@@ -113,8 +140,14 @@ 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 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
||||
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
@@ -173,6 +206,9 @@ func (s *userServer) GetConversations(ctx context.Context, req *pbUser.GetConver
|
||||
|
||||
func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConversationReq) (*pbUser.SetConversationResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
if req.NotificationType == 0 {
|
||||
req.NotificationType = constant.ConversationOptChangeNotification
|
||||
}
|
||||
resp := &pbUser.SetConversationResp{}
|
||||
var conversation db.Conversation
|
||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
@@ -189,7 +225,17 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID)
|
||||
// notification
|
||||
if req.Conversation.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
|
||||
//sync peer user conversation if conversation is singleChatType
|
||||
if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
} else {
|
||||
chat.ConversationChangeNotification(req.OperationID, req.Conversation.OwnerUserID)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
@@ -207,13 +253,24 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
stringList := strings.Split(req.ConversationID, "_")
|
||||
if len(stringList) > 1 {
|
||||
switch stringList[0] {
|
||||
case "single_":
|
||||
conversation.UserID = stringList[1]
|
||||
conversation.ConversationType = constant.SingleChatType
|
||||
case "group":
|
||||
conversation.GroupID = stringList[1]
|
||||
conversation.ConversationType = constant.GroupChatType
|
||||
}
|
||||
}
|
||||
err := imdb.SetRecvMsgOpt(conversation)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
||||
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
|
||||
@@ -76,7 +76,7 @@ func Test_ParseToken(t *testing.T) {
|
||||
uid := "1"
|
||||
platform := int32(1)
|
||||
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
||||
claims, err := token_verify.ParseToken(tokenString)
|
||||
claims, err := token_verify.ParseToken(tokenString, "")
|
||||
if err == nil {
|
||||
assert.Equal(t, claims.UID, uid)
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ type SetReceiveMessageOptResp struct {
|
||||
|
||||
type Conversation struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
ConversationType int32 `json:"conversationType"`
|
||||
ConversationID string `json:"conversationID" binding:"required"`
|
||||
ConversationType int32 `json:"conversationType" binding:"required"`
|
||||
UserID string `json:"userID"`
|
||||
GroupID string `json:"groupID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
@@ -49,7 +49,8 @@ type Conversation struct {
|
||||
|
||||
type SetConversationReq struct {
|
||||
Conversation
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetConversationResp struct {
|
||||
@@ -57,9 +58,10 @@ type SetConversationResp struct {
|
||||
}
|
||||
|
||||
type BatchSetConversationsReq struct {
|
||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type BatchSetConversationsResp struct {
|
||||
@@ -103,10 +105,11 @@ type GetConversationsResp struct {
|
||||
}
|
||||
|
||||
type SetRecvMsgOptReq struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
}
|
||||
|
||||
type SetRecvMsgOptResp struct {
|
||||
|
||||
@@ -21,7 +21,7 @@ type ImportFriendReq struct {
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type UserIDResult struct {
|
||||
UserID string `json:"userID""`
|
||||
UserID string `json:"userID"`
|
||||
Result int32 `json:"result"`
|
||||
}
|
||||
type ImportFriendResp struct {
|
||||
|
||||
@@ -185,3 +185,38 @@ type DismissGroupReq struct {
|
||||
type DismissGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type MuteGroupMemberReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
MutedSeconds uint32 `json:"mutedSeconds" binding:"required"`
|
||||
}
|
||||
type MuteGroupMemberResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CancelMuteGroupMemberReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
}
|
||||
type CancelMuteGroupMemberResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type MuteGroupReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
}
|
||||
type MuteGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CancelMuteGroupReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
}
|
||||
type CancelMuteGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct {
|
||||
}
|
||||
|
||||
type MinioUploadFileReq struct {
|
||||
OperationID string `form:"operationID"`
|
||||
FileType int `form:"fileType"`
|
||||
OperationID string `form:"operationID" binding:"required"`
|
||||
FileType int `form:"fileType" binding:"required"`
|
||||
}
|
||||
|
||||
type MinioUploadFileResp struct {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package base_info
|
||||
|
||||
import (
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
)
|
||||
|
||||
type GetUserTagsReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tags []*pbOffice.Tag `json:"tags"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateTagReq struct {
|
||||
TagName string `json:"tagName" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type CreateTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
NewName string `json:"newName"`
|
||||
IncreaseUserIDList []string `json:"increaseUserIDList"`
|
||||
ReduceUserIDList []string `json:"reduceUserIDList"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SendMsg2TagReq struct {
|
||||
TagList []string `json:"tagList"`
|
||||
UserList []string `json:"userList"`
|
||||
GroupList []string `json:"groupList"`
|
||||
|
||||
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SendMsg2TagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetTagSendLogsReq struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetTagSendLogsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Logs []*pbOffice.TagSendLog `json:"logs"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tag *pbOffice.Tag `json:"tag"`
|
||||
} `json:"data"`
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package base_info
|
||||
|
||||
type OSSCredentialReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
Filename string `json:"filename"`
|
||||
FileType string `json:"file_type"`
|
||||
}
|
||||
|
||||
type OSSCredentialRespData struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
AccessKeyId string `json:"access_key_id"`
|
||||
AccessKeySecret string `json:"access_key_secret"`
|
||||
Token string `json:"token"`
|
||||
Bucket string `json:"bucket"`
|
||||
FinalHost string `json:"final_host"`
|
||||
}
|
||||
|
||||
type OSSCredentialResp struct {
|
||||
CommResp
|
||||
OssData OSSCredentialRespData `json:"-"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
+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"
|
||||
@@ -45,6 +44,17 @@ type config struct {
|
||||
SecretID string `yaml:"secretID"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
Ali struct {
|
||||
RegionID string `yaml:"regionID"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
StsEndpoint string `yaml:"stsEndpoint"`
|
||||
OssEndpoint string `yaml:"ossEndpoint"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
FinalHost string `yaml:"finalHost"`
|
||||
StsDurationSeconds int64 `yaml:"stsDurationSeconds"`
|
||||
OssRoleArn string `yaml:"OssRoleArn"`
|
||||
}
|
||||
Minio struct {
|
||||
Bucket string `yaml:"bucket"`
|
||||
Location string `yaml:"location"`
|
||||
@@ -66,6 +76,7 @@ type config struct {
|
||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||
}
|
||||
Mongo struct {
|
||||
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
|
||||
DBAddress []string `yaml:"dbAddress"`
|
||||
DBDirect bool `yaml:"dbDirect"`
|
||||
DBTimeout int `yaml:"dbTimeout"`
|
||||
@@ -103,6 +114,7 @@ type config struct {
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
@@ -140,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 {
|
||||
@@ -257,6 +278,30 @@ type config struct {
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupDismissed"`
|
||||
|
||||
GroupMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMuted"`
|
||||
|
||||
GroupCancelMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupCancelMuted"`
|
||||
|
||||
GroupMemberMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMemberMuted"`
|
||||
|
||||
GroupMemberCancelMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMemberCancelMuted"`
|
||||
|
||||
////////////////////////user///////////////////////
|
||||
UserInfoUpdated struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
@@ -313,6 +358,14 @@ type config struct {
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"conversationOptUpdate"`
|
||||
ConversationSetPrivate struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips struct {
|
||||
OpenTips string `yaml:"openTips"`
|
||||
CloseTips string `yaml:"closeTips"`
|
||||
} `yaml:"defaultTips"`
|
||||
} `yaml:"conversationSetPrivate"`
|
||||
}
|
||||
Demo struct {
|
||||
Port []int `yaml:"openImDemoPort"`
|
||||
@@ -332,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"`
|
||||
@@ -371,5 +428,4 @@ func init() {
|
||||
if err = yaml.Unmarshal(bytes, &Config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Println("load config: ", Config)
|
||||
}
|
||||
|
||||
@@ -56,14 +56,13 @@ const (
|
||||
FriendRemarkSetNotification = 1206 //set_friend_remark?
|
||||
BlackAddedNotification = 1207 //add_black
|
||||
BlackDeletedNotification = 1208 //remove_black
|
||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||
|
||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||
|
||||
UserNotificationBegin = 1301
|
||||
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
||||
ConversationNotification = 1307
|
||||
ConversationNotNotification = 1308
|
||||
ConversationDefault = 0
|
||||
UserNotificationEnd = 1399
|
||||
OANotification = 1400
|
||||
|
||||
GroupNotificationBegin = 1500
|
||||
|
||||
@@ -78,11 +77,18 @@ const (
|
||||
MemberInvitedNotification = 1509
|
||||
MemberEnterNotification = 1510
|
||||
GroupDismissedNotification = 1511
|
||||
GroupMemberMutedNotification = 1512
|
||||
GroupMemberCancelMutedNotification = 1513
|
||||
GroupMutedNotification = 1514
|
||||
GroupCancelMutedNotification = 1515
|
||||
|
||||
SignalingNotificationBegin = 1600
|
||||
SignalingNotification = 1601
|
||||
SignalingNotificationEnd = 1699
|
||||
NotificationEnd = 2000
|
||||
|
||||
ConversationPrivateChatNotification = 1701
|
||||
|
||||
NotificationEnd = 2000
|
||||
|
||||
//status
|
||||
MsgNormal = 1
|
||||
@@ -95,6 +101,8 @@ const (
|
||||
//SessionType
|
||||
SingleChatType = 1
|
||||
GroupChatType = 2
|
||||
|
||||
NotificationChatType = 4
|
||||
//token
|
||||
NormalToken = 0
|
||||
InValidToken = 1
|
||||
@@ -122,17 +130,20 @@ const (
|
||||
ReceiveNotNotifyMessage = 2
|
||||
|
||||
//OptionsKey
|
||||
IsHistory = "history"
|
||||
IsPersistent = "persistent"
|
||||
IsOfflinePush = "offlinePush"
|
||||
IsUnreadCount = "unreadCount"
|
||||
IsConversationUpdate = "conversationUpdate"
|
||||
IsSenderSync = "senderSync"
|
||||
IsHistory = "history"
|
||||
IsPersistent = "persistent"
|
||||
IsOfflinePush = "offlinePush"
|
||||
IsUnreadCount = "unreadCount"
|
||||
IsConversationUpdate = "conversationUpdate"
|
||||
IsSenderSync = "senderSync"
|
||||
IsNotPrivate = "notPrivate"
|
||||
IsSenderConversationUpdate = "senderConversationUpdate"
|
||||
|
||||
//GroupStatus
|
||||
GroupOk = 0
|
||||
GroupBanChat = 1
|
||||
GroupStatusDismissed = 2
|
||||
GroupStatusMuted = 3
|
||||
|
||||
GroupBaned = 3
|
||||
GroupBanPrivateChat = 4
|
||||
@@ -206,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
|
||||
@@ -220,3 +231,5 @@ func GroupIsBanPrivateChat(status int32) bool {
|
||||
}
|
||||
|
||||
const BigVersion = "v3"
|
||||
|
||||
const LogFileName = "OpenIM.log"
|
||||
|
||||
+14
-7
@@ -2,7 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
//"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@@ -33,6 +33,7 @@ func key(dbAddress, dbName string) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
//log.NewPrivateLog(constant.LogFileName)
|
||||
//var mgoSession *mgo.Session
|
||||
var mongoClient *mongo.Client
|
||||
var err1 error
|
||||
@@ -41,21 +42,27 @@ func init() {
|
||||
// mongo init
|
||||
// "mongodb://sysop:moon@localhost/records"
|
||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
if config.Config.Mongo.DBUri != "" {
|
||||
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
||||
uri = config.Config.Mongo.DBUri
|
||||
} else {
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
}
|
||||
|
||||
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{
|
||||
|
||||
@@ -108,6 +108,7 @@ type GroupMember struct {
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
}
|
||||
|
||||
@@ -220,4 +221,4 @@ type Conversation struct {
|
||||
|
||||
func (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogo/protobuf/sortkeys"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"math/rand"
|
||||
|
||||
//"github.com/garyburd/redigo/redis"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -22,6 +24,8 @@ import (
|
||||
|
||||
const cChat = "msg"
|
||||
const cGroup = "group"
|
||||
const cTag = "tag"
|
||||
const cSendLog = "send_log"
|
||||
const singleGocMsgNum = 5000
|
||||
|
||||
type MsgInfo struct {
|
||||
@@ -430,9 +434,143 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
|
||||
//return nil
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
UserID string `bson:"user_id"`
|
||||
TagID string `bson:"tag_id"`
|
||||
TagName string `bson:"tag_name"`
|
||||
UserList []string `bson:"user_list"`
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserTags(userID string) ([]Tag, error) {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
var tags []Tag
|
||||
cursor, err := c.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
}
|
||||
if err = cursor.All(ctx, &tags); err != nil {
|
||||
return tags, err
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (d *DataBases) CreateTag(userID, tagName string, userList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := Tag{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
UserList: userList,
|
||||
}
|
||||
_, err := c.InsertOne(ctx, tag)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetTagByID(userID, tagID string) (Tag, error) {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
var tag Tag
|
||||
err := c.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func (d *DataBases) DeleteTag(userID, tagID string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_, err := c.DeleteOne(ctx, bson.M{"user_id": userID, "tag_id": tagID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
var tag Tag
|
||||
if err := c.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if newName != "" {
|
||||
_, err := c.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"tag_name": newName}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
||||
tag.UserList = utils.RemoveRepeatedStringInList(tag.UserList)
|
||||
for _, v := range reduceUserIDList {
|
||||
for i2, v2 := range tag.UserList {
|
||||
if v == v2 {
|
||||
tag.UserList[i2] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
var newUserList []string
|
||||
for _, v := range tag.UserList {
|
||||
if v != "" {
|
||||
newUserList = append(newUserList, v)
|
||||
}
|
||||
}
|
||||
_, err := c.UpdateOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}, bson.M{"$set": bson.M{"user_list": newUserList}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DataBases) GetUserIDListByTagID(userID, tagID string) ([]string, error) {
|
||||
var tag Tag
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cTag)
|
||||
_ = c.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, nil
|
||||
}
|
||||
|
||||
type TagUser struct {
|
||||
UserID string `bson:"user_id"`
|
||||
UserName string `bson:"user_name"`
|
||||
}
|
||||
|
||||
type TagSendLog struct {
|
||||
UserList []TagUser `bson:"tag_list"`
|
||||
SendID string `bson:"send_id"`
|
||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||
Content string `bson:"content"`
|
||||
SendTime int64 `bson:"send_time"`
|
||||
}
|
||||
|
||||
func (d *DataBases) SaveTagSendLog(tagSendLog *TagSendLog) error {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
_, err := c.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32) ([]TagSendLog, error) {
|
||||
var tagSendLogs []TagSendLog
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cSendLog)
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||
cursor, err := c.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
err = cursor.All(ctx, &tagSendLogs)
|
||||
if err != nil {
|
||||
return tagSendLogs, err
|
||||
}
|
||||
return tagSendLogs, nil
|
||||
}
|
||||
|
||||
func generateTagID(tagName, userID string) string {
|
||||
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()) + time.Now().String())
|
||||
}
|
||||
|
||||
func getCurrentTimestampByMill() int64 {
|
||||
return time.Now().UnixNano() / 1e6
|
||||
}
|
||||
|
||||
func getSeqUid(uid string, seq uint32) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
return indexGen(uid, seqSuffix)
|
||||
|
||||
+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
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
|
||||
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
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -65,6 +66,24 @@ func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
|
||||
return groupMemberList, nil
|
||||
}
|
||||
|
||||
func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberIDList []string
|
||||
for _, v := range groupMembers {
|
||||
groupMemberIDList = append(groupMemberIDList, v.UserID)
|
||||
}
|
||||
return groupMemberIDList, nil
|
||||
}
|
||||
|
||||
func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
@@ -260,13 +279,21 @@ 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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
//
|
||||
//func SelectGroupList(groupID string) ([]string, error) {
|
||||
// var groupUserID string
|
||||
|
||||
@@ -57,7 +57,6 @@ func SetGroupInfo(groupInfo db.Group) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
|
||||
return err
|
||||
}
|
||||
@@ -68,7 +67,7 @@ func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
@@ -79,7 +78,7 @@ func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||
return groups, err
|
||||
}
|
||||
@@ -102,7 +101,7 @@ func DeleteGroup(groupId string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
var group db.Group
|
||||
var groupMembers []db.GroupMember
|
||||
if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
|
||||
@@ -119,7 +118,6 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
groupMember := db.GroupMember{
|
||||
UserID: userId,
|
||||
GroupID: groupId,
|
||||
@@ -182,7 +180,7 @@ func GetGroupsCountNum(group db.Group) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
var count int32
|
||||
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
@@ -198,7 +196,7 @@ func GetGroupById(groupId string) (db.Group, error) {
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
|
||||
return group, err
|
||||
}
|
||||
@@ -211,9 +209,17 @@ func GetGroupMaster(groupId string) (db.GroupMember, error) {
|
||||
if err != nil {
|
||||
return groupMember, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err := dbConn.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
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -74,12 +74,25 @@ func GetUserByUserID(userID string) (*db.User, error) {
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
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
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return user.Nickname, nil
|
||||
}
|
||||
|
||||
func UpdateUserInfo(user db.User) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
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
|
||||
}
|
||||
@@ -99,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
|
||||
}
|
||||
@@ -118,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
|
||||
@@ -191,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
|
||||
}
|
||||
@@ -235,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
|
||||
}
|
||||
@@ -262,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
|
||||
}
|
||||
@@ -272,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
|
||||
@@ -285,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
|
||||
@@ -298,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")
|
||||
@@ -312,12 +325,31 @@ func SetConversation(conversation db.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 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return dbConn.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
|
||||
|
||||
}
|
||||
|
||||
func SetRecvMsgOpt(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
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")
|
||||
@@ -337,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])
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ func loggerInit(moduleName string) *Logger {
|
||||
}
|
||||
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
||||
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "debug", moduleName),
|
||||
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "info", moduleName),
|
||||
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "warn", moduleName),
|
||||
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "error", moduleName),
|
||||
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
}, &nested.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||
HideKeys: false,
|
||||
|
||||
@@ -101,7 +101,7 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
|
||||
}
|
||||
|
||||
func IsAppManagerAccess(token string, OpUserID string) bool {
|
||||
claims, err := ParseToken(token)
|
||||
claims, err := ParseToken(token, "")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func CheckAccess(OpUserID string, OwnerUserID string) bool {
|
||||
}
|
||||
|
||||
func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
||||
claims, err := ParseToken(token)
|
||||
claims, err := ParseToken(token, operationID)
|
||||
if err != nil {
|
||||
log.Error(operationID, "ParseToken failed, ", err.Error(), token)
|
||||
return false, ""
|
||||
@@ -138,31 +138,31 @@ func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
||||
return true, claims.UID
|
||||
}
|
||||
|
||||
func ParseToken(tokensString string) (claims *Claims, err error) {
|
||||
|
||||
func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
|
||||
claims, err = GetClaimFromToken(tokensString)
|
||||
if err != nil {
|
||||
log.NewError("", "token validate err", err.Error())
|
||||
log.NewError(operationID, "token validate err", err.Error(), tokensString)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
||||
if err != nil {
|
||||
log.NewError("", "get token from redis err", err.Error())
|
||||
log.NewError(operationID, "get token from redis err", err.Error(), tokensString)
|
||||
return nil, &constant.ErrTokenInvalid
|
||||
}
|
||||
if m == nil {
|
||||
log.NewError("", "get token from redis err", "m is nil")
|
||||
log.NewError(operationID, "get token from redis err", "m is nil", tokensString)
|
||||
return nil, &constant.ErrTokenInvalid
|
||||
}
|
||||
if v, ok := m[tokensString]; ok {
|
||||
switch v {
|
||||
case constant.NormalToken:
|
||||
log.NewDebug("", "this is normal return", claims)
|
||||
log.NewDebug(operationID, "this is normal return", claims)
|
||||
return claims, nil
|
||||
case constant.InValidToken:
|
||||
return nil, &constant.ErrTokenInvalid
|
||||
case constant.KickedToken:
|
||||
log.Error(operationID, "this token has been kicked by other same terminal ", constant.ErrTokenKicked)
|
||||
return nil, &constant.ErrTokenKicked
|
||||
case constant.ExpiredToken:
|
||||
return nil, &constant.ErrTokenExpired
|
||||
@@ -170,6 +170,7 @@ func ParseToken(tokensString string) (claims *Claims, err error) {
|
||||
return nil, &constant.ErrTokenUnknown
|
||||
}
|
||||
}
|
||||
log.NewError(operationID, "redis token map not find", constant.ErrTokenUnknown)
|
||||
return nil, &constant.ErrTokenUnknown
|
||||
}
|
||||
|
||||
@@ -195,7 +196,7 @@ func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {
|
||||
|
||||
//Validation token, false means failure, true means successful verification
|
||||
func VerifyToken(token, uid string) (bool, error) {
|
||||
claims, err := ParseToken(token)
|
||||
claims, err := ParseToken(token, "")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -207,7 +208,7 @@ func VerifyToken(token, uid string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
|
||||
claims, err := ParseToken(token)
|
||||
claims, err := ParseToken(token, "")
|
||||
if err != nil {
|
||||
return false, err, "parse token err"
|
||||
}
|
||||
|
||||
@@ -118,6 +118,14 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group
|
||||
dst.AppMangerLevel = 1
|
||||
}
|
||||
dst.JoinTime = int32(src.JoinTime.Unix())
|
||||
if src.MuteEndTime.Unix() < 0 {
|
||||
dst.JoinTime = 0
|
||||
return nil
|
||||
}
|
||||
dst.MuteEndTime = uint32(src.MuteEndTime.Unix())
|
||||
if dst.MuteEndTime < uint32(time.Now().Unix()) {
|
||||
dst.MuteEndTime = 0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+720
-178
File diff suppressed because it is too large
Load Diff
@@ -319,7 +319,7 @@ message AddGroupMembersCMSResp {
|
||||
}
|
||||
|
||||
message DismissGroupReq{
|
||||
string opUserID = 1; //group member or app manager
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
@@ -328,6 +328,59 @@ message DismissGroupResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message MuteGroupMemberReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
string userID = 4;
|
||||
uint32 mutedSeconds = 5;
|
||||
}
|
||||
|
||||
message MuteGroupMemberResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message CancelMuteGroupMemberReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
string userID = 4;
|
||||
}
|
||||
|
||||
message CancelMuteGroupMemberResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message MuteGroupReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message MuteGroupResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message CancelMuteGroupReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message CancelMuteGroupResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
service group{
|
||||
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
||||
rpc joinGroup(JoinGroupReq) returns(JoinGroupResp);
|
||||
@@ -356,6 +409,10 @@ service group{
|
||||
rpc AddGroupMembersCMS(AddGroupMembersCMSReq) returns(AddGroupMembersCMSResp);
|
||||
|
||||
rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp);
|
||||
rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
|
||||
rpc CancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
|
||||
rpc MuteGroup(MuteGroupReq) returns(MuteGroupResp);
|
||||
rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,118 @@
|
||||
syntax = "proto3";
|
||||
import "Open_IM/pkg/proto/sdk_ws/ws.proto";
|
||||
option go_package = "./office;office";
|
||||
package office;
|
||||
|
||||
message CommonResp{
|
||||
int32 errCode = 1;
|
||||
string errMsg = 2;
|
||||
}
|
||||
|
||||
message TagUser {
|
||||
string userID = 1;
|
||||
string userName = 2;
|
||||
}
|
||||
|
||||
message Tag {
|
||||
string tagID = 1;
|
||||
string tagName = 2;
|
||||
repeated TagUser userList = 3;
|
||||
}
|
||||
|
||||
message GetUserTagsReq{
|
||||
string userID = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message GetUserTagsResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated Tag tags = 2;
|
||||
}
|
||||
|
||||
message CreateTagReq {
|
||||
string tagName = 1;
|
||||
string userID = 2;
|
||||
repeated string userIDList = 3;
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message CreateTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message DeleteTagReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message DeleteTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message SetTagReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string newName = 3;
|
||||
repeated string increaseUserIDList = 4;
|
||||
repeated string reduceUserIDList = 5;
|
||||
string operationID = 6;
|
||||
}
|
||||
|
||||
message SetTagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message SendMsg2TagReq {
|
||||
repeated string tagList = 1;
|
||||
repeated string UserList = 2;
|
||||
repeated string GroupList = 3;
|
||||
string sendID = 4;
|
||||
int32 senderPlatformID = 5;
|
||||
string content = 6;
|
||||
string operationID = 7;
|
||||
}
|
||||
|
||||
message SendMsg2TagResp {
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetTagSendLogsReq {
|
||||
server_api_params.RequestPagination Pagination = 1;
|
||||
string userID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message TagSendLog {
|
||||
repeated TagUser userList = 1;
|
||||
string content = 2;
|
||||
int64 sendTime = 3;
|
||||
}
|
||||
|
||||
message GetTagSendLogsResp {
|
||||
CommonResp commonResp = 1;
|
||||
server_api_params.ResponsePagination Pagination = 2;
|
||||
repeated TagSendLog tagSendLogs = 3;
|
||||
}
|
||||
|
||||
message GetUserTagByIDReq {
|
||||
string userID = 1;
|
||||
string tagID = 2;
|
||||
string operationID = 3;
|
||||
}
|
||||
|
||||
message GetUserTagByIDResp {
|
||||
CommonResp commonResp = 1;
|
||||
Tag tag = 2;
|
||||
}
|
||||
|
||||
service OfficeService {
|
||||
rpc GetUserTags(GetUserTagsReq) returns(GetUserTagsResp);
|
||||
rpc CreateTag(CreateTagReq) returns(CreateTagResp);
|
||||
rpc DeleteTag(DeleteTagReq) returns(DeleteTagResp);
|
||||
rpc SetTag(SetTagReq) returns(SetTagResp);
|
||||
rpc SendMsg2Tag(SendMsg2TagReq) returns(SendMsg2TagResp);
|
||||
rpc GetTagSendLogs(GetTagSendLogsReq) returns(GetTagSendLogsResp);
|
||||
rpc GetUserTagByID(GetUserTagByIDReq) returns(GetUserTagByIDResp);
|
||||
}
|
||||
|
||||
+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);
|
||||
}
|
||||
|
||||
+538
-223
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,7 @@ message GroupMemberFullInfo {
|
||||
int32 joinSource = 8;
|
||||
string operatorUserID = 9;
|
||||
string ex = 10;
|
||||
uint32 muteEndTime = 11;
|
||||
}
|
||||
|
||||
message PublicUserInfo{
|
||||
@@ -260,6 +261,33 @@ message GroupDismissedTips{
|
||||
int64 operationTime = 3;
|
||||
}
|
||||
|
||||
message GroupMemberMutedTips{
|
||||
GroupInfo group = 1;
|
||||
GroupMemberFullInfo opUser = 2;
|
||||
int64 operationTime = 3;
|
||||
GroupMemberFullInfo mutedUser = 4;
|
||||
uint32 mutedSeconds = 5;
|
||||
}
|
||||
|
||||
message GroupMemberCancelMutedTips{
|
||||
GroupInfo group = 1;
|
||||
GroupMemberFullInfo opUser = 2;
|
||||
int64 operationTime = 3;
|
||||
GroupMemberFullInfo mutedUser = 4;
|
||||
}
|
||||
|
||||
message GroupMutedTips{
|
||||
GroupInfo group = 1;
|
||||
GroupMemberFullInfo opUser = 2;
|
||||
int64 operationTime = 3;
|
||||
}
|
||||
|
||||
message GroupCancelMutedTips{
|
||||
GroupInfo group = 1;
|
||||
GroupMemberFullInfo opUser = 2;
|
||||
int64 operationTime = 3;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////friend/////////////////////
|
||||
//message FriendInfo{
|
||||
@@ -332,7 +360,12 @@ message UserInfoUpdatedTips{
|
||||
//////////////////////conversation/////////////////////
|
||||
message ConversationUpdateTips{
|
||||
string UserID = 1;
|
||||
}
|
||||
|
||||
message ConversationSetPrivateTips{
|
||||
string recvID = 1;
|
||||
string sendID = 2;
|
||||
bool isPrivate = 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -473,7 +506,7 @@ message DelMsgListReq{
|
||||
}
|
||||
|
||||
message DelMsgListResp{
|
||||
int32 errCode = 1;
|
||||
int32 errCode = 1;
|
||||
string errMsg = 2;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user