Compare commits
199 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 | ||
|
|
9d29d49ada | ||
|
|
e7b95892ff | ||
|
|
4bf5c77374 | ||
|
|
df4a75f4b0 | ||
|
|
4bdb4cbbb5 | ||
|
|
4cdcdee8e4 | ||
|
|
e6c36411cb | ||
|
|
a4788a95af | ||
|
|
b5de638c0b | ||
|
|
c1a210313e | ||
|
|
ab0ed67f81 | ||
|
|
5d54d5b7d6 | ||
|
|
1d09ffa529 | ||
|
|
eef9d15aaa | ||
|
|
8034ddc413 | ||
|
|
e75adb165a | ||
|
|
09ce0d5285 | ||
|
|
cc1ad41e94 | ||
|
|
8a38646bc5 | ||
|
|
a2b65f52f6 | ||
|
|
c16d8da784 | ||
|
|
a55582a018 | ||
|
|
ea6d472002 | ||
|
|
3dc4290f2a | ||
|
|
6c43f75f9f | ||
|
|
e0c6972bed | ||
|
|
1ab3e04cba | ||
|
|
1b8f664c8a | ||
|
|
7637b2bec2 | ||
|
|
cfab49a7dd | ||
|
|
91b9e50fd0 | ||
|
|
ebf7a1d40d | ||
|
|
d3a38963ae |
37
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
vendored
Normal file
37
.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -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:
|
||||||
|
<!---->
|
||||||
36
.github/ISSUE_TEMPLATE/deployment-issues.md
vendored
Normal file
36
.github/ISSUE_TEMPLATE/deployment-issues.md
vendored
Normal file
@@ -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
|
||||||
38
.github/ISSUE_TEMPLATE/update-.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/update-.md
vendored
Normal file
@@ -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
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@ out-test
|
|||||||
.github
|
.github
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
|
||||||
deploy/open_im_demo
|
deploy/open_im_demo
|
||||||
deploy/open_im_api
|
deploy/open_im_api
|
||||||
deploy/open_im_msg_gateway
|
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)
|
4. Start docker-compose with one click(Docker automatically pulls all images)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
cd Open-IM-Server
|
||||||
docker-compose up -d
|
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
|
./docker_check_service.sh
|
||||||
|
./check_all.sh
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
Submodule cmd/Open-IM-SDK-Core updated: a06dfeeda5...9d67999cec
@@ -7,21 +7,33 @@ import (
|
|||||||
"Open_IM/internal/api/friend"
|
"Open_IM/internal/api/friend"
|
||||||
"Open_IM/internal/api/group"
|
"Open_IM/internal/api/group"
|
||||||
"Open_IM/internal/api/manage"
|
"Open_IM/internal/api/manage"
|
||||||
|
"Open_IM/internal/api/office"
|
||||||
apiThird "Open_IM/internal/api/third"
|
apiThird "Open_IM/internal/api/third"
|
||||||
"Open_IM/internal/api/user"
|
"Open_IM/internal/api/user"
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
//"syscall"
|
//"syscall"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
f, _ := os.Create("../logs/api.log")
|
||||||
|
gin.DefaultWriter = io.MultiWriter(f)
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(utils.CorsHandler())
|
r.Use(utils.CorsHandler())
|
||||||
|
|
||||||
|
log.Info("load config: ", config.Config)
|
||||||
// user routing group, which handles user registration and login services
|
// user routing group, which handles user registration and login services
|
||||||
userRouterGroup := r.Group("/user")
|
userRouterGroup := r.Group("/user")
|
||||||
{
|
{
|
||||||
@@ -66,6 +78,11 @@ func main() {
|
|||||||
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
|
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
|
||||||
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
|
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
|
||||||
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList) //1
|
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList) //1
|
||||||
|
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
|
//certificate
|
||||||
authRouterGroup := r.Group("/auth")
|
authRouterGroup := r.Group("/auth")
|
||||||
@@ -77,7 +94,9 @@ func main() {
|
|||||||
thirdGroup := r.Group("/third")
|
thirdGroup := r.Group("/third")
|
||||||
{
|
{
|
||||||
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
|
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_storage_credential", apiThird.MinioStorageCredential)
|
||||||
|
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
|
||||||
}
|
}
|
||||||
//Message
|
//Message
|
||||||
chatGroup := r.Group("/msg")
|
chatGroup := r.Group("/msg")
|
||||||
@@ -106,12 +125,23 @@ func main() {
|
|||||||
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
||||||
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
||||||
}
|
}
|
||||||
apiThird.MinioInit()
|
// office
|
||||||
log.NewPrivateLog("api")
|
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")
|
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start api server, port: ", *ginPort)
|
||||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||||
if err != nil {
|
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 (
|
import (
|
||||||
"Open_IM/internal/cms_api"
|
"Open_IM/internal/cms_api"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -11,5 +12,6 @@ func main() {
|
|||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := cms_api.NewGinRouter()
|
router := cms_api.NewGinRouter()
|
||||||
router.Use(utils.CorsHandler())
|
router.Use(utils.CorsHandler())
|
||||||
|
fmt.Println("start cms api server, port: ", 8000)
|
||||||
router.Run(":" + "8000")
|
router.Run(":" + "8000")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,23 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/internal/demo/register"
|
"Open_IM/internal/demo/register"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 := gin.Default()
|
||||||
r.Use(utils.CorsHandler())
|
r.Use(utils.CorsHandler())
|
||||||
@@ -23,8 +31,12 @@ func main() {
|
|||||||
authRouterGroup.POST("/login", register.Login)
|
authRouterGroup.POST("/login", register.Login)
|
||||||
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||||
}
|
}
|
||||||
log.NewPrivateLog("demo")
|
|
||||||
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
||||||
flag.Parse()
|
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 (
|
import (
|
||||||
"Open_IM/internal/msg_gateway/gate"
|
"Open_IM/internal/msg_gateway/gate"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
rpcPort := flag.Int("rpc_port", 10400, "rpc listening port")
|
rpcPort := flag.Int("rpc_port", 10400, "rpc listening port")
|
||||||
wsPort := flag.Int("ws_port", 17778, "ws listening port")
|
wsPort := flag.Int("ws_port", 17778, "ws listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort)
|
||||||
gate.Init(*rpcPort, *wsPort)
|
gate.Init(*rpcPort, *wsPort)
|
||||||
gate.Run()
|
gate.Run()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -2,13 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/internal/msg_transfer/logic"
|
"Open_IM/internal/msg_transfer/logic"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
logic.Init()
|
logic.Init()
|
||||||
|
fmt.Println("start msg_transfer server")
|
||||||
logic.Run()
|
logic.Run()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/internal/push/logic"
|
"Open_IM/internal/push/logic"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,6 +14,8 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
|
fmt.Println("start push rpc server, port: ", *rpcPort)
|
||||||
logic.Init(*rpcPort)
|
logic.Init(*rpcPort)
|
||||||
logic.Run()
|
logic.Run()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
commonDB "Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.NewPrivateLog("timer")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
//for {
|
//for {
|
||||||
// fmt.Println("start delete mongodb expired record")
|
// fmt.Println("start delete mongodb expired record")
|
||||||
// timeUnixBegin := time.Now().Unix()
|
// timeUnixBegin := time.Now().Unix()
|
||||||
@@ -39,27 +37,27 @@ func main() {
|
|||||||
// time.Sleep(time.Duration(sleepTime) * time.Second)
|
// time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
for {
|
//for {
|
||||||
uidList, err := im_mysql_model.SelectAllUserID()
|
// uidList, err := im_mysql_model.SelectAllUserID()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
//log.NewError("999999", err.Error())
|
// //log.NewError("999999", err.Error())
|
||||||
} else {
|
// } else {
|
||||||
for _, v := range uidList {
|
// for _, v := range uidList {
|
||||||
minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
// minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
//log.NewError("999999", "get user minSeq err", err.Error(), v)
|
// //log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||||
continue
|
// continue
|
||||||
} else {
|
// } else {
|
||||||
err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
// err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
//log.NewError("999999", "set user minSeq err", err.Error(), v)
|
// //log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
time.Sleep(time.Duration(100) * time.Millisecond)
|
// time.Sleep(time.Duration(100) * time.Millisecond)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
|
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 11000, "rpc listening port")
|
rpcPort := flag.Int("port", 11000, "rpc listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start cms rpc server, port: ", *rpcPort)
|
||||||
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
|
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
rpcAuth "Open_IM/internal/rpc/auth"
|
rpcAuth "Open_IM/internal/rpc/auth"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
|
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start auth rpc server, port: ", *rpcPort)
|
||||||
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
|
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"Open_IM/internal/rpc/friend"
|
"Open_IM/internal/rpc/friend"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
|
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start friend rpc server, port: ", *rpcPort)
|
||||||
rpcServer := friend.NewFriendServer(*rpcPort)
|
rpcServer := friend.NewFriendServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"Open_IM/internal/rpc/group"
|
"Open_IM/internal/rpc/group"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10500, "get RpcGroupPort from cmd,default 16000 as port")
|
rpcPort := flag.Int("port", 10500, "get RpcGroupPort from cmd,default 16000 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start group rpc server, port: ", *rpcPort)
|
||||||
rpcServer := group.NewGroupServer(*rpcPort)
|
rpcServer := group.NewGroupServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
|
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10900, "rpc listening port")
|
rpcPort := flag.Int("port", 10900, "rpc listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start msg cms rpc server, port: ", *rpcPort)
|
||||||
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
|
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
rpcChat "Open_IM/internal/rpc/msg"
|
rpcChat "Open_IM/internal/rpc/msg"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10300, "rpc listening port")
|
rpcPort := flag.Int("port", 10300, "rpc listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start msg rpc server, port: ", *rpcPort)
|
||||||
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
|
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
23
cmd/rpc/open_im_office/Makefile
Normal file
23
cmd/rpc/open_im_office/Makefile
Normal file
@@ -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
|
||||||
15
cmd/rpc/open_im_office/main.go
Normal file
15
cmd/rpc/open_im_office/main.go
Normal file
@@ -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 (
|
import (
|
||||||
"Open_IM/internal/rpc/statistics"
|
"Open_IM/internal/rpc/statistics"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10800, "rpc listening port")
|
rpcPort := flag.Int("port", 10800, "rpc listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start statistics rpc server, port: ", *rpcPort)
|
||||||
rpcServer := statistics.NewStatisticsServer(*rpcPort)
|
rpcServer := statistics.NewStatisticsServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"Open_IM/internal/rpc/user"
|
"Open_IM/internal/rpc/user"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Println("start user rpc server, port: ", *rpcPort)
|
||||||
rpcServer := user.NewUserServer(*rpcPort)
|
rpcServer := user.NewUserServer(*rpcPort)
|
||||||
rpcServer.Run()
|
rpcServer.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ mysql:
|
|||||||
dbMaxLifeTime: 120
|
dbMaxLifeTime: 120
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||||
|
dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
dbDatabase: openIM #mongo db 默认即可
|
dbDatabase: openIM #mongo db 默认即可
|
||||||
@@ -72,6 +73,7 @@ endpoints:
|
|||||||
rpc_statistic: openim_rpc_statistic
|
rpc_statistic: openim_rpc_statistic
|
||||||
rpc_admin_cms: openim_rpc_admin_cms
|
rpc_admin_cms: openim_rpc_admin_cms
|
||||||
rpc_message_cms: openim_rpc_admin_cms
|
rpc_message_cms: openim_rpc_admin_cms
|
||||||
|
rpc_office: openim_rpc_office
|
||||||
|
|
||||||
api:
|
api:
|
||||||
openImApiPort: [ 10000 ] #api服务端口,默认即可,需要开放此端口或做nginx转发
|
openImApiPort: [ 10000 ] #api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||||
@@ -90,9 +92,20 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申
|
|||||||
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
||||||
bucket: openim
|
bucket: openim
|
||||||
location: us-east-1
|
location: us-east-1
|
||||||
endpoint: http://127.0.0.1:9000
|
endpoint: http://121.37.25.71:9000
|
||||||
accessKeyID: user12345
|
accessKeyID: user12345
|
||||||
secretAccessKey: key12345
|
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服务端口 默认即可
|
rpcport: #rpc服务端口 默认即可
|
||||||
@@ -106,6 +119,7 @@ rpcport: #rpc服务端口 默认即可
|
|||||||
openImStatisticsPort: [ 10800 ]
|
openImStatisticsPort: [ 10800 ]
|
||||||
openImMessageCmsPort: [ 10900 ]
|
openImMessageCmsPort: [ 10900 ]
|
||||||
openImAdminCmsPort: [ 11000 ]
|
openImAdminCmsPort: [ 11000 ]
|
||||||
|
openImOfficePort: [ 11100 ]
|
||||||
c2c:
|
c2c:
|
||||||
callbackBeforeSendMsg:
|
callbackBeforeSendMsg:
|
||||||
switch: false
|
switch: false
|
||||||
@@ -127,6 +141,7 @@ rpcregistername: #rpc注册服务名,默认即可
|
|||||||
OpenImStatisticsName: Statistics
|
OpenImStatisticsName: Statistics
|
||||||
OpenImMessageCMSName: MessageCMS
|
OpenImMessageCMSName: MessageCMS
|
||||||
openImAdminCMSName: AdminCMS
|
openImAdminCMSName: AdminCMS
|
||||||
|
openImOfficeName: Office
|
||||||
|
|
||||||
log:
|
log:
|
||||||
storageLocation: ../logs/
|
storageLocation: ../logs/
|
||||||
@@ -150,6 +165,7 @@ longconnsvr:
|
|||||||
websocketMaxMsgLen: 4096
|
websocketMaxMsgLen: 4096
|
||||||
websocketTimeOut: 10
|
websocketTimeOut: 10
|
||||||
|
|
||||||
|
## 推送只能开启一个
|
||||||
push:
|
push:
|
||||||
tpns: #腾讯推送,暂未测试 暂不要使用
|
tpns: #腾讯推送,暂未测试 暂不要使用
|
||||||
ios:
|
ios:
|
||||||
@@ -158,11 +174,22 @@ push:
|
|||||||
android:
|
android:
|
||||||
accessID: 111
|
accessID: 111
|
||||||
secretKey: 111
|
secretKey: 111
|
||||||
|
enable: false
|
||||||
jpns: #极光推送 在极光后台申请后,修改以下四项,必须修改
|
jpns: #极光推送 在极光后台申请后,修改以下四项,必须修改
|
||||||
appKey: cf47465a368f24c659608e7e
|
appKey: cf47465a368f24c659608e7e
|
||||||
masterSecret: 02204efe3f3832947a236ee5
|
masterSecret: 02204efe3f3832947a236ee5
|
||||||
pushUrl: "https://api.jpush.cn/v3/push"
|
pushUrl: "https://api.jpush.cn/v3/push"
|
||||||
pushIntent: "intent:#Intent;component=io.openim.app.enterprisechat/io.openim.app.enterprisechat.MainActivity;end"
|
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:
|
manager:
|
||||||
#app管理员userID和对应的secret 建议修改。 用于管理后台登录,也可以用户管理后台对应的api
|
#app管理员userID和对应的secret 建议修改。 用于管理后台登录,也可以用户管理后台对应的api
|
||||||
appManagerUid: [ "openIM123456","openIM654321", "openIM333", "openIMAdmin"]
|
appManagerUid: [ "openIM123456","openIM654321", "openIM333", "openIMAdmin"]
|
||||||
@@ -340,6 +367,67 @@ notification:
|
|||||||
defaultTips:
|
defaultTips:
|
||||||
tips: "entered the group" # group info changed by xx
|
tips: "entered the group" # group info changed by xx
|
||||||
|
|
||||||
|
groupDismissed:
|
||||||
|
conversation:
|
||||||
|
reliabilityLevel: 3
|
||||||
|
unreadCount: true
|
||||||
|
offlinePush:
|
||||||
|
switch: false
|
||||||
|
title: "groupDismissed title"
|
||||||
|
desc: "groupDismissed desc"
|
||||||
|
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#################################
|
#############################friend#################################
|
||||||
|
|
||||||
friendApplicationAdded:
|
friendApplicationAdded:
|
||||||
@@ -475,6 +563,19 @@ notification:
|
|||||||
defaultTips:
|
defaultTips:
|
||||||
tips: "conversation opt update"
|
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---------------------#
|
#---------------demo configuration---------------------#
|
||||||
@@ -499,5 +600,6 @@ demo:
|
|||||||
smtpAddr: "smtp.qq.com"
|
smtpAddr: "smtp.qq.com"
|
||||||
smtpPort: 25 #需开放此端口 出口方向
|
smtpPort: 25 #需开放此端口 出口方向
|
||||||
|
|
||||||
|
rtc:
|
||||||
|
port: 11300
|
||||||
|
address: 127.0.0.1
|
||||||
@@ -19,6 +19,7 @@ mysql:
|
|||||||
dbMaxLifeTime: 120
|
dbMaxLifeTime: 120
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
|
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||||
dbAddress: [ openim_mongo:27017 ]
|
dbAddress: [ openim_mongo:27017 ]
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 10
|
dbTimeout: 10
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ services:
|
|||||||
# - MONGO_INITDB_ROOT_USERNAME=openIM
|
# - MONGO_INITDB_ROOT_USERNAME=openIM
|
||||||
# - MONGO_INITDB_ROOT_PASSWORD=openIM
|
# - MONGO_INITDB_ROOT_PASSWORD=openIM
|
||||||
|
|
||||||
|
|
||||||
#TZ: Asia/Shanghai
|
#TZ: Asia/Shanghai
|
||||||
restart: always
|
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
|
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:
|
open_im_server:
|
||||||
image: openim/open_im_server:v2.0.2
|
image: openim/open_im_server:v2.0.7
|
||||||
container_name: open_im_server
|
container_name: open_im_server
|
||||||
volumes:
|
volumes:
|
||||||
- ./logs:/Open-IM-Server/logs
|
- ./logs:/Open-IM-Server/logs
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -7,6 +7,7 @@ require (
|
|||||||
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
|
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
|
||||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
||||||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8
|
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/alibabacloud-go/tea v1.1.17
|
||||||
github.com/antonfisher/nested-logrus-formatter v1.3.0
|
github.com/antonfisher/nested-logrus-formatter v1.3.0
|
||||||
github.com/bwmarrin/snowflake v0.3.0
|
github.com/bwmarrin/snowflake v0.3.0
|
||||||
@@ -21,7 +22,7 @@ require (
|
|||||||
github.com/gin-gonic/gin v1.7.0
|
github.com/gin-gonic/gin v1.7.0
|
||||||
github.com/go-playground/validator/v10 v10.4.1
|
github.com/go-playground/validator/v10 v10.4.1
|
||||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
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-jwt/jwt/v4 v4.1.0
|
||||||
github.com/golang/protobuf v1.5.2
|
github.com/golang/protobuf v1.5.2
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
@@ -59,6 +60,7 @@ require (
|
|||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
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/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -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-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-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
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 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8=
|
||||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU=
|
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=
|
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/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 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
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 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0=
|
||||||
github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
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.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.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=
|
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.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
|
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.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 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
|
||||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
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=
|
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)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||||
client := rpc.NewAuthClient(etcdConn)
|
client := rpc.NewAuthClient(etcdConn)
|
||||||
reply, err := client.UserRegister(context.Background(), req)
|
reply, err := client.UserRegister(context.Background(), req)
|
||||||
if err != nil || reply.CommonResp.ErrCode != 0 {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "UserRegister failed ", err, reply.CommonResp.ErrCode)
|
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})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": reply.CommonResp.ErrMsg})
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
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)
|
client := pbUser.NewUserClient(etcdConn)
|
||||||
respPb, err := client.GetConversation(context.Background(), &reqPb)
|
respPb, err := client.GetConversation(context.Background(), &reqPb)
|
||||||
if err != nil {
|
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()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ func SetRecvMsgOpt(c *gin.Context) {
|
|||||||
client := pbUser.NewUserClient(etcdConn)
|
client := pbUser.NewUserClient(etcdConn)
|
||||||
respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb)
|
respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb)
|
||||||
if err != nil {
|
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()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -201,3 +201,18 @@ func SetRecvMsgOpt(c *gin.Context) {
|
|||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Deprecated
|
||||||
|
func SetReceiveMessageOpt(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Deprecated
|
||||||
|
func GetReceiveMessageOpt(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Deprecated
|
||||||
|
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ func CreateGroup(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.OwnerUserID = req.OpUserID
|
req.OwnerUserID = params.OwnerUserID
|
||||||
req.OperationID = params.OperationID
|
req.OperationID = params.OperationID
|
||||||
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
||||||
|
|
||||||
@@ -536,3 +536,163 @@ func TransferGroupOwner(c *gin.Context) {
|
|||||||
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
|
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DismissGroup(c *gin.Context) {
|
||||||
|
params := api.DismissGroupReq{}
|
||||||
|
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.DismissGroupReq{}
|
||||||
|
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(), " 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.DismissGroup(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.DismissGroupResp{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 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"
|
"context"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -29,6 +30,7 @@ var validate *validator.Validate
|
|||||||
|
|
||||||
func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||||
var newContent string
|
var newContent string
|
||||||
|
var err error
|
||||||
switch params.ContentType {
|
switch params.ContentType {
|
||||||
case constant.Text:
|
case constant.Text:
|
||||||
newContent = params.Content["text"].(string)
|
newContent = params.Content["text"].(string)
|
||||||
@@ -40,6 +42,9 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
|||||||
fallthrough
|
fallthrough
|
||||||
case constant.File:
|
case constant.File:
|
||||||
newContent = utils.StructToJsonString(params.Content)
|
newContent = utils.StructToJsonString(params.Content)
|
||||||
|
case constant.Revoke:
|
||||||
|
newContent = params.Content["revokeMsgClientID"].(string)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
var options map[string]bool
|
var options map[string]bool
|
||||||
@@ -70,6 +75,14 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
|||||||
OfflinePushInfo: params.OfflinePushInfo,
|
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
|
return &pbData
|
||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
@@ -103,7 +116,11 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
//case constant.Location:
|
//case constant.Location:
|
||||||
case constant.Custom:
|
case constant.Custom:
|
||||||
data = CustomElem{}
|
data = CustomElem{}
|
||||||
//case constant.Revoke:
|
case constant.Revoke:
|
||||||
|
data = RevokeElem{}
|
||||||
|
case constant.OANotification:
|
||||||
|
data = OANotificationElem{}
|
||||||
|
params.SessionType = constant.NotificationChatType
|
||||||
//case constant.HasReadReceipt:
|
//case constant.HasReadReceipt:
|
||||||
//case constant.Typing:
|
//case constant.Typing:
|
||||||
//case constant.Quote:
|
//case constant.Quote:
|
||||||
@@ -121,12 +138,13 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
log.ErrorByKv("data args validate err", "", "err", err.Error())
|
log.ErrorByKv("data args validate err", "", "err", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.NewInfo("", data, params)
|
||||||
token := c.Request.Header.Get("token")
|
token := c.Request.Header.Get("token")
|
||||||
claims, err := token_verify.ParseToken(token)
|
claims, err := token_verify.ParseToken(token, params.OperationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(params.OperationID, "parse token failed", err.Error())
|
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
|
||||||
@@ -138,11 +156,13 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
if len(params.RecvID) == 0 {
|
if len(params.RecvID) == 0 {
|
||||||
log.NewError(params.OperationID, "recvID is a null string")
|
log.NewError(params.OperationID, "recvID is a null string")
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "recvID is a null string", "sendTime": 0, "MsgID": ""})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "recvID is a null string", "sendTime": 0, "MsgID": ""})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case constant.GroupChatType:
|
case constant.GroupChatType:
|
||||||
if len(params.GroupID) == 0 {
|
if len(params.GroupID) == 0 {
|
||||||
log.NewError(params.OperationID, "groupID is a null string")
|
log.NewError(params.OperationID, "groupID is a null string")
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "groupID is a null string", "sendTime": 0, "MsgID": ""})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "groupID is a null string", "sendTime": 0, "MsgID": ""})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -198,16 +218,16 @@ type ManagementSendMsgReq struct {
|
|||||||
|
|
||||||
type PictureBaseInfo struct {
|
type PictureBaseInfo struct {
|
||||||
UUID string `mapstructure:"uuid"`
|
UUID string `mapstructure:"uuid"`
|
||||||
Type string `mapstructure:"type" validate:"required"`
|
Type string `mapstructure:"type" `
|
||||||
Size int64 `mapstructure:"size" validate:"required"`
|
Size int64 `mapstructure:"size" `
|
||||||
Width int32 `mapstructure:"width" validate:"required"`
|
Width int32 `mapstructure:"width" `
|
||||||
Height int32 `mapstructure:"height" validate:"required"`
|
Height int32 `mapstructure:"height"`
|
||||||
Url string `mapstructure:"url" validate:"required"`
|
Url string `mapstructure:"url" `
|
||||||
}
|
}
|
||||||
|
|
||||||
type PictureElem struct {
|
type PictureElem struct {
|
||||||
SourcePath string `mapstructure:"sourcePath"`
|
SourcePath string `mapstructure:"sourcePath"`
|
||||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
|
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
|
||||||
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
||||||
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
||||||
}
|
}
|
||||||
@@ -257,3 +277,20 @@ type CustomElem struct {
|
|||||||
type TextElem struct {
|
type TextElem struct {
|
||||||
Text string `mapstructure:"text" validate:"required"`
|
Text string `mapstructure:"text" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|||||||
280
internal/api/office/tag.go
Normal file
280
internal/api/office/tag.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
95
internal/api/third/ali_oss_credential.go
Normal file
95
internal/api/third/ali_oss_credential.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -10,18 +10,26 @@ import (
|
|||||||
url2 "net/url"
|
url2 "net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
minioClient *minio.Client
|
||||||
|
)
|
||||||
|
|
||||||
func MinioInit() {
|
func MinioInit() {
|
||||||
|
operationID := utils.OperationIDGenerator()
|
||||||
|
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio)
|
||||||
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
minioClient, err := minio.New(minioUrl.Host, &minio.Options{
|
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, ""),
|
Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
|
||||||
Secure: false,
|
Secure: false,
|
||||||
})
|
})
|
||||||
|
log.NewInfo(operationID, utils.GetSelfFuncName(), "new ok ", config.Config.Credential.Minio)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
opt := minio.MakeBucketOptions{
|
opt := minio.MakeBucketOptions{
|
||||||
@@ -30,15 +38,15 @@ func MinioInit() {
|
|||||||
}
|
}
|
||||||
err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
|
err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
|
||||||
if err != nil {
|
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)
|
exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||||
if err == nil && exists {
|
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 {
|
} else {
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,5 +56,5 @@ func MinioInit() {
|
|||||||
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success")
|
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio create and set policy success")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,89 @@ import (
|
|||||||
"Open_IM/pkg/common/token_verify"
|
"Open_IM/pkg/common/token_verify"
|
||||||
_ "Open_IM/pkg/common/token_verify"
|
_ "Open_IM/pkg/common/token_verify"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
|
"context"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
_ "github.com/minio/minio-go/v7"
|
_ "github.com/minio/minio-go/v7"
|
||||||
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
cr "github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func MinioUploadFile(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
req apiStruct.MinioUploadFileReq
|
||||||
|
resp apiStruct.MinioUploadFileResp
|
||||||
|
)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), r)
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file or snapShot args"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if err := c.Bind(&req); err != nil {
|
||||||
|
log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||||
|
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 {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing snapshot arg: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
snapShotFileObj, err := snapShotFile.Open()
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
snapShotNewName, snapShotNewType := utils.GetNewFileNameAndContentType(snapShotFile.Filename, constant.ImageType)
|
||||||
|
log.Debug(req.OperationID, utils.GetSelfFuncName(), snapShotNewName, snapShotNewType)
|
||||||
|
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, snapShotNewName, snapShotFileObj, snapShotFile.Size, minio.PutObjectOptions{ContentType: snapShotNewType})
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "PutObject snapShotFile error", err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.SnapshotURL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + snapShotNewName
|
||||||
|
resp.SnapshotNewName = snapShotNewName
|
||||||
|
}
|
||||||
|
file, err := c.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "missing file arg: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fileObj, err := file.Open()
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "Open file error", err.Error())
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newName, newType := utils.GetNewFileNameAndContentType(file.Filename, req.FileType)
|
||||||
|
log.Debug(req.OperationID, utils.GetSelfFuncName(), newName, newType)
|
||||||
|
_, 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.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.NewName = newName
|
||||||
|
resp.URL = config.Config.Credential.Minio.Endpoint + "/" + config.Config.Credential.Minio.Bucket + "/" + newName
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func MinioStorageCredential(c *gin.Context) {
|
func MinioStorageCredential(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
req apiStruct.MinioStorageCredentialReq
|
req apiStruct.MinioStorageCredentialReq
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ func GetGroupById(c *gin.Context) {
|
|||||||
resp.ProfilePhoto = respPb.CMSGroup.GroupInfo.FaceURL
|
resp.ProfilePhoto = respPb.CMSGroup.GroupInfo.FaceURL
|
||||||
resp.GroupMasterName = respPb.CMSGroup.GroupMasterName
|
resp.GroupMasterName = respPb.CMSGroup.GroupMasterName
|
||||||
resp.GroupMasterId = respPb.CMSGroup.GroupMasterId
|
resp.GroupMasterId = respPb.CMSGroup.GroupMasterId
|
||||||
|
resp.IsBanChat = constant.GroupIsBanChat(respPb.CMSGroup.GroupInfo.Status)
|
||||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ func GetGroups(c *gin.Context) {
|
|||||||
GroupMasterName: v.GroupMasterName,
|
GroupMasterName: v.GroupMasterName,
|
||||||
GroupMasterId: v.GroupMasterId,
|
GroupMasterId: v.GroupMasterId,
|
||||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||||
IsBanChat: false,
|
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||||
IsBanPrivateChat: false,
|
IsBanPrivateChat: false,
|
||||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||||
})
|
})
|
||||||
@@ -114,7 +115,7 @@ func GetGroupByName(c *gin.Context) {
|
|||||||
GroupMasterName: v.GroupMasterName,
|
GroupMasterName: v.GroupMasterName,
|
||||||
GroupMasterId: v.GroupMasterId,
|
GroupMasterId: v.GroupMasterId,
|
||||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||||
IsBanChat: false,
|
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||||
IsBanPrivateChat: false,
|
IsBanPrivateChat: false,
|
||||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
type ParamsSetPassword struct {
|
type ParamsSetPassword struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
Name string `json:"name"`
|
||||||
PhoneNumber string `json:"phoneNumber"`
|
PhoneNumber string `json:"phoneNumber"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
VerificationCode string `json:"verificationCode"`
|
VerificationCode string `json:"verificationCode"`
|
||||||
@@ -38,6 +39,9 @@ func SetPassword(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
account = params.PhoneNumber
|
account = params.PhoneNumber
|
||||||
}
|
}
|
||||||
|
if params.Name == "" {
|
||||||
|
params.Name = account
|
||||||
|
}
|
||||||
if params.VerificationCode != config.Config.Demo.SuperCode {
|
if params.VerificationCode != config.Config.Demo.SuperCode {
|
||||||
accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
|
accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||||
v, err := db.DB.GetAccountCode(accountKey)
|
v, err := db.DB.GetAccountCode(accountKey)
|
||||||
@@ -54,7 +58,7 @@ func SetPassword(c *gin.Context) {
|
|||||||
openIMRegisterReq.OperationID = params.OperationID
|
openIMRegisterReq.OperationID = params.OperationID
|
||||||
openIMRegisterReq.Platform = params.Platform
|
openIMRegisterReq.Platform = params.Platform
|
||||||
openIMRegisterReq.UserID = account
|
openIMRegisterReq.UserID = account
|
||||||
openIMRegisterReq.Nickname = account
|
openIMRegisterReq.Nickname = params.Name
|
||||||
openIMRegisterReq.Secret = config.Config.Secret
|
openIMRegisterReq.Secret = config.Config.Secret
|
||||||
openIMRegisterResp := api.UserRegisterResp{}
|
openIMRegisterResp := api.UserRegisterResp{}
|
||||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||||
@@ -69,7 +73,7 @@ func SetPassword(c *gin.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
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
|
return
|
||||||
}
|
}
|
||||||
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"Open_IM/pkg/statistics"
|
"Open_IM/pkg/statistics"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
@@ -20,7 +20,7 @@ var (
|
|||||||
|
|
||||||
func Init(rpcPort, wsPort int) {
|
func Init(rpcPort, wsPort int) {
|
||||||
//log initialization
|
//log initialization
|
||||||
log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName)
|
|
||||||
rwLock = new(sync.RWMutex)
|
rwLock = new(sync.RWMutex)
|
||||||
validate = validator.New()
|
validate = validator.New()
|
||||||
statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300)
|
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/common/log"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
pbChat "Open_IM/pkg/proto/chat"
|
pbChat "Open_IM/pkg/proto/chat"
|
||||||
|
pbRtc "Open_IM/pkg/proto/rtc"
|
||||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"google.golang.org/grpc"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,7 +32,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
dec := gob.NewDecoder(b)
|
dec := gob.NewDecoder(b)
|
||||||
err := dec.Decode(&m)
|
err := dec.Decode(&m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorByKv("ws Decode err", "", "err", err.Error())
|
log.NewError("", "ws Decode err", err.Error())
|
||||||
ws.sendErrMsg(conn, 200, err.Error(), constant.WSDataError, "", "")
|
ws.sendErrMsg(conn, 200, err.Error(), constant.WSDataError, "", "")
|
||||||
err = conn.Close()
|
err = conn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -37,7 +41,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := validate.Struct(m); err != nil {
|
if err := validate.Struct(m); err != nil {
|
||||||
log.ErrorByKv("ws args validate err", "", "err", err.Error())
|
log.NewError("", "ws args validate err", err.Error())
|
||||||
ws.sendErrMsg(conn, 201, err.Error(), m.ReqIdentifier, m.MsgIncr, m.OperationID)
|
ws.sendErrMsg(conn, 201, err.Error(), m.ReqIdentifier, m.MsgIncr, m.OperationID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -45,7 +49,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
// ws.sendErrMsg(conn, 202, "token validate err", m.ReqIdentifier, m.MsgIncr,m.OperationID)
|
// ws.sendErrMsg(conn, 202, "token validate err", m.ReqIdentifier, m.MsgIncr,m.OperationID)
|
||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
log.InfoByKv("Basic Info Authentication Success", m.OperationID, "reqIdentifier", m.ReqIdentifier, "sendID", m.SendID, "msgIncr", m.MsgIncr)
|
log.NewInfo(m.OperationID, "Basic Info Authentication Success", m)
|
||||||
|
|
||||||
switch m.ReqIdentifier {
|
switch m.ReqIdentifier {
|
||||||
case constant.WSGetNewestSeq:
|
case constant.WSGetNewestSeq:
|
||||||
@@ -61,7 +65,7 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
log.NewInfo("", "goroutine num is ", runtime.NumGoroutine())
|
log.NewInfo("", "goroutine num is ", runtime.NumGoroutine())
|
||||||
}
|
}
|
||||||
func (ws *WServer) getSeqReq(conn *UserConn, m *Req) {
|
func (ws *WServer) getSeqReq(conn *UserConn, m *Req) {
|
||||||
log.NewInfo(m.OperationID, "Ws call success to getNewSeq", m.MsgIncr, m.SendID, m.ReqIdentifier)
|
log.NewInfo(m.OperationID, "Ws call success to getNewSeq", m.MsgIncr, m.SendID, m.ReqIdentifier, m.Data)
|
||||||
rpcReq := pbChat.GetMaxAndMinSeqReq{}
|
rpcReq := pbChat.GetMaxAndMinSeqReq{}
|
||||||
nReply := new(pbChat.GetMaxAndMinSeqResp)
|
nReply := new(pbChat.GetMaxAndMinSeqResp)
|
||||||
rpcReq.UserID = m.SendID
|
rpcReq.UserID = m.SendID
|
||||||
@@ -99,15 +103,15 @@ func (ws *WServer) getSeqResp(conn *UserConn, m *Req, pb *pbChat.GetMaxAndMinSeq
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) {
|
func (ws *WServer) pullMsgBySeqListReq(conn *UserConn, m *Req) {
|
||||||
log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq start", m.SendID, m.ReqIdentifier, m.MsgIncr)
|
log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq start", m.SendID, m.ReqIdentifier, m.MsgIncr, m.Data)
|
||||||
nReply := new(sdk_ws.PullMessageBySeqListResp)
|
nReply := new(sdk_ws.PullMessageBySeqListResp)
|
||||||
isPass, errCode, errMsg, data := ws.argsValidate(m, constant.WSPullMsgBySeqList)
|
isPass, errCode, errMsg, data := ws.argsValidate(m, constant.WSPullMsgBySeqList)
|
||||||
log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq middle", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(sdk_ws.PullMessageBySeqListReq).SeqList)
|
|
||||||
if isPass {
|
if isPass {
|
||||||
rpcReq := sdk_ws.PullMessageBySeqListReq{}
|
rpcReq := sdk_ws.PullMessageBySeqListReq{}
|
||||||
rpcReq.SeqList = data.(sdk_ws.PullMessageBySeqListReq).SeqList
|
rpcReq.SeqList = data.(sdk_ws.PullMessageBySeqListReq).SeqList
|
||||||
rpcReq.UserID = m.SendID
|
rpcReq.UserID = m.SendID
|
||||||
rpcReq.OperationID = m.OperationID
|
rpcReq.OperationID = m.OperationID
|
||||||
|
log.NewInfo(m.OperationID, "Ws call success to pullMsgBySeqListReq middle", m.SendID, m.ReqIdentifier, m.MsgIncr, data.(sdk_ws.PullMessageBySeqListReq).SeqList)
|
||||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||||
msgClient := pbChat.NewChatClient(grpcConn)
|
msgClient := pbChat.NewChatClient(grpcConn)
|
||||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &rpcReq)
|
reply, err := msgClient.PullMessageBySeqList(context.Background(), &rpcReq)
|
||||||
@@ -145,7 +149,7 @@ func (ws *WServer) pullMsgBySeqListResp(conn *UserConn, m *Req, pb *sdk_ws.PullM
|
|||||||
}
|
}
|
||||||
func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) {
|
func (ws *WServer) sendMsgReq(conn *UserConn, m *Req) {
|
||||||
sendMsgCount++
|
sendMsgCount++
|
||||||
log.NewInfo(m.OperationID, "Ws call success to sendMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID)
|
log.NewInfo(m.OperationID, "Ws call success to sendMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID, m.Data)
|
||||||
nReply := new(pbChat.SendMsgResp)
|
nReply := new(pbChat.SendMsgResp)
|
||||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg)
|
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg)
|
||||||
if isPass {
|
if isPass {
|
||||||
@@ -196,44 +200,65 @@ func (ws *WServer) sendMsgResp(conn *UserConn, m *Req, pb *pbChat.SendMsgResp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID)
|
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID, m.Data)
|
||||||
nReply := new(pbChat.SendMsgResp)
|
nReply := new(pbChat.SendMsgResp)
|
||||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg)
|
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg)
|
||||||
log.NewInfo(m.OperationID, "args is ", pData.(*sdk_ws.SignalReq))
|
if isPass {
|
||||||
isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
signalResp := pbRtc.SignalResp{}
|
||||||
if isPass && isPass2 {
|
//isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
||||||
pbData := pbChat.SendMsgReq{
|
connGrpc, err := grpc.Dial(config.Config.Rtc.Address+":"+strconv.Itoa(config.Config.Rtc.Port), grpc.WithInsecure())
|
||||||
Token: m.Token,
|
|
||||||
OperationID: m.OperationID,
|
|
||||||
MsgData: msgData,
|
|
||||||
}
|
|
||||||
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 {
|
if err != nil {
|
||||||
log.NewError(pbData.OperationID, "rpc sendMsg err", err.Error())
|
log.NewError(m.OperationID, utils.GetSelfFuncName(), "grpc.Dial failed", err.Error())
|
||||||
nReply.ErrCode = 200
|
ws.sendSignalMsgResp(conn, 204, "create grpc failed"+err.Error(), m, nil)
|
||||||
nReply.ErrMsg = err.Error()
|
return
|
||||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, signalResp)
|
}
|
||||||
} else {
|
rtcClient := pbRtc.NewRtcServiceClient(connGrpc)
|
||||||
log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String())
|
req := &pbRtc.SignalMessageAssembleReq{
|
||||||
ws.sendSignalMsgResp(conn, 0, "", m, signalResp)
|
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,
|
||||||
|
}
|
||||||
|
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, utils.GetSelfFuncName(), "rpc sendMsg err", err.Error())
|
||||||
|
nReply.ErrCode = 200
|
||||||
|
nReply.ErrMsg = err.Error()
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 {
|
} else {
|
||||||
if isPass {
|
ws.sendSignalMsgResp(conn, errCode, errMsg, m, nil)
|
||||||
log.NewError(m.OperationID, isPass2, errCode2, errMsg2)
|
|
||||||
ws.sendSignalMsgResp(conn, errCode2, errMsg2, m, signalResp)
|
|
||||||
} else {
|
|
||||||
ws.sendSignalMsgResp(conn, errCode, errMsg, m, signalResp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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{})
|
// := make(map[string]interface{})
|
||||||
|
log.Debug(m.OperationID, "SignalMsgResp is", pb.String())
|
||||||
b, _ := proto.Marshal(pb)
|
b, _ := proto.Marshal(pb)
|
||||||
mReply := Resp{
|
mReply := Resp{
|
||||||
ReqIdentifier: m.ReqIdentifier,
|
ReqIdentifier: m.ReqIdentifier,
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
package open_im_media
|
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 (
|
const (
|
||||||
// Address gRPC服务地址
|
// Address gRPC服务地址
|
||||||
Address = "127.0.0.1:11300"
|
Address = "127.0.0.1:11300"
|
||||||
@@ -23,35 +14,35 @@ func NewMedia() *Media {
|
|||||||
return &Media{}
|
return &Media{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
//func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
||||||
var newData pbRtc.ParticipantMetaData
|
// var newData pbRtc.ParticipantMetaData
|
||||||
copier.Copy(&newData, data)
|
// copier.Copy(&newData, data)
|
||||||
conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
// conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", "", err
|
// return "", "", err
|
||||||
}
|
// }
|
||||||
defer conn.Close()
|
// defer conn.Close()
|
||||||
c := pbRtc.NewRtcServiceClient(conn)
|
// c := pbRtc.NewRtcServiceClient(conn)
|
||||||
req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
// req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
||||||
resp, err := c.GetJoinToken(context.Background(), req)
|
// resp, err := c.GetJoinToken(context.Background(), req)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", "", err
|
// return "", "", err
|
||||||
}
|
// }
|
||||||
if resp.CommonResp.ErrCode != 0 {
|
// if resp.CommonResp.ErrCode != 0 {
|
||||||
return "", "", errors.New(resp.CommonResp.ErrMsg)
|
// return "", "", errors.New(resp.CommonResp.ErrMsg)
|
||||||
}
|
// }
|
||||||
return resp.Jwt, resp.LiveURL, nil
|
// return resp.Jwt, resp.LiveURL, nil
|
||||||
//at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
// //at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
||||||
//grant := &auth.VideoGrant{
|
// //grant := &auth.VideoGrant{
|
||||||
// RoomJoin: true,
|
// // RoomJoin: true,
|
||||||
// Room: room,
|
// // Room: room,
|
||||||
//}
|
// //}
|
||||||
//at.AddGrant(grant).
|
// //at.AddGrant(grant).
|
||||||
// SetIdentity(identity).
|
// // SetIdentity(identity).
|
||||||
// SetValidFor(time.Hour)
|
// // SetValidFor(time.Hour)
|
||||||
//
|
// //
|
||||||
//return at.ToJWT()
|
// //return at.ToJWT()
|
||||||
}
|
//}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
||||||
|
|||||||
@@ -7,12 +7,10 @@
|
|||||||
package gate
|
package gate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/internal/msg_gateway/gate/open_im_media"
|
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
|
pbRtc "Open_IM/pkg/proto/rtc"
|
||||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
|
||||||
"errors"
|
|
||||||
"github.com/golang/protobuf/proto"
|
"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
|
return true, 0, "", data
|
||||||
case constant.WSSendSignalMsg:
|
case constant.WSSendSignalMsg:
|
||||||
data := open_im_sdk.SignalReq{}
|
data := pbRtc.SignalReq{}
|
||||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||||
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||||
return false, 203, err.Error(), nil
|
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) {
|
//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 msg open_im_sdk.MsgData
|
||||||
var resp open_im_sdk.SignalResp
|
// var resp open_im_sdk.SignalResp
|
||||||
media := open_im_media.NewMedia()
|
// media := open_im_media.NewMedia()
|
||||||
msg.MsgFrom = constant.UserMsgType
|
// msg.MsgFrom = constant.UserMsgType
|
||||||
msg.ContentType = constant.SignalingNotification
|
// msg.ContentType = constant.SignalingNotification
|
||||||
reqData, e := proto.Marshal(s)
|
// reqData, e := proto.Marshal(s)
|
||||||
if e != nil {
|
// if e != nil {
|
||||||
return false, 201, e.Error(), nil, nil
|
// return false, 201, e.Error(), nil, nil
|
||||||
}
|
// }
|
||||||
msg.Content = reqData
|
// msg.Content = reqData
|
||||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
// msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||||
options := make(map[string]bool, 6)
|
// options := make(map[string]bool, 6)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
// utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
// utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
// utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
// utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
// utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
// utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||||
msg.Options = options
|
// utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||||
switch payload := s.Payload.(type) {
|
// msg.Options = options
|
||||||
case *open_im_sdk.SignalReq_Invite:
|
// switch payload := s.Payload.(type) {
|
||||||
token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
// case *open_im_sdk.SignalReq_Invite:
|
||||||
if err2 != nil {
|
// token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
||||||
return false, 202, err2.Error(), nil, nil
|
// if err2 != nil {
|
||||||
}
|
// return false, 202, err2.Error(), nil, nil
|
||||||
invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
// }
|
||||||
Token: token,
|
// invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||||
RoomID: payload.Invite.Invitation.RoomID,
|
// Token: token,
|
||||||
LiveURL: liveURL,
|
// RoomID: payload.Invite.Invitation.RoomID,
|
||||||
}}
|
// LiveURL: liveURL,
|
||||||
resp.Payload = &invite
|
// }}
|
||||||
msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
// resp.Payload = &invite
|
||||||
msg.SessionType = payload.Invite.Invitation.SessionType
|
// msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||||
msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
// msg.SessionType = payload.Invite.Invitation.SessionType
|
||||||
msg.SendID = payload.Invite.Invitation.InviterUserID
|
// msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||||
if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
// msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||||
msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
// if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||||
} else {
|
// msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||||
return false, 203, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// } 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
|
// msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||||
case *open_im_sdk.SignalReq_InviteInGroup:
|
// return true, 0, "", &resp, &msg
|
||||||
token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
// case *open_im_sdk.SignalReq_InviteInGroup:
|
||||||
if err2 != nil {
|
// token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
||||||
return false, 204, err2.Error(), nil, nil
|
// 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,
|
// inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||||
Token: token,
|
// RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||||
LiveURL: liveURL,
|
// Token: token,
|
||||||
}}
|
// LiveURL: liveURL,
|
||||||
resp.Payload = &inviteGroup
|
// }}
|
||||||
msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
// resp.Payload = &inviteGroup
|
||||||
msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
// msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||||
msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
// msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||||
msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
// msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||||
if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
// msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||||
msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
// if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||||
} else {
|
// msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||||
return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// } else {
|
||||||
}
|
// return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||||
msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
// }
|
||||||
|
// msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||||
return true, 0, "", &resp, &msg
|
//
|
||||||
case *open_im_sdk.SignalReq_Cancel:
|
// return true, 0, "", &resp, &msg
|
||||||
cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
// case *open_im_sdk.SignalReq_Cancel:
|
||||||
resp.Payload = &cancel
|
// cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
||||||
msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
// resp.Payload = &cancel
|
||||||
msg.SendID = payload.Cancel.Invitation.InviterUserID
|
// msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
||||||
msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
// msg.SendID = payload.Cancel.Invitation.InviterUserID
|
||||||
msg.SessionType = payload.Cancel.Invitation.SessionType
|
// msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
||||||
if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
// msg.SessionType = payload.Cancel.Invitation.SessionType
|
||||||
switch payload.Cancel.Invitation.SessionType {
|
// if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
||||||
case constant.SingleChatType:
|
// switch payload.Cancel.Invitation.SessionType {
|
||||||
msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
// case constant.SingleChatType:
|
||||||
case constant.GroupChatType:
|
// msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
||||||
msg.GroupID = payload.Cancel.Invitation.GroupID
|
// case constant.GroupChatType:
|
||||||
}
|
// msg.GroupID = payload.Cancel.Invitation.GroupID
|
||||||
} else {
|
// }
|
||||||
return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// } else {
|
||||||
}
|
// return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||||
msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
// }
|
||||||
return true, 0, "", &resp, &msg
|
// msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
||||||
case *open_im_sdk.SignalReq_Accept:
|
// return true, 0, "", &resp, &msg
|
||||||
token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
// case *open_im_sdk.SignalReq_Accept:
|
||||||
if err2 != nil {
|
// token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
||||||
return false, 207, err2.Error(), nil, nil
|
// if err2 != nil {
|
||||||
}
|
// return false, 207, err2.Error(), nil, nil
|
||||||
accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
// }
|
||||||
Token: token,
|
// accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
||||||
LiveURL: liveURL,
|
// Token: token,
|
||||||
RoomID: payload.Accept.Invitation.RoomID,
|
// LiveURL: liveURL,
|
||||||
}}
|
// RoomID: payload.Accept.Invitation.RoomID,
|
||||||
resp.Payload = &accept
|
// }}
|
||||||
msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
// resp.Payload = &accept
|
||||||
msg.SendID = payload.Accept.OpUserID
|
// msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
||||||
msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
// msg.SendID = payload.Accept.OpUserID
|
||||||
msg.SessionType = payload.Accept.Invitation.SessionType
|
// msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
||||||
if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
// msg.SessionType = payload.Accept.Invitation.SessionType
|
||||||
switch payload.Accept.Invitation.SessionType {
|
// if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
||||||
case constant.SingleChatType:
|
// switch payload.Accept.Invitation.SessionType {
|
||||||
msg.RecvID = payload.Accept.Invitation.InviterUserID
|
// case constant.SingleChatType:
|
||||||
case constant.GroupChatType:
|
// msg.RecvID = payload.Accept.Invitation.InviterUserID
|
||||||
msg.GroupID = payload.Accept.Invitation.GroupID
|
// case constant.GroupChatType:
|
||||||
}
|
// msg.GroupID = payload.Accept.Invitation.GroupID
|
||||||
} else {
|
// }
|
||||||
return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// } else {
|
||||||
}
|
// return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||||
msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
// }
|
||||||
return true, 0, "", &resp, &msg
|
// msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
||||||
case *open_im_sdk.SignalReq_HungUp:
|
// return true, 0, "", &resp, &msg
|
||||||
case *open_im_sdk.SignalReq_Reject:
|
// case *open_im_sdk.SignalReq_HungUp:
|
||||||
reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
// case *open_im_sdk.SignalReq_Reject:
|
||||||
resp.Payload = &reject
|
// reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
||||||
msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
// resp.Payload = &reject
|
||||||
msg.SendID = payload.Reject.OpUserID
|
// msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
||||||
msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
// msg.SendID = payload.Reject.OpUserID
|
||||||
msg.SessionType = payload.Reject.Invitation.SessionType
|
// msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
||||||
if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
// msg.SessionType = payload.Reject.Invitation.SessionType
|
||||||
switch payload.Reject.Invitation.SessionType {
|
// if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
||||||
case constant.SingleChatType:
|
// switch payload.Reject.Invitation.SessionType {
|
||||||
msg.RecvID = payload.Reject.Invitation.InviterUserID
|
// case constant.SingleChatType:
|
||||||
case constant.GroupChatType:
|
// msg.RecvID = payload.Reject.Invitation.InviterUserID
|
||||||
msg.GroupID = payload.Reject.Invitation.GroupID
|
// case constant.GroupChatType:
|
||||||
}
|
// msg.GroupID = payload.Reject.Invitation.GroupID
|
||||||
} else {
|
// }
|
||||||
return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// } else {
|
||||||
}
|
// return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||||
msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
// }
|
||||||
return true, 0, "", &resp, &msg
|
// msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
||||||
}
|
// return true, 0, "", &resp, &msg
|
||||||
return false, 210, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
// }
|
||||||
}
|
// 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++
|
mc.groupMsgCount++
|
||||||
}
|
}
|
||||||
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
|
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:
|
default:
|
||||||
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -13,7 +13,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
log.NewPrivateLog(config.Config.ModuleName.MsgTransferName)
|
|
||||||
persistentCH.Init()
|
persistentCH.Init()
|
||||||
historyCH.Init()
|
historyCH.Init()
|
||||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
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) {
|
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
|
||||||
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
||||||
|
var tag bool
|
||||||
msgFromMQ := pbMsg.MsgDataToMQ{}
|
msgFromMQ := pbMsg.MsgDataToMQ{}
|
||||||
err := proto.Unmarshal(msg, &msgFromMQ)
|
err := proto.Unmarshal(msg, &msgFromMQ)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
//Control whether to store history messages (mysql)
|
//Control whether to store history messages (mysql)
|
||||||
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
||||||
//Only process receiver data
|
//Only process receiver data
|
||||||
if isPersist {
|
if isPersist {
|
||||||
if msgKey == msgFromMQ.MsgData.RecvID && msgFromMQ.MsgData.SessionType == constant.SingleChatType {
|
switch msgFromMQ.MsgData.SessionType {
|
||||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
case constant.SingleChatType, constant.NotificationChatType:
|
||||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
if msgKey == msgFromMQ.MsgData.RecvID {
|
||||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
tag = true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else if msgFromMQ.MsgData.SessionType == constant.GroupChatType && msgKey == msgFromMQ.MsgData.SendID {
|
case constant.GroupChatType:
|
||||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
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 {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
167
internal/push/getui/push.go
Normal file
167
internal/push/getui/push.go
Normal file
@@ -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"
|
"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
|
var pf requestBody.Platform
|
||||||
_ = pf.SetPlatform(platform)
|
_ = pf.SetPlatform(platform)
|
||||||
var au requestBody.Audience
|
var au requestBody.Audience
|
||||||
@@ -34,25 +52,23 @@ func JGAccountListPush(accounts []string, alert, detailContent, platform string)
|
|||||||
|
|
||||||
con, err := json.Marshal(po)
|
con, err := json.Marshal(po)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
|
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", common.GetAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret))
|
req.Header.Set("Authorization", common.GetAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret))
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
result, err := ioutil.ReadAll(resp.Body)
|
result, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
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/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"Open_IM/pkg/statistics"
|
"Open_IM/pkg/statistics"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
@@ -24,7 +23,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init(rpcPort int) {
|
func Init(rpcPort int) {
|
||||||
log.NewPrivateLog(config.Config.ModuleName.PushName)
|
|
||||||
rpcServer.Init(rpcPort)
|
rpcServer.Init(rpcPort)
|
||||||
pushCh.Init()
|
pushCh.Init()
|
||||||
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
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/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
@@ -99,12 +101,22 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
|||||||
content = constant.ContentType2PushContent[constant.Common]
|
content = constant.ContentType2PushContent[constant.Common]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var offlinePusher pusher.OfflinePusher
|
||||||
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
|
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 {
|
if err != nil {
|
||||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
|
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
|
||||||
} else {
|
} 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
5
internal/push/push_interface.go
Normal file
5
internal/push/push_interface.go
Normal file
@@ -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 {
|
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||||
log.NewPrivateLog("AdminCMS")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &adminCMSServer{
|
return &adminCMSServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
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) {
|
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp := &pbAdminCMS.AdminLoginResp{}
|
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 {
|
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||||
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||||
if err != nil {
|
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)
|
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||||
}
|
}
|
||||||
resp.Token = token
|
resp.Token = token
|
||||||
@@ -84,4 +84,4 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi
|
|||||||
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ type rpcAuth struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcAuthServer(port int) *rpcAuth {
|
func NewRpcAuthServer(port int) *rpcAuth {
|
||||||
log.NewPrivateLog("auth")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &rpcAuth{
|
return &rpcAuth{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type friendServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewFriendServer(port int) *friendServer {
|
func NewFriendServer(port int) *friendServer {
|
||||||
log.NewPrivateLog("friend")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &friendServer{
|
return &friendServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||||
|
|||||||
@@ -7,3 +7,7 @@ import (
|
|||||||
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func callbackAfterCreateGroup(req *pbGroup.CreateGroupReq) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ type groupServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupServer(port int) *groupServer {
|
func NewGroupServer(port int) *groupServer {
|
||||||
log.NewPrivateLog("group")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &groupServer{
|
return &groupServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||||
@@ -41,16 +41,16 @@ func NewGroupServer(port int) *groupServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) Run() {
|
func (s *groupServer) Run() {
|
||||||
log.NewInfo("0", "group rpc start ")
|
log.NewInfo("", "group rpc start ")
|
||||||
ip := utils.ServerIP
|
ip := utils.ServerIP
|
||||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||||
//listener network
|
//listener network
|
||||||
listener, err := net.Listen("tcp", registerAddress)
|
listener, err := net.Listen("tcp", registerAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
log.NewError("", "Listen failed ", err.Error(), registerAddress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
log.NewInfo("", "listen network success, ", registerAddress, listener)
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
//grpc server
|
//grpc server
|
||||||
srv := grpc.NewServer()
|
srv := grpc.NewServer()
|
||||||
@@ -59,15 +59,15 @@ func (s *groupServer) Run() {
|
|||||||
pbGroup.RegisterGroupServer(srv, s)
|
pbGroup.RegisterGroupServer(srv, s)
|
||||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
log.NewError("", "RegisterEtcd failed ", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = srv.Serve(listener)
|
err = srv.Serve(listener)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Serve failed ", err.Error())
|
log.NewError("", "Serve failed ", err.Error())
|
||||||
return
|
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) {
|
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 {
|
for _, v := range memberList {
|
||||||
|
log.Debug(req.OperationID, v)
|
||||||
var node open_im_sdk.GroupMemberFullInfo
|
var node open_im_sdk.GroupMemberFullInfo
|
||||||
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
||||||
|
log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix())
|
||||||
|
log.Debug(req.OperationID, "cp value: ", node)
|
||||||
resp.MemberList = append(resp.MemberList, &node)
|
resp.MemberList = append(resp.MemberList, &node)
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", resp.String())
|
log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", resp.String())
|
||||||
@@ -355,7 +358,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|||||||
//remove
|
//remove
|
||||||
var resp pbGroup.KickGroupMemberResp
|
var resp pbGroup.KickGroupMemberResp
|
||||||
for _, v := range req.KickedUserIDList {
|
for _, v := range req.KickedUserIDList {
|
||||||
//owner cant kicked
|
//owner can‘t kicked
|
||||||
if v == groupOwnerUserID {
|
if v == groupOwnerUserID {
|
||||||
log.NewError(req.OperationID, "failed, can't kick owner ", v)
|
log.NewError(req.OperationID, "failed, can't kick owner ", v)
|
||||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
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,
|
Status: group.Status,
|
||||||
CreatorUserID: group.CreatorUserID,
|
CreatorUserID: group.CreatorUserID,
|
||||||
GroupType: group.GroupType,
|
GroupType: group.GroupType,
|
||||||
|
CreateTime: uint32(group.CreateTime.Unix()),
|
||||||
}
|
}
|
||||||
groupMember, err := imdb.GetGroupMaster(group.GroupID)
|
groupMember, err := imdb.GetGroupMaster(group.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -674,6 +678,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
|||||||
resp.CMSGroup.GroupMasterName = groupMember.Nickname
|
resp.CMSGroup.GroupMasterName = groupMember.Nickname
|
||||||
resp.CMSGroup.GroupMasterId = groupMember.UserID
|
resp.CMSGroup.GroupMasterId = groupMember.UserID
|
||||||
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
|
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -701,6 +706,7 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
|||||||
groupMember, err := imdb.GetGroupMaster(v.GroupID)
|
groupMember, err := imdb.GetGroupMaster(v.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
|
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
|
||||||
GroupInfo: &open_im_sdk.GroupInfo{
|
GroupInfo: &open_im_sdk.GroupInfo{
|
||||||
@@ -710,11 +716,13 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
|||||||
OwnerUserID: v.CreatorUserID,
|
OwnerUserID: v.CreatorUserID,
|
||||||
Status: v.Status,
|
Status: v.Status,
|
||||||
CreatorUserID: v.CreatorUserID,
|
CreatorUserID: v.CreatorUserID,
|
||||||
|
CreateTime: uint32(v.CreateTime.Unix()),
|
||||||
},
|
},
|
||||||
GroupMasterName: groupMember.Nickname,
|
GroupMasterName: groupMember.Nickname,
|
||||||
GroupMasterId: groupMember.UserID,
|
GroupMasterId: groupMember.UserID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,3 +945,102 @@ func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.
|
|||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) {
|
||||||
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||||
|
if !token_verify.IsMangerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||||
|
log.NewError(req.OperationID, "verify failed ", req.OpUserID, req.GroupID)
|
||||||
|
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err := imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusDismissed)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, "OperateGroupStatus failed ", req.GroupID, constant.GroupStatusDismissed)
|
||||||
|
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||||
|
}
|
||||||
|
chat.GroupDismissedNotification(req)
|
||||||
|
|
||||||
|
err = imdb.DeleteGroupMemberByGroupID(req.GroupID)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(req.OperationID, "DeleteGroupMemberByGroupID failed ", req.GroupID)
|
||||||
|
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
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 {
|
func NewMessageCMSServer(port int) *messageCMSServer {
|
||||||
log.NewPrivateLog("MessageCMS")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &messageCMSServer{
|
return &messageCMSServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
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())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||||
}
|
}
|
||||||
chatLog := db.ChatLog{
|
chatLog := db.ChatLog{
|
||||||
Content: req.Content,
|
Content: req.Content,
|
||||||
SendTime: time,
|
SendTime: time,
|
||||||
ContentType: req.ContentType,
|
ContentType: req.ContentType,
|
||||||
SessionType: req.SessionType,
|
SessionType: req.SessionType,
|
||||||
}
|
}
|
||||||
@@ -101,20 +101,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
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 {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
return resp, errors.WrapError(constant.ErrDB)
|
||||||
}
|
}
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
pbChatLog := &pbMessageCMS.ChatLogs{
|
||||||
SessionType: chatLog.SessionType,
|
SessionType: chatLog.SessionType,
|
||||||
ContentType: chatLog.ContentType,
|
ContentType: chatLog.ContentType,
|
||||||
SearchContent: req.Content,
|
SearchContent: req.Content,
|
||||||
WholeContent: chatLog.Content,
|
WholeContent: chatLog.Content,
|
||||||
Date: chatLog.CreateTime.String(),
|
Date: chatLog.CreateTime.String(),
|
||||||
SenderNickName: chatLog.SenderNickname,
|
SenderNickName: chatLog.SenderNickname,
|
||||||
SenderId: chatLog.SendID,
|
SenderId: chatLog.SendID,
|
||||||
}
|
}
|
||||||
if chatLog.SenderNickname == "" {
|
if chatLog.SenderNickname == "" {
|
||||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import (
|
|||||||
"github.com/golang/protobuf/proto"
|
"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 err error
|
||||||
var tips open_im_sdk.TipsComm
|
|
||||||
tips.Detail, err = proto.Marshal(m)
|
tips.Detail, err = proto.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(operationID, utils.GetSelfFuncName(), "Marshal failed ", err.Error(), m.String())
|
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
marshaler := jsonpb.Marshaler{
|
marshaler := jsonpb.Marshaler{
|
||||||
@@ -24,15 +24,10 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
|||||||
EmitDefaults: false,
|
EmitDefaults: false,
|
||||||
}
|
}
|
||||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||||
cn := config.Config.Notification
|
|
||||||
switch contentType {
|
|
||||||
case constant.ConversationOptChangeNotification:
|
|
||||||
tips.DefaultTips = cn.ConversationOptUpdate.DefaultTips.Tips
|
|
||||||
}
|
|
||||||
var n NotificationMsg
|
var n NotificationMsg
|
||||||
n.SendID = userID
|
n.SendID = sendID
|
||||||
n.RecvID = userID
|
n.RecvID = recvID
|
||||||
n.ContentType = contentType
|
n.ContentType = int32(contentType)
|
||||||
n.SessionType = constant.SingleChatType
|
n.SessionType = constant.SingleChatType
|
||||||
n.MsgFrom = constant.SysMsgType
|
n.MsgFrom = constant.SysMsgType
|
||||||
n.OperationID = operationID
|
n.OperationID = operationID
|
||||||
@@ -44,10 +39,38 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
|||||||
Notification(&n)
|
Notification(&n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetConversationNotification(operationID, userID string) {
|
// SetPrivate调用
|
||||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "userID: ", userID)
|
func ConversationSetPrivateNotification(operationID, sendID, recvID string, isPrivateChat bool) {
|
||||||
conversationUpdateTips := open_im_sdk.ConversationUpdateTips{
|
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,
|
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())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsg failed", err.Error())
|
||||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||||
resp.ErrCode = constant.ErrDB.ErrCode
|
resp.ErrCode = constant.ErrDB.ErrCode
|
||||||
return resp, err
|
return resp, nil
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|||||||
@@ -157,7 +157,17 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
|
|||||||
case constant.MemberInvitedNotification: //
|
case constant.MemberInvitedNotification: //
|
||||||
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
||||||
case constant.MemberEnterNotification:
|
case constant.MemberEnterNotification:
|
||||||
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
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:
|
default:
|
||||||
log.Error(operationID, "contentType failed ", contentType)
|
log.Error(operationID, "contentType failed ", contentType)
|
||||||
return
|
return
|
||||||
@@ -225,6 +235,71 @@ func GroupInfoSetNotification(operationID, opUserID, groupID string) {
|
|||||||
groupNotification(constant.GroupInfoSetNotification, &GroupInfoChangedTips, opUserID, groupID, "", operationID)
|
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{
|
//message ReceiveJoinApplicationTips{
|
||||||
// GroupInfo Group = 1;
|
// GroupInfo Group = 1;
|
||||||
// PublicUserInfo Applicant = 2;
|
// PublicUserInfo Applicant = 2;
|
||||||
@@ -324,6 +399,19 @@ func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
|
|||||||
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GroupDismissedNotification(req *pbGroup.DismissGroupReq) {
|
||||||
|
tips := open_im_sdk.GroupDismissedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||||
|
if err := setGroupInfo(req.GroupID, tips.Group); err != nil {
|
||||||
|
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := setOpUserInfo(req.OpUserID, req.GroupID, tips.OpUser); err != nil {
|
||||||
|
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupNotification(constant.GroupDismissedNotification, &tips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||||
|
}
|
||||||
|
|
||||||
//message MemberKickedTips{
|
//message MemberKickedTips{
|
||||||
// GroupInfo Group = 1;
|
// GroupInfo Group = 1;
|
||||||
// GroupMemberFullInfo OpUser = 2;
|
// GroupMemberFullInfo OpUser = 2;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
@@ -22,7 +23,7 @@ type rpcChat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcChatServer(port int) *rpcChat {
|
func NewRpcChatServer(port int) *rpcChat {
|
||||||
log.NewPrivateLog("msg")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
rc := rpcChat{
|
rc := rpcChat{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
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)
|
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("", "", "listen network success, address = %s", address)
|
log.Info("", "", "listen network success, address = ", address)
|
||||||
|
|
||||||
//grpc server
|
//grpc server
|
||||||
srv := grpc.NewServer()
|
srv := grpc.NewServer()
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
|||||||
case constant.HasReadReceipt:
|
case constant.HasReadReceipt:
|
||||||
log.Info("", "this is a test start", msg, msg.Options)
|
log.Info("", "this is a test start", msg, msg.Options)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, 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.IsUnreadCount, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||||
log.Info("", "this is a test end", msg, msg.Options)
|
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.IsPersistent, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, 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.IsUnreadCount, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, 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())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
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:
|
default:
|
||||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||||
}
|
}
|
||||||
@@ -503,14 +522,56 @@ func Notification(n *NotificationMsg) {
|
|||||||
ex = config.Config.Notification.ConversationOptUpdate.OfflinePush.Ext
|
ex = config.Config.Notification.ConversationOptUpdate.OfflinePush.Ext
|
||||||
reliabilityLevel = config.Config.Notification.ConversationOptUpdate.Conversation.ReliabilityLevel
|
reliabilityLevel = config.Config.Notification.ConversationOptUpdate.Conversation.ReliabilityLevel
|
||||||
unReadCount = config.Config.Notification.ConversationOptUpdate.Conversation.UnreadCount
|
unReadCount = config.Config.Notification.ConversationOptUpdate.Conversation.UnreadCount
|
||||||
|
|
||||||
|
case constant.GroupDismissedNotification:
|
||||||
|
pushSwitch = config.Config.Notification.GroupDismissed.OfflinePush.PushSwitch
|
||||||
|
title = config.Config.Notification.GroupDismissed.OfflinePush.Title
|
||||||
|
desc = config.Config.Notification.GroupDismissed.OfflinePush.Desc
|
||||||
|
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 {
|
switch reliabilityLevel {
|
||||||
case constant.UnreliableNotification:
|
case constant.UnreliableNotification:
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||||
|
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||||
case constant.ReliableNotificationNoMsg:
|
case constant.ReliableNotificationNoMsg:
|
||||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||||
|
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||||
case constant.ReliableNotificationMsg:
|
case constant.ReliableNotificationMsg:
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -527,6 +588,6 @@ func Notification(n *NotificationMsg) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||||
} else if reply.ErrCode != 0 {
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
internal/rpc/msg/tag_send_msg.go
Normal file
45
internal/rpc/msg/tag_send_msg.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
268
internal/rpc/office/office.go
Normal file
268
internal/rpc/office/office.go
Normal file
@@ -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_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
//"context"
|
//"context"
|
||||||
|
errors "Open_IM/pkg/common/http"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
errors "Open_IM/pkg/common/http"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
@@ -35,7 +35,7 @@ type statisticsServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewStatisticsServer(port int) *statisticsServer {
|
func NewStatisticsServer(port int) *statisticsServer {
|
||||||
log.NewPrivateLog("Statistics")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &statisticsServer{
|
return &statisticsServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
||||||
@@ -164,7 +164,7 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
|
|||||||
}
|
}
|
||||||
// month
|
// month
|
||||||
case !isInOneMonth(from, to):
|
case !isInOneMonth(from, to):
|
||||||
if to.Sub(from) < time.Hour * 24 * 30 {
|
if to.Sub(from) < time.Hour*24*30 {
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
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())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||||
}
|
}
|
||||||
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
||||||
Date: v[0].String(),
|
Date: v[0].String(),
|
||||||
Num: num,
|
Num: num,
|
||||||
}
|
}
|
||||||
}(wg, i, v)
|
}(wg, i, v)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type userServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewUserServer(port int) *userServer {
|
func NewUserServer(port int) *userServer {
|
||||||
log.NewPrivateLog("user")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &userServer{
|
return &userServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||||
@@ -72,6 +72,30 @@ func (s *userServer) Run() {
|
|||||||
log.NewInfo("0", "rpc user success")
|
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) {
|
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||||
var userInfoList []*sdkws.UserInfo
|
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) {
|
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
|
if req.NotificationType == 0 {
|
||||||
|
req.NotificationType = constant.ConversationOptChangeNotification
|
||||||
|
}
|
||||||
resp := &pbUser.BatchSetConversationsResp{}
|
resp := &pbUser.BatchSetConversationsResp{}
|
||||||
for _, v := range req.Conversations {
|
for _, v := range req.Conversations {
|
||||||
conversation := db.Conversation{}
|
conversation := db.Conversation{}
|
||||||
@@ -113,8 +140,14 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Success = append(resp.Success, v.ConversationID)
|
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())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||||
resp.CommonResp = &pbUser.CommonResp{}
|
resp.CommonResp = &pbUser.CommonResp{}
|
||||||
return resp, nil
|
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) {
|
func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConversationReq) (*pbUser.SetConversationResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
|
if req.NotificationType == 0 {
|
||||||
|
req.NotificationType = constant.ConversationOptChangeNotification
|
||||||
|
}
|
||||||
resp := &pbUser.SetConversationResp{}
|
resp := &pbUser.SetConversationResp{}
|
||||||
var conversation db.Conversation
|
var conversation db.Conversation
|
||||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
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}
|
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
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())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||||
resp.CommonResp = &pbUser.CommonResp{}
|
resp.CommonResp = &pbUser.CommonResp{}
|
||||||
return resp, nil
|
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}
|
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
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)
|
err := imdb.SetRecvMsgOpt(conversation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||||
resp.CommonResp = &pbUser.CommonResp{}
|
resp.CommonResp = &pbUser.CommonResp{}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func Test_ParseToken(t *testing.T) {
|
|||||||
uid := "1"
|
uid := "1"
|
||||||
platform := int32(1)
|
platform := int32(1)
|
||||||
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
||||||
claims, err := token_verify.ParseToken(tokenString)
|
claims, err := token_verify.ParseToken(tokenString, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
assert.Equal(t, claims.UID, uid)
|
assert.Equal(t, claims.UID, uid)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ type SetReceiveMessageOptResp struct {
|
|||||||
|
|
||||||
type Conversation struct {
|
type Conversation struct {
|
||||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||||
ConversationID string `json:"conversationID"`
|
ConversationID string `json:"conversationID" binding:"required"`
|
||||||
ConversationType int32 `json:"conversationType"`
|
ConversationType int32 `json:"conversationType" binding:"required"`
|
||||||
UserID string `json:"userID"`
|
UserID string `json:"userID"`
|
||||||
GroupID string `json:"groupID"`
|
GroupID string `json:"groupID"`
|
||||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||||
@@ -49,7 +49,8 @@ type Conversation struct {
|
|||||||
|
|
||||||
type SetConversationReq struct {
|
type SetConversationReq struct {
|
||||||
Conversation
|
Conversation
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
NotificationType int32 `json:"notificationType"`
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetConversationResp struct {
|
type SetConversationResp struct {
|
||||||
@@ -57,9 +58,10 @@ type SetConversationResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BatchSetConversationsReq struct {
|
type BatchSetConversationsReq struct {
|
||||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
NotificationType int32 `json:"notificationType"`
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BatchSetConversationsResp struct {
|
type BatchSetConversationsResp struct {
|
||||||
@@ -103,10 +105,11 @@ type GetConversationsResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SetRecvMsgOptReq struct {
|
type SetRecvMsgOptReq struct {
|
||||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||||
ConversationID string `json:"conversationID"`
|
ConversationID string `json:"conversationID"`
|
||||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
NotificationType int32 `json:"notificationType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetRecvMsgOptResp struct {
|
type SetRecvMsgOptResp struct {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ type ImportFriendReq struct {
|
|||||||
FromUserID string `json:"fromUserID" binding:"required"`
|
FromUserID string `json:"fromUserID" binding:"required"`
|
||||||
}
|
}
|
||||||
type UserIDResult struct {
|
type UserIDResult struct {
|
||||||
UserID string `json:"userID""`
|
UserID string `json:"userID"`
|
||||||
Result int32 `json:"result"`
|
Result int32 `json:"result"`
|
||||||
}
|
}
|
||||||
type ImportFriendResp struct {
|
type ImportFriendResp struct {
|
||||||
|
|||||||
@@ -177,3 +177,46 @@ type TransferGroupOwnerReq struct {
|
|||||||
type TransferGroupOwnerResp struct {
|
type TransferGroupOwnerResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DismissGroupReq struct {
|
||||||
|
GroupID string `json:"groupID" binding:"required"`
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,8 +6,20 @@ type MinioStorageCredentialReq struct {
|
|||||||
|
|
||||||
type MiniostorageCredentialResp struct {
|
type MiniostorageCredentialResp struct {
|
||||||
SecretAccessKey string `json:"secretAccessKey"`
|
SecretAccessKey string `json:"secretAccessKey"`
|
||||||
AccessKeyID string `json:"accessKeyID"`
|
AccessKeyID string `json:"accessKeyID"`
|
||||||
SessionToken string `json:"sessionToken"`
|
SessionToken string `json:"sessionToken"`
|
||||||
BucketName string `json:"bucketName"`
|
BucketName string `json:"bucketName"`
|
||||||
StsEndpointURL string `json:"stsEndpointURL"`
|
StsEndpointURL string `json:"stsEndpointURL"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinioUploadFileReq struct {
|
||||||
|
OperationID string `form:"operationID" binding:"required"`
|
||||||
|
FileType int `form:"fileType" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinioUploadFileResp struct {
|
||||||
|
URL string `json:"URL"`
|
||||||
|
NewName string `json:"newName"`
|
||||||
|
SnapshotURL string `json:"snapshotURL,omitempty"`
|
||||||
|
SnapshotNewName string `json:"snapshotName,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
88
pkg/base_info/office_struct.go
Normal file
88
pkg/base_info/office_struct.go
Normal file
@@ -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"`
|
||||||
|
}
|
||||||
22
pkg/base_info/oss_api_struct.go
Normal file
22
pkg/base_info/oss_api_struct.go
Normal file
@@ -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"`
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ type GroupResponse struct {
|
|||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
IsBanChat bool `json:"is_ban_chat"`
|
IsBanChat bool `json:"is_ban_chat"`
|
||||||
IsBanPrivateChat bool `json:"is_ban_private_chat"`
|
IsBanPrivateChat bool `json:"is_ban_private_chat"`
|
||||||
ProfilePhoto string `json:"profile_photo"`
|
ProfilePhoto string `json:"profile_photo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetGroupByIdRequest struct {
|
type GetGroupByIdRequest struct {
|
||||||
@@ -63,7 +63,6 @@ type SetGroupMemberRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SetGroupMemberRespones struct {
|
type SetGroupMemberRespones struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type BanGroupChatRequest struct {
|
type BanGroupChatRequest struct {
|
||||||
@@ -88,7 +87,7 @@ type DeleteGroupResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetGroupMembersRequest struct {
|
type GetGroupMembersRequest struct {
|
||||||
GroupId string `form:"group_id" binding:"required"`
|
GroupId string `form:"group_id" binding:"required"`
|
||||||
UserName string `form:"user_name"`
|
UserName string `form:"user_name"`
|
||||||
RequestPagination
|
RequestPagination
|
||||||
}
|
}
|
||||||
@@ -96,24 +95,24 @@ type GetGroupMembersRequest struct {
|
|||||||
type GroupMemberResponse struct {
|
type GroupMemberResponse struct {
|
||||||
MemberPosition int `json:"member_position"`
|
MemberPosition int `json:"member_position"`
|
||||||
MemberNickName string `json:"member_nick_name"`
|
MemberNickName string `json:"member_nick_name"`
|
||||||
MemberId string `json:"member_id"`
|
MemberId string `json:"member_id"`
|
||||||
JoinTime string `json:"join_time"`
|
JoinTime string `json:"join_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetGroupMembersResponse struct {
|
type GetGroupMembersResponse struct {
|
||||||
GroupMembers []GroupMemberResponse `json:"group_members"`
|
GroupMembers []GroupMemberResponse `json:"group_members"`
|
||||||
ResponsePagination
|
ResponsePagination
|
||||||
MemberNums int `json:"member_nums"`
|
MemberNums int `json:"member_nums"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupMemberRequest struct {
|
type GroupMemberRequest struct {
|
||||||
GroupId string `json:"group_id" binding:"required"`
|
GroupId string `json:"group_id" binding:"required"`
|
||||||
Members []string `json:"members" binding:"required"`
|
Members []string `json:"members" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupMemberOperateResponse struct {
|
type GroupMemberOperateResponse struct {
|
||||||
Success []string `json:"success"`
|
Success []string `json:"success"`
|
||||||
Failed []string `json:"failed"`
|
Failed []string `json:"failed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddGroupMembersRequest struct {
|
type AddGroupMembersRequest struct {
|
||||||
@@ -128,19 +127,18 @@ type RemoveGroupMembersRequest struct {
|
|||||||
GroupMemberRequest
|
GroupMemberRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoveGroupMembersResponse struct{
|
type RemoveGroupMembersResponse struct {
|
||||||
GroupMemberOperateResponse
|
GroupMemberOperateResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlterGroupInfoRequest struct {
|
type AlterGroupInfoRequest struct {
|
||||||
GroupID string `json:"group_id"`
|
GroupID string `json:"group_id"`
|
||||||
GroupName string `json:"group_name"`
|
GroupName string `json:"group_name"`
|
||||||
Notification string `json:"notification"`
|
Notification string `json:"notification"`
|
||||||
Introduction string `json:"introduction"`
|
Introduction string `json:"introduction"`
|
||||||
ProfilePhoto string `json:"profile_photo"`
|
ProfilePhoto string `json:"profile_photo"`
|
||||||
GroupType int `json:"group_type"`
|
GroupType int `json:"group_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlterGroupInfoResponse struct {
|
type AlterGroupInfoResponse struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -45,6 +44,17 @@ type config struct {
|
|||||||
SecretID string `yaml:"secretID"`
|
SecretID string `yaml:"secretID"`
|
||||||
SecretKey string `yaml:"secretKey"`
|
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 {
|
Minio struct {
|
||||||
Bucket string `yaml:"bucket"`
|
Bucket string `yaml:"bucket"`
|
||||||
Location string `yaml:"location"`
|
Location string `yaml:"location"`
|
||||||
@@ -66,6 +76,7 @@ type config struct {
|
|||||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||||
}
|
}
|
||||||
Mongo struct {
|
Mongo struct {
|
||||||
|
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
|
||||||
DBAddress []string `yaml:"dbAddress"`
|
DBAddress []string `yaml:"dbAddress"`
|
||||||
DBDirect bool `yaml:"dbDirect"`
|
DBDirect bool `yaml:"dbDirect"`
|
||||||
DBTimeout int `yaml:"dbTimeout"`
|
DBTimeout int `yaml:"dbTimeout"`
|
||||||
@@ -103,6 +114,7 @@ type config struct {
|
|||||||
OpenImAuthName string `yaml:"openImAuthName"`
|
OpenImAuthName string `yaml:"openImAuthName"`
|
||||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||||
|
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||||
}
|
}
|
||||||
Etcd struct {
|
Etcd struct {
|
||||||
EtcdSchema string `yaml:"etcdSchema"`
|
EtcdSchema string `yaml:"etcdSchema"`
|
||||||
@@ -140,12 +152,21 @@ type config struct {
|
|||||||
AccessID string `yaml:"accessID"`
|
AccessID string `yaml:"accessID"`
|
||||||
SecretKey string `yaml:"secretKey"`
|
SecretKey string `yaml:"secretKey"`
|
||||||
}
|
}
|
||||||
|
Enable bool `yaml:"enable"`
|
||||||
}
|
}
|
||||||
Jpns struct {
|
Jpns struct {
|
||||||
AppKey string `yaml:"appKey"`
|
AppKey string `yaml:"appKey"`
|
||||||
MasterSecret string `yaml:"masterSecret"`
|
MasterSecret string `yaml:"masterSecret"`
|
||||||
PushUrl string `yaml:"pushUrl"`
|
PushUrl string `yaml:"pushUrl"`
|
||||||
PushIntent string `yaml:"pushIntent"`
|
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 {
|
Manager struct {
|
||||||
@@ -250,6 +271,37 @@ type config struct {
|
|||||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||||
} `yaml:"memberEnter"`
|
} `yaml:"memberEnter"`
|
||||||
|
|
||||||
|
GroupDismissed struct {
|
||||||
|
Conversation PConversation `yaml:"conversation"`
|
||||||
|
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||||
|
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///////////////////////
|
////////////////////////user///////////////////////
|
||||||
UserInfoUpdated struct {
|
UserInfoUpdated struct {
|
||||||
Conversation PConversation `yaml:"conversation"`
|
Conversation PConversation `yaml:"conversation"`
|
||||||
@@ -306,6 +358,14 @@ type config struct {
|
|||||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||||
} `yaml:"conversationOptUpdate"`
|
} `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 {
|
Demo struct {
|
||||||
Port []int `yaml:"openImDemoPort"`
|
Port []int `yaml:"openImDemoPort"`
|
||||||
@@ -325,6 +385,10 @@ type config struct {
|
|||||||
SmtpPort int `yaml:"smtpPort"`
|
SmtpPort int `yaml:"smtpPort"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Rtc struct {
|
||||||
|
Port int `yaml:"port"`
|
||||||
|
Address string `yaml:"address"`
|
||||||
|
} `yaml:"rtc"`
|
||||||
}
|
}
|
||||||
type PConversation struct {
|
type PConversation struct {
|
||||||
ReliabilityLevel int `yaml:"reliabilityLevel"`
|
ReliabilityLevel int `yaml:"reliabilityLevel"`
|
||||||
@@ -364,5 +428,4 @@ func init() {
|
|||||||
if err = yaml.Unmarshal(bytes, &Config); err != nil {
|
if err = yaml.Unmarshal(bytes, &Config); err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
fmt.Println("load config: ", Config)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,14 +56,13 @@ const (
|
|||||||
FriendRemarkSetNotification = 1206 //set_friend_remark?
|
FriendRemarkSetNotification = 1206 //set_friend_remark?
|
||||||
BlackAddedNotification = 1207 //add_black
|
BlackAddedNotification = 1207 //add_black
|
||||||
BlackDeletedNotification = 1208 //remove_black
|
BlackDeletedNotification = 1208 //remove_black
|
||||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
|
||||||
|
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||||
|
|
||||||
UserNotificationBegin = 1301
|
UserNotificationBegin = 1301
|
||||||
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
||||||
ConversationNotification = 1307
|
|
||||||
ConversationNotNotification = 1308
|
|
||||||
ConversationDefault = 0
|
|
||||||
UserNotificationEnd = 1399
|
UserNotificationEnd = 1399
|
||||||
|
OANotification = 1400
|
||||||
|
|
||||||
GroupNotificationBegin = 1500
|
GroupNotificationBegin = 1500
|
||||||
|
|
||||||
@@ -77,11 +76,19 @@ const (
|
|||||||
MemberKickedNotification = 1508
|
MemberKickedNotification = 1508
|
||||||
MemberInvitedNotification = 1509
|
MemberInvitedNotification = 1509
|
||||||
MemberEnterNotification = 1510
|
MemberEnterNotification = 1510
|
||||||
|
GroupDismissedNotification = 1511
|
||||||
|
GroupMemberMutedNotification = 1512
|
||||||
|
GroupMemberCancelMutedNotification = 1513
|
||||||
|
GroupMutedNotification = 1514
|
||||||
|
GroupCancelMutedNotification = 1515
|
||||||
|
|
||||||
SignalingNotificationBegin = 1600
|
SignalingNotificationBegin = 1600
|
||||||
SignalingNotification = 1601
|
SignalingNotification = 1601
|
||||||
SignalingNotificationEnd = 1699
|
SignalingNotificationEnd = 1699
|
||||||
NotificationEnd = 2000
|
|
||||||
|
ConversationPrivateChatNotification = 1701
|
||||||
|
|
||||||
|
NotificationEnd = 2000
|
||||||
|
|
||||||
//status
|
//status
|
||||||
MsgNormal = 1
|
MsgNormal = 1
|
||||||
@@ -94,6 +101,8 @@ const (
|
|||||||
//SessionType
|
//SessionType
|
||||||
SingleChatType = 1
|
SingleChatType = 1
|
||||||
GroupChatType = 2
|
GroupChatType = 2
|
||||||
|
|
||||||
|
NotificationChatType = 4
|
||||||
//token
|
//token
|
||||||
NormalToken = 0
|
NormalToken = 0
|
||||||
InValidToken = 1
|
InValidToken = 1
|
||||||
@@ -121,17 +130,21 @@ const (
|
|||||||
ReceiveNotNotifyMessage = 2
|
ReceiveNotNotifyMessage = 2
|
||||||
|
|
||||||
//OptionsKey
|
//OptionsKey
|
||||||
IsHistory = "history"
|
IsHistory = "history"
|
||||||
IsPersistent = "persistent"
|
IsPersistent = "persistent"
|
||||||
IsOfflinePush = "offlinePush"
|
IsOfflinePush = "offlinePush"
|
||||||
IsUnreadCount = "unreadCount"
|
IsUnreadCount = "unreadCount"
|
||||||
IsConversationUpdate = "conversationUpdate"
|
IsConversationUpdate = "conversationUpdate"
|
||||||
IsSenderSync = "senderSync"
|
IsSenderSync = "senderSync"
|
||||||
|
IsNotPrivate = "notPrivate"
|
||||||
|
IsSenderConversationUpdate = "senderConversationUpdate"
|
||||||
|
|
||||||
//GroupStatus
|
//GroupStatus
|
||||||
GroupOk = 0
|
GroupOk = 0
|
||||||
GroupBanChat = 1
|
GroupBanChat = 1
|
||||||
GroupDisband = 2
|
GroupStatusDismissed = 2
|
||||||
|
GroupStatusMuted = 3
|
||||||
|
|
||||||
GroupBaned = 3
|
GroupBaned = 3
|
||||||
GroupBanPrivateChat = 4
|
GroupBanPrivateChat = 4
|
||||||
|
|
||||||
@@ -159,6 +172,11 @@ const (
|
|||||||
//callback callbackHandleCode
|
//callback callbackHandleCode
|
||||||
CallbackHandleSuccess = 0
|
CallbackHandleSuccess = 0
|
||||||
CallbackHandleFailed = 1
|
CallbackHandleFailed = 1
|
||||||
|
|
||||||
|
// minioUpload
|
||||||
|
OtherType = 1
|
||||||
|
VideoType = 2
|
||||||
|
ImageType = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
var ContentType2PushContent = map[int64]string{
|
var ContentType2PushContent = map[int64]string{
|
||||||
@@ -199,7 +217,7 @@ const (
|
|||||||
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
||||||
|
|
||||||
func GroupIsBanChat(status int32) bool {
|
func GroupIsBanChat(status int32) bool {
|
||||||
if status != GroupBanChat {
|
if status != GroupStatusMuted {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -213,3 +231,5 @@ func GroupIsBanPrivateChat(status int32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BigVersion = "v3"
|
const BigVersion = "v3"
|
||||||
|
|
||||||
|
const LogFileName = "OpenIM.log"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/log"
|
//"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
@@ -33,6 +33,7 @@ func key(dbAddress, dbName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
//log.NewPrivateLog(constant.LogFileName)
|
||||||
//var mgoSession *mgo.Session
|
//var mgoSession *mgo.Session
|
||||||
var mongoClient *mongo.Client
|
var mongoClient *mongo.Client
|
||||||
var err1 error
|
var err1 error
|
||||||
@@ -41,21 +42,27 @@ func init() {
|
|||||||
// mongo init
|
// mongo init
|
||||||
// "mongodb://sysop:moon@localhost/records"
|
// "mongodb://sysop:moon@localhost/records"
|
||||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||||
uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d",
|
if config.Config.Mongo.DBUri != "" {
|
||||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
||||||
config.Config.Mongo.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))
|
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
if err != nil {
|
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)
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
if err1 != nil {
|
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())
|
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
|
DB.mongoClient = mongoClient
|
||||||
|
|
||||||
//mgoDailInfo := &mgo.DialInfo{
|
//mgoDailInfo := &mgo.DialInfo{
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ type GroupMember struct {
|
|||||||
JoinTime time.Time `gorm:"column:join_time"`
|
JoinTime time.Time `gorm:"column:join_time"`
|
||||||
JoinSource int32 `gorm:"column:join_source"`
|
JoinSource int32 `gorm:"column:join_source"`
|
||||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||||
|
MuteEndTime time.Time `gorm:"column:mute_end_time"`
|
||||||
Ex string `gorm:"column:ex;size:1024"`
|
Ex string `gorm:"column:ex;size:1024"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,4 +221,4 @@ type Conversation struct {
|
|||||||
|
|
||||||
func (Conversation) TableName() string {
|
func (Conversation) TableName() string {
|
||||||
return "conversations"
|
return "conversations"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gogo/protobuf/sortkeys"
|
"github.com/gogo/protobuf/sortkeys"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
//"github.com/garyburd/redigo/redis"
|
//"github.com/garyburd/redigo/redis"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
@@ -22,6 +24,8 @@ import (
|
|||||||
|
|
||||||
const cChat = "msg"
|
const cChat = "msg"
|
||||||
const cGroup = "group"
|
const cGroup = "group"
|
||||||
|
const cTag = "tag"
|
||||||
|
const cSendLog = "send_log"
|
||||||
const singleGocMsgNum = 5000
|
const singleGocMsgNum = 5000
|
||||||
|
|
||||||
type MsgInfo struct {
|
type MsgInfo struct {
|
||||||
@@ -78,9 +82,10 @@ func (d *DataBases) DelMsgLogic(uid string, seqList []uint32, operationID string
|
|||||||
sortkeys.Uint32s(seqList)
|
sortkeys.Uint32s(seqList)
|
||||||
seqMsgs, err := d.GetMsgBySeqListMongo2(uid, seqList, operationID)
|
seqMsgs, err := d.GetMsgBySeqListMongo2(uid, seqList, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
for _, seqMsg := range seqMsgs {
|
for _, seqMsg := range seqMsgs {
|
||||||
|
log.NewDebug(operationID, utils.GetSelfFuncName(), *seqMsg)
|
||||||
seqMsg.Status = constant.MsgDeleted
|
seqMsg.Status = constant.MsgDeleted
|
||||||
if err = d.ReplaceMsgBySeq(uid, seqMsg, operationID); err != nil {
|
if err = d.ReplaceMsgBySeq(uid, seqMsg, operationID); err != nil {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), "ReplaceMsgListBySeq error", err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), "ReplaceMsgListBySeq error", err.Error())
|
||||||
@@ -90,20 +95,25 @@ func (d *DataBases) DelMsgLogic(uid string, seqList []uint32, operationID string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DataBases) ReplaceMsgBySeq(uid string, msg *open_im_sdk.MsgData, operationID string) error {
|
func (d *DataBases) ReplaceMsgBySeq(uid string, msg *open_im_sdk.MsgData, operationID string) error {
|
||||||
log.NewInfo(operationID, utils.GetSelfFuncName(), uid, msg)
|
log.NewInfo(operationID, utils.GetSelfFuncName(), uid, *msg)
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
uid = getSeqUid(uid, msg.Seq)
|
uid = getSeqUid(uid, msg.Seq)
|
||||||
seqIndex := getMsgIndex(msg.Seq)
|
seqIndex := getMsgIndex(msg.Seq)
|
||||||
s := fmt.Sprintf("msg.%d.msg", seqIndex)
|
s := fmt.Sprintf("msg.%d.msg", seqIndex)
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), seqIndex, s)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), seqIndex, s)
|
||||||
|
bytes, err := proto.Marshal(msg)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(operationID, utils.GetSelfFuncName(), "proto marshal", err.Error())
|
||||||
|
return utils.Wrap(err, "")
|
||||||
|
}
|
||||||
updateResult, err := c.UpdateOne(
|
updateResult, err := c.UpdateOne(
|
||||||
ctx, bson.M{"uid": uid},
|
ctx, bson.M{"uid": uid},
|
||||||
bson.M{"$set": bson.M{s: msg}})
|
bson.M{"$set": bson.M{s: bytes}})
|
||||||
log.NewInfo(operationID, utils.GetSelfFuncName(), updateResult)
|
log.NewInfo(operationID, utils.GetSelfFuncName(), updateResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), "UpdateOne", err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), "UpdateOne", err.Error())
|
||||||
return err
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -424,9 +434,143 @@ func (d *DataBases) DelGroupMember(groupID, uid string) error {
|
|||||||
//return nil
|
//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 {
|
func getCurrentTimestampByMill() int64 {
|
||||||
return time.Now().UnixNano() / 1e6
|
return time.Now().UnixNano() / 1e6
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSeqUid(uid string, seq uint32) string {
|
func getSeqUid(uid string, seq uint32) string {
|
||||||
seqSuffix := seq / singleGocMsgNum
|
seqSuffix := seq / singleGocMsgNum
|
||||||
return indexGen(uid, seqSuffix)
|
return indexGen(uid, seqSuffix)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -24,13 +24,13 @@ func initMysqlDB() {
|
|||||||
var err1 error
|
var err1 error
|
||||||
db, err := gorm.Open("mysql", dsn)
|
db, err := gorm.Open("mysql", dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Open failed ", err.Error(), dsn)
|
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(time.Duration(30) * time.Second)
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
db, err1 = gorm.Open("mysql", dsn)
|
db, err1 = gorm.Open("mysql", dsn)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.NewError("0", "Open failed ", err1.Error(), dsn)
|
fmt.Println("0", "Open failed ", err1.Error(), dsn)
|
||||||
panic(err1.Error())
|
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)
|
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
|
err = db.Exec(sql).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Exec failed ", err.Error(), sql)
|
fmt.Println("0", "Exec failed ", err.Error(), sql)
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
db.Close()
|
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)
|
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||||
db, err = gorm.Open("mysql", dsn)
|
db, err = gorm.Open("mysql", dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("0", "Open failed ", err.Error(), dsn)
|
fmt.Println("0", "Open failed ", err.Error(), dsn)
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewInfo("open db ok ", dsn)
|
fmt.Println("open db ok ", dsn)
|
||||||
db.AutoMigrate(&Friend{},
|
db.AutoMigrate(&Friend{},
|
||||||
&FriendRequest{},
|
&FriendRequest{},
|
||||||
&Group{},
|
&Group{},
|
||||||
@@ -64,49 +64,49 @@ func initMysqlDB() {
|
|||||||
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||||
|
|
||||||
if !db.HasTable(&Friend{}) {
|
if !db.HasTable(&Friend{}) {
|
||||||
log.NewInfo("CreateTable Friend")
|
fmt.Println("CreateTable Friend")
|
||||||
db.CreateTable(&Friend{})
|
db.CreateTable(&Friend{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&FriendRequest{}) {
|
if !db.HasTable(&FriendRequest{}) {
|
||||||
log.NewInfo("CreateTable FriendRequest")
|
fmt.Println("CreateTable FriendRequest")
|
||||||
db.CreateTable(&FriendRequest{})
|
db.CreateTable(&FriendRequest{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&Group{}) {
|
if !db.HasTable(&Group{}) {
|
||||||
log.NewInfo("CreateTable Group")
|
fmt.Println("CreateTable Group")
|
||||||
db.CreateTable(&Group{})
|
db.CreateTable(&Group{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&GroupMember{}) {
|
if !db.HasTable(&GroupMember{}) {
|
||||||
log.NewInfo("CreateTable GroupMember")
|
fmt.Println("CreateTable GroupMember")
|
||||||
db.CreateTable(&GroupMember{})
|
db.CreateTable(&GroupMember{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&GroupRequest{}) {
|
if !db.HasTable(&GroupRequest{}) {
|
||||||
log.NewInfo("CreateTable GroupRequest")
|
fmt.Println("CreateTable GroupRequest")
|
||||||
db.CreateTable(&GroupRequest{})
|
db.CreateTable(&GroupRequest{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&User{}) {
|
if !db.HasTable(&User{}) {
|
||||||
log.NewInfo("CreateTable User")
|
fmt.Println("CreateTable User")
|
||||||
db.CreateTable(&User{})
|
db.CreateTable(&User{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.HasTable(&Black{}) {
|
if !db.HasTable(&Black{}) {
|
||||||
log.NewInfo("CreateTable Black")
|
fmt.Println("CreateTable Black")
|
||||||
db.CreateTable(&Black{})
|
db.CreateTable(&Black{})
|
||||||
}
|
}
|
||||||
if !db.HasTable(&ChatLog{}) {
|
if !db.HasTable(&ChatLog{}) {
|
||||||
log.NewInfo("CreateTable Black")
|
fmt.Println("CreateTable Black")
|
||||||
db.CreateTable(&ChatLog{})
|
db.CreateTable(&ChatLog{})
|
||||||
}
|
}
|
||||||
if !db.HasTable(&Register{}) {
|
if !db.HasTable(&Register{}) {
|
||||||
log.NewInfo("CreateTable Black")
|
fmt.Println("CreateTable Black")
|
||||||
db.CreateTable(&Register{})
|
db.CreateTable(&Register{})
|
||||||
}
|
}
|
||||||
if !db.HasTable(&Conversation{}) {
|
if !db.HasTable(&Conversation{}) {
|
||||||
log.NewInfo("CreateTable Black")
|
fmt.Println("CreateTable Black")
|
||||||
db.CreateTable(&Conversation{})
|
db.CreateTable(&Conversation{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func ResetPassword(account, password string) error {
|
|||||||
Password: password,
|
Password: password,
|
||||||
}
|
}
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
|
|||||||
if toInsertInfo.RoleLevel == 0 {
|
if toInsertInfo.RoleLevel == 0 {
|
||||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||||
}
|
}
|
||||||
|
toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||||
err = dbConn.Table("group_members").Create(toInsertInfo).Error
|
err = dbConn.Table("group_members").Create(toInsertInfo).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -65,6 +66,24 @@ func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) {
|
|||||||
return groupMemberList, nil
|
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) {
|
func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -103,6 +122,18 @@ func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteGroupMemberByGroupID(groupID string) error {
|
||||||
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = dbConn.Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error {
|
func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -248,13 +279,21 @@ func GetGroupMembersCount(groupId, userName string) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return count, err
|
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 {
|
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, err
|
||||||
}
|
}
|
||||||
return count, nil
|
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) {
|
//func SelectGroupList(groupID string) ([]string, error) {
|
||||||
// var groupUserID string
|
// var groupUserID string
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ func SetGroupInfo(groupInfo db.Group) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
|
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -68,7 +67,7 @@ func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return groups, err
|
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
|
err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error
|
||||||
return groups, err
|
return groups, err
|
||||||
}
|
}
|
||||||
@@ -79,7 +78,7 @@ func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return groups, err
|
return groups, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||||
return groups, err
|
return groups, err
|
||||||
}
|
}
|
||||||
@@ -102,7 +101,7 @@ func DeleteGroup(groupId string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
var group db.Group
|
var group db.Group
|
||||||
var groupMembers []db.GroupMember
|
var groupMembers []db.GroupMember
|
||||||
if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
|
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 {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
groupMember := db.GroupMember{
|
groupMember := db.GroupMember{
|
||||||
UserID: userId,
|
UserID: userId,
|
||||||
GroupID: groupId,
|
GroupID: groupId,
|
||||||
@@ -182,7 +180,7 @@ func GetGroupsCountNum(group db.Group) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
var count int32
|
var count int32
|
||||||
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -198,7 +196,7 @@ func GetGroupById(groupId string) (db.Group, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return group, err
|
return group, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
|
||||||
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
|
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
|
||||||
return group, err
|
return group, err
|
||||||
}
|
}
|
||||||
@@ -211,9 +209,17 @@ func GetGroupMaster(groupId string) (db.GroupMember, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return groupMember, err
|
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 {
|
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, err
|
||||||
}
|
}
|
||||||
return groupMember, nil
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||||
return groupRequestList, err
|
return groupRequestList, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return chatLogs, err
|
return chatLogs, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
db := dbConn.Table("chat_logs").
|
db := dbConn.Table("chat_logs").
|
||||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||||
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
|
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
|
||||||
@@ -43,7 +43,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
db := dbConn.Table("chat_logs").
|
db := dbConn.Table("chat_logs").
|
||||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||||
if chatLog.SessionType != 0 {
|
if chatLog.SessionType != 0 {
|
||||||
@@ -65,4 +65,4 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
|||||||
|
|
||||||
err = db.Find(&chatLogs).Count(&count).Error
|
err = db.Find(&chatLogs).Count(&count).Error
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func GetActiveUserNum(from, to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -21,7 +21,7 @@ func GetIncreaseUserNum(from, to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -32,7 +32,7 @@ func GetTotalUserNum() (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("users").Count(&num).Error
|
err = dbConn.Table("users").Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -43,7 +43,7 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
|
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -54,7 +54,7 @@ func GetPrivateMessageNum(from, to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -65,7 +65,7 @@ func GetGroupMessageNum(from, to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -76,7 +76,7 @@ func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -87,7 +87,7 @@ func GetTotalGroupNum() (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("groups").Count(&num).Error
|
err = dbConn.Table("groups").Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -98,7 +98,7 @@ func GetGroupNum(to time.Time) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var num int32
|
var num int32
|
||||||
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
|
||||||
return num, err
|
return num, err
|
||||||
@@ -116,7 +116,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return activeGroups, err
|
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
|
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 {
|
for _, activeGroup := range activeGroups {
|
||||||
group := db.Group{
|
group := db.Group{
|
||||||
@@ -140,7 +140,7 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return activeUsers, err
|
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
|
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 {
|
for _, activeUser := range activeUsers {
|
||||||
user := db.User{
|
user := db.User{
|
||||||
|
|||||||
@@ -74,12 +74,25 @@ func GetUserByUserID(userID string) (*db.User, error) {
|
|||||||
return &user, nil
|
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 {
|
func UpdateUserInfo(user db.User) error {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
|
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -99,7 +112,7 @@ func SelectAllUserID() ([]string, error) {
|
|||||||
|
|
||||||
func SelectSomeUserID(userIDList []string) ([]string, error) {
|
func SelectSomeUserID(userIDList []string) ([]string, error) {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -118,7 +131,7 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return users, err
|
return users, err
|
||||||
@@ -191,7 +204,7 @@ func UnBlockUser(userId string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
|
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
@@ -235,7 +248,7 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return blockUserInfos, err
|
return blockUserInfos, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
|
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
|
||||||
return blockUserInfos, err
|
return blockUserInfos, err
|
||||||
}
|
}
|
||||||
@@ -262,7 +275,7 @@ func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return users, err
|
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
|
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
@@ -272,7 +285,7 @@ func GetUsersCount(user db.User) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var count int32
|
var count int32
|
||||||
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
|
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -285,7 +298,7 @@ func GetBlockUsersNumCount() (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
var count int32
|
var count int32
|
||||||
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
|
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -298,7 +311,7 @@ func SetConversation(conversation db.Conversation) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
newConversation := conversation
|
newConversation := conversation
|
||||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
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 {
|
func SetRecvMsgOpt(conversation db.Conversation) error {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
newConversation := conversation
|
newConversation := conversation
|
||||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
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 {
|
if err != nil {
|
||||||
return conversations, err
|
return conversations, err
|
||||||
}
|
}
|
||||||
dbConn.LogMode(true)
|
dbConn.LogMode(false)
|
||||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||||
return conversations, err
|
return conversations, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const (
|
|||||||
userMinSeq = "REDIS_USER_MIN_SEQ:"
|
userMinSeq = "REDIS_USER_MIN_SEQ:"
|
||||||
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
uidPidToken = "UID_PID_TOKEN_STATUS:"
|
||||||
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
|
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
|
||||||
|
GetuiToken = "GETUI"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
|
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
|
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
|
// warp error
|
||||||
func WrapError(err constant.ErrInfo) error {
|
func WrapError(err constant.ErrInfo, msg ...string) error {
|
||||||
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
|
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 {
|
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||||
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
||||||
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "debug", moduleName),
|
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "info", moduleName),
|
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "warn", moduleName),
|
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "error", moduleName),
|
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
}, &nested.Formatter{
|
}, &nested.Formatter{
|
||||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||||
HideKeys: false,
|
HideKeys: false,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsAppManagerAccess(token string, OpUserID string) bool {
|
func IsAppManagerAccess(token string, OpUserID string) bool {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ func CheckAccess(OpUserID string, OwnerUserID string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(operationID, "ParseToken failed, ", err.Error(), token)
|
log.Error(operationID, "ParseToken failed, ", err.Error(), token)
|
||||||
return false, ""
|
return false, ""
|
||||||
@@ -138,31 +138,31 @@ func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
|||||||
return true, claims.UID
|
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)
|
claims, err = GetClaimFromToken(tokensString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", "token validate err", err.Error())
|
log.NewError(operationID, "token validate err", err.Error(), tokensString)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
||||||
if err != nil {
|
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
|
return nil, &constant.ErrTokenInvalid
|
||||||
}
|
}
|
||||||
if m == nil {
|
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
|
return nil, &constant.ErrTokenInvalid
|
||||||
}
|
}
|
||||||
if v, ok := m[tokensString]; ok {
|
if v, ok := m[tokensString]; ok {
|
||||||
switch v {
|
switch v {
|
||||||
case constant.NormalToken:
|
case constant.NormalToken:
|
||||||
log.NewDebug("", "this is normal return", claims)
|
log.NewDebug(operationID, "this is normal return", claims)
|
||||||
return claims, nil
|
return claims, nil
|
||||||
case constant.InValidToken:
|
case constant.InValidToken:
|
||||||
return nil, &constant.ErrTokenInvalid
|
return nil, &constant.ErrTokenInvalid
|
||||||
case constant.KickedToken:
|
case constant.KickedToken:
|
||||||
|
log.Error(operationID, "this token has been kicked by other same terminal ", constant.ErrTokenKicked)
|
||||||
return nil, &constant.ErrTokenKicked
|
return nil, &constant.ErrTokenKicked
|
||||||
case constant.ExpiredToken:
|
case constant.ExpiredToken:
|
||||||
return nil, &constant.ErrTokenExpired
|
return nil, &constant.ErrTokenExpired
|
||||||
@@ -170,6 +170,7 @@ func ParseToken(tokensString string) (claims *Claims, err error) {
|
|||||||
return nil, &constant.ErrTokenUnknown
|
return nil, &constant.ErrTokenUnknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.NewError(operationID, "redis token map not find", constant.ErrTokenUnknown)
|
||||||
return nil, &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
|
//Validation token, false means failure, true means successful verification
|
||||||
func VerifyToken(token, uid string) (bool, error) {
|
func VerifyToken(token, uid string) (bool, error) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -207,7 +208,7 @@ func VerifyToken(token, uid string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
|
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err, "parse token err"
|
return false, err, "parse token err"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,14 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group
|
|||||||
dst.AppMangerLevel = 1
|
dst.AppMangerLevel = 1
|
||||||
}
|
}
|
||||||
dst.JoinTime = int32(src.JoinTime.Unix())
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -318,6 +318,68 @@ message AddGroupMembersCMSResp {
|
|||||||
repeated string failed = 2;
|
repeated string failed = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message DismissGroupReq{
|
||||||
|
string opUserID = 1; //group or app manager
|
||||||
|
string operationID = 2;
|
||||||
|
string groupID = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
service group{
|
||||||
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
||||||
@@ -345,6 +407,12 @@ service group{
|
|||||||
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
|
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
|
||||||
rpc RemoveGroupMembersCMS(RemoveGroupMembersCMSReq) returns(RemoveGroupMembersCMSResp);
|
rpc RemoveGroupMembersCMS(RemoveGroupMembersCMSReq) returns(RemoveGroupMembersCMSResp);
|
||||||
rpc AddGroupMembersCMS(AddGroupMembersCMSReq) returns(AddGroupMembersCMSResp);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1305
pkg/proto/office/office.pb.go
Normal file
1305
pkg/proto/office/office.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
118
pkg/proto/office/office.proto
Normal file
118
pkg/proto/office/office.proto
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,34 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
option go_package = "./rtc;rtc";
|
option go_package = "./rtc;rtc";
|
||||||
package rtc;
|
package proto;
|
||||||
|
|
||||||
message CommonResp{
|
message CommonResp{
|
||||||
int32 errCode = 1;
|
int32 errCode = 1;
|
||||||
string errMsg = 2;
|
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{
|
message GroupInfo{
|
||||||
string groupID = 1;
|
string groupID = 1;
|
||||||
string groupName = 2;
|
string groupName = 2;
|
||||||
@@ -62,8 +84,136 @@ message GetJoinTokenResp{
|
|||||||
string liveURL = 3;
|
string liveURL = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
service RtcService {
|
message OfflinePushInfo{
|
||||||
rpc GetJoinToken(GetJoinTokenReq) returns(GetJoinTokenResp);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,7 @@ message GroupMemberFullInfo {
|
|||||||
int32 joinSource = 8;
|
int32 joinSource = 8;
|
||||||
string operatorUserID = 9;
|
string operatorUserID = 9;
|
||||||
string ex = 10;
|
string ex = 10;
|
||||||
|
uint32 muteEndTime = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PublicUserInfo{
|
message PublicUserInfo{
|
||||||
@@ -254,6 +255,39 @@ message MemberEnterTips{
|
|||||||
int64 operationTime = 3;
|
int64 operationTime = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GroupDismissedTips{
|
||||||
|
GroupInfo group = 1;
|
||||||
|
GroupMemberFullInfo opUser = 2;
|
||||||
|
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/////////////////////
|
//////////////////////friend/////////////////////
|
||||||
//message FriendInfo{
|
//message FriendInfo{
|
||||||
@@ -326,7 +360,12 @@ message UserInfoUpdatedTips{
|
|||||||
//////////////////////conversation/////////////////////
|
//////////////////////conversation/////////////////////
|
||||||
message ConversationUpdateTips{
|
message ConversationUpdateTips{
|
||||||
string UserID = 1;
|
string UserID = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConversationSetPrivateTips{
|
||||||
|
string recvID = 1;
|
||||||
|
string sendID = 2;
|
||||||
|
bool isPrivate = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -467,7 +506,7 @@ message DelMsgListReq{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message DelMsgListResp{
|
message DelMsgListResp{
|
||||||
int32 errCode = 1;
|
int32 errCode = 1;
|
||||||
string errMsg = 2;
|
string errMsg = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user