mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 22:39:18 +08:00
Compare commits
470 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1dbec122a | |||
| 47cb54461f | |||
| 91e03f7cfd | |||
| c0314d95c9 | |||
| 8e17b3ff51 | |||
| b932a659b6 | |||
| 80b2ed19e0 | |||
| 88000926f4 | |||
| 12245fefed | |||
| 8eebd5fb9a | |||
| c5b0e31d36 | |||
| 5c5e828cc6 | |||
| ecb11cf927 | |||
| 485241d080 | |||
| 8701f8868c | |||
| e68086e149 | |||
| 16a2d80801 | |||
| d5e5659a2c | |||
| 3c2e8dcf87 | |||
| 03320e8644 | |||
| 40ae6ccf2f | |||
| bcbade3729 | |||
| 58a6f9cae3 | |||
| bf154eb8c3 | |||
| 766b6e9fef | |||
| d89a41d4c7 | |||
| d24a7d7b22 | |||
| 57a746fc21 | |||
| 2c1bd41fba | |||
| 6260cf24cc | |||
| 88d4a670d4 | |||
| ea0b6c5ee5 | |||
| 20f61042fc | |||
| 2751a967e8 | |||
| 93057870a7 | |||
| 6b98c3fed5 | |||
| eb63ed926d | |||
| b72787f5bb | |||
| 0793b2ab38 | |||
| 604ed3e3e1 | |||
| 0aefbc2c7d | |||
| eb1fa90788 | |||
| 65f02e5139 | |||
| bbfe65a905 | |||
| 59468eb162 | |||
| 1889a283ee | |||
| 0655b2021d | |||
| a1b8c9b6fd | |||
| c4a60bc6f6 | |||
| eb7037eea8 | |||
| 7546083cd5 | |||
| 74ee36f43a | |||
| f8c3e4d66f | |||
| 6db8d9a38a | |||
| 61145a2d03 | |||
| 4a9410742a | |||
| db78e4ef03 | |||
| 7b0eb4e79d | |||
| 17f6b8eb2a | |||
| 37c40d7dda | |||
| 1a2aa876e3 | |||
| 39822f323f | |||
| 338acfba75 | |||
| 490f4f36f1 | |||
| 69c46f684f | |||
| 1626406557 | |||
| f662defcf9 | |||
| 8f07f8e9e1 | |||
| 7e44f7f110 | |||
| b211a66e99 | |||
| 0bdb066820 | |||
| 4ee84e10fd | |||
| ab706f4076 | |||
| bd7266653f | |||
| 08f968dced | |||
| 9f9ebd838a | |||
| a03f89fb68 | |||
| 51146a4ed5 | |||
| 80301f2cb2 | |||
| 9a9f26c435 | |||
| eebe9cbd5f | |||
| 503d43b552 | |||
| b3077fc15d | |||
| fdc462d071 | |||
| f44a26da3c | |||
| d12d03fd5e | |||
| 51ee2df755 | |||
| a89bb33015 | |||
| 7659cca8ba | |||
| f754e951f7 | |||
| e2905d01ac | |||
| 9d691f2452 | |||
| a426c8bb26 | |||
| bc8b1722b0 | |||
| ac31c612b3 | |||
| 03c3eea54e | |||
| bccaf16343 | |||
| 30df45ef2e | |||
| 6500ba48a7 | |||
| 03b35721a2 | |||
| 14327d4462 | |||
| 1b968903e2 | |||
| b719e95e6e | |||
| 318eb2f47d | |||
| 010f24e5c3 | |||
| db9762c5b2 | |||
| d1ebcde725 | |||
| 545f9cad2d | |||
| 3247d84b6b | |||
| e73f0a916a | |||
| 150af5ff8b | |||
| 1659ab146d | |||
| 86e17d38d4 | |||
| 1809c59f25 | |||
| 4eb9661730 | |||
| 4acbe4b31a | |||
| df17dd749f | |||
| 20e5a88e56 | |||
| 0a939a5b91 | |||
| 6ad7c30a18 | |||
| e6bfc60139 | |||
| c866baa4eb | |||
| 91303acdbe | |||
| 1273af4b1b | |||
| e682b408f3 | |||
| 0a0c206998 | |||
| 44ffd98d0c | |||
| 53ec93c8f8 | |||
| f779ed7628 | |||
| f2fdb74f23 | |||
| 4ba87e3349 | |||
| 7abee90992 | |||
| 159a9e00c8 | |||
| 9c62f38345 | |||
| 1443f5f997 | |||
| 17d8a124cd | |||
| 5cd565306e | |||
| 67010e20d7 | |||
| 704604f6fe | |||
| e687f56c7f | |||
| ff85575e98 | |||
| 26be25c218 | |||
| d3d5e0cbfb | |||
| 4796bf632c | |||
| 5eef365baf | |||
| 937ff63af9 | |||
| 33211bfb27 | |||
| a243da8b1e | |||
| 62e605a443 | |||
| 2bdaaa5a33 | |||
| bcad3c1ced | |||
| b865f5d6e7 | |||
| 00664822ec | |||
| 4594c15de7 | |||
| 2b6ec1672c | |||
| d44d5711cb | |||
| 54cb13ba62 | |||
| c32f5dd951 | |||
| 2e6c42c8ac | |||
| 5757b86d39 | |||
| 9df4a79827 | |||
| 071dd46a4c | |||
| 030d619910 | |||
| c56fd399c1 | |||
| 31c954db0e | |||
| cb6a040c4d | |||
| 51c3a753a9 | |||
| c28c592c80 | |||
| fc07f851f7 | |||
| ab4a5e6719 | |||
| 88e9dd54b2 | |||
| f53f34559a | |||
| 3e5d9a394f | |||
| 3f287eb148 | |||
| dfe854a236 | |||
| 3854c7bba2 | |||
| 01c066419d | |||
| 040b1d9bc8 | |||
| 6c4acbad68 | |||
| b5c11ece57 | |||
| 50696d2e88 | |||
| e7661fd4be | |||
| 957e11eff0 | |||
| bd6e8d093a | |||
| f7b5a86a09 | |||
| 97fd107f47 | |||
| fc688dca99 | |||
| fe3bd2a1f1 | |||
| 3625befc0b | |||
| 6e6508aafd | |||
| 3a8a0a541e | |||
| 650495306f | |||
| 5664c34790 | |||
| b1c66997ca | |||
| 114ffd4667 | |||
| ad1770ec95 | |||
| 5f22402761 | |||
| c11094a11e | |||
| 6873bf384e | |||
| 42242daf9b | |||
| 1f96b960ab | |||
| f6b30ed0c6 | |||
| c59dc129a8 | |||
| 472c1a9e3e | |||
| 24fe8ab4a4 | |||
| 453c6f05bd | |||
| 248de7f1f2 | |||
| 3bbf84861e | |||
| 0dac9044a5 | |||
| a981d1082a | |||
| 803d0c2ae2 | |||
| 06e44cc649 | |||
| fd01e5c263 | |||
| ecc47dcfbb | |||
| b6e06dfdc2 | |||
| eb630b23ae | |||
| eae7a48991 | |||
| 9436c836e6 | |||
| 7c64239b36 | |||
| 80ba371296 | |||
| 6787563efe | |||
| 9def85f9ba | |||
| 6d55f35404 | |||
| 1902c37924 | |||
| 02b5ff38a4 | |||
| f076a927c9 | |||
| 6184eaa30e | |||
| a42b72e9ce | |||
| f4dcae722c | |||
| bbcb3e9403 | |||
| 3d690b7c72 | |||
| b4ab2c69ae | |||
| 4a7f406edb | |||
| 9e18bcaeb8 | |||
| 9abfe233bc | |||
| 3267958541 | |||
| af5ee45206 | |||
| 300b72b9b8 | |||
| 42af55a740 | |||
| 3c1e6d0e5c | |||
| edf7df368e | |||
| cde38e012f | |||
| bef4f0c4e2 | |||
| bf081dce32 | |||
| 0bb3cb4aab | |||
| 0d5132f710 | |||
| cad147faf8 | |||
| cc405b83e2 | |||
| c65f5b7279 | |||
| c216340120 | |||
| ff5cbc490e | |||
| 27cba5ba31 | |||
| 9976b8132f | |||
| dbc5bd96f3 | |||
| 9489ab862b | |||
| 1bb634bc6f | |||
| 07b5c7fef4 | |||
| 4a7cfab543 | |||
| 426ef5cb88 | |||
| 5b86412407 | |||
| 4f8fcd2d3d | |||
| 16c40aa51c | |||
| 6449c4a53d | |||
| d670356388 | |||
| fb4c8549dc | |||
| 42dc5c1f0f | |||
| 659c3bc1cf | |||
| f5684f2c45 | |||
| 1d2d2b1c9c | |||
| bc06ba54b9 | |||
| 1b6e223456 | |||
| 9e4a2168c0 | |||
| 46aa26a444 | |||
| 4d01aa3006 | |||
| 2c308af615 | |||
| caf4ab60cd | |||
| 4a8d37bde1 | |||
| 3289dd8419 | |||
| 13473eeb4d | |||
| 4264cd8830 | |||
| edcc215774 | |||
| 3085fffb49 | |||
| 81a6e4b46c | |||
| e0d612c92f | |||
| fadbb91287 | |||
| 72146c08ae | |||
| 0c7cb274b4 | |||
| a08c499c95 | |||
| a879bbce59 | |||
| f11f8b3e0e | |||
| 7842545627 | |||
| 2a0f8f5ce3 | |||
| 4ae3ad7abd | |||
| a16025ca95 | |||
| fdefe09187 | |||
| 06370a763c | |||
| 691e2580e5 | |||
| f40369d061 | |||
| 046c523880 | |||
| b3b7ae26cf | |||
| 49424b8b56 | |||
| 68ff4a52dc | |||
| 07c932e9e6 | |||
| cbe3abeab0 | |||
| 3d5e3ce6cf | |||
| 4efdabc1ff | |||
| 8ca495ec50 | |||
| 69aba02c9a | |||
| 42225dd35e | |||
| ad4c9fcc83 | |||
| ef4d0c3c42 | |||
| 59cc45eaab | |||
| f64c40e91f | |||
| 46d7d30089 | |||
| 48f15bb71c | |||
| ac70b1d11b | |||
| d720082644 | |||
| 1f45b642e9 | |||
| 83228d8aa6 | |||
| 34f1e50f90 | |||
| b0c518a0d6 | |||
| aa673a3a5c | |||
| 40d58f6bc2 | |||
| 7604b24ffc | |||
| a47c0c91a3 | |||
| 0232f52281 | |||
| 08eba71c8a | |||
| 577a9249d1 | |||
| ea6461bd0a | |||
| f58c94146a | |||
| 6efe13d142 | |||
| 0a8fdc6cc8 | |||
| b91b298174 | |||
| f87038622b | |||
| 8b077848bb | |||
| 2945e6f8bf | |||
| 0f760dc388 | |||
| 5a9b5db99b | |||
| 6ba51fb338 | |||
| 146aa497f9 | |||
| e7bc82d152 | |||
| 26f8172b1a | |||
| 634584400a | |||
| 7d6be79ba8 | |||
| cef208f6ef | |||
| f4921d1317 | |||
| 7f1a74b576 | |||
| 3dc11777c6 | |||
| b536165910 | |||
| 7c7aa9e7a7 | |||
| 2b03b57b5c | |||
| 77c6120014 | |||
| b82ff7b88d | |||
| a16a75230c | |||
| 0e27b302bc | |||
| c369ab9b1c | |||
| bb267ccae7 | |||
| efe24658a4 | |||
| 5cdf9e7551 | |||
| 4390302384 | |||
| dab00e7fb2 | |||
| 929c5e7a5b | |||
| d600042110 | |||
| 0a58e7433e | |||
| 5639c985df | |||
| 9fbfbfb23b | |||
| ecd2f0e2bf | |||
| 60418276bd | |||
| 170392f0bc | |||
| 6744745152 | |||
| 009ae6a235 | |||
| bf5f72c00b | |||
| 84aca5b9e1 | |||
| 6164266870 | |||
| cc9df9c586 | |||
| 29a268d476 | |||
| 18d7aab703 | |||
| 373e6b6c8e | |||
| 71fab4f6be | |||
| de55c14a16 | |||
| e8517e954d | |||
| 78281fc82c | |||
| bc260fffde | |||
| db00a08bdc | |||
| 85cf7f26ce | |||
| acca147ff2 | |||
| d53da0e422 | |||
| 11eaaab72d | |||
| 475e64fc5b | |||
| 1bd8154ac4 | |||
| d2fa0e7852 | |||
| f2b324abc2 | |||
| d2225dd841 | |||
| 8d26aa86b9 | |||
| 7e937d7d29 | |||
| fe4b534b78 | |||
| d0a65c7c68 | |||
| 416f87f4bb | |||
| 7eeb67be28 | |||
| 7ed6ee5075 | |||
| d3c8215e15 | |||
| 30bc6c274e | |||
| ecb1068f0b | |||
| f6eef21b45 | |||
| 1aeff25316 | |||
| 6de569537f | |||
| 764bc3fead | |||
| a89d617532 | |||
| fef33795d0 | |||
| d2c04b761d | |||
| c5828aba91 | |||
| 1286f9dcb6 | |||
| 391e525fc5 | |||
| afc32b1cfa | |||
| 0797181967 | |||
| 14c5e631ff | |||
| 5cdb039c33 | |||
| a11c4fcb58 | |||
| c67a937d40 | |||
| 03fa7137b9 | |||
| e95400988e | |||
| 942c9c6a63 | |||
| 6c45665fde | |||
| d92ac8f588 | |||
| 169665da32 | |||
| c4d80b4844 | |||
| 7827749453 | |||
| 5e78697a69 | |||
| a0e6a78496 | |||
| af99a93536 | |||
| e9ea117985 | |||
| b9ddb0140f | |||
| dae70371d1 | |||
| 228cbb4082 | |||
| 679c913f3a | |||
| 03fb7947c3 | |||
| c39f5a27b2 | |||
| dbdb516f3c | |||
| c1a97b7356 | |||
| a6d8f7ea24 | |||
| 574c7600e0 | |||
| d1c0205d77 | |||
| 13c29d2c1e | |||
| dc1a0f050e | |||
| e252a00d55 | |||
| 5bedbb7c7d | |||
| e510418152 | |||
| 8197ae6aa7 | |||
| 9d619d520d | |||
| 46605479e9 | |||
| 6d20eddd43 | |||
| c1ee2a0adb | |||
| a4788a95af | |||
| c1a210313e | |||
| ab0ed67f81 | |||
| 5d54d5b7d6 | |||
| a2b65f52f6 | |||
| c16d8da784 | |||
| a55582a018 | |||
| ea6d472002 | |||
| 3dc4290f2a | |||
| 6c43f75f9f | |||
| e0c6972bed | |||
| 1ab3e04cba | |||
| 1b8f664c8a | |||
| 7637b2bec2 | |||
| cfab49a7dd | |||
| 91b9e50fd0 | |||
| ebf7a1d40d | |||
| d3a38963ae |
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: "\U0001F41E Bug"
|
||||
about: File a bug/issue
|
||||
title: "[BUG] <title>"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Note: Please search to see if an issue already exists for the bug you encountered.
|
||||
-->
|
||||
|
||||
### Environment:
|
||||
<!-- linux? windows? or Mac?
|
||||
Example:
|
||||
- OS: Ubuntu 20.04 -->
|
||||
|
||||
### Physical Memory Capacity:
|
||||
<!-- 8G or above is better -->
|
||||
|
||||
### Docker Image:
|
||||
<!-- Did you pull the docker image before execute docker images -->
|
||||
|
||||
### Code Version:
|
||||
<!-- Did you pull code from github? Make sure the code is up to date-->
|
||||
|
||||
### Component installation:
|
||||
<!-- Has etcd, mysql, mongodb, redis or Kafka been installed on the server before Open-IM-Server deployment-->
|
||||
|
||||
|
||||
### Log File:
|
||||
<!-- view log file(logs/openIM.log) content. -->
|
||||
|
||||
|
||||
### screenshot:
|
||||
<!---->
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
name: Deployment issues
|
||||
about: Deployment issues
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
If you are deploying OpenIM for the first time
|
||||
|
||||
|
||||
|
||||
```
|
||||
git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd Open-IM-Server/script ; chmod +x *.sh ; ./env_check.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd .. ; docker-compose up -d
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd script ; ./docker_check_service.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: 'update '
|
||||
about: update docker image
|
||||
title: update docker image
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
```
|
||||
cd Open-IM-Server ; docker-compose down
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
git pull
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
docker-compose pull
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
chmod +x script/*.sh ; docker-compose up -d
|
||||
```
|
||||
|
||||
screenshot here
|
||||
|
||||
```
|
||||
cd script ; ./docker_check_service.sh
|
||||
```
|
||||
|
||||
screenshot here
|
||||
@@ -7,6 +7,7 @@ out-test
|
||||
.github
|
||||
.idea
|
||||
|
||||
|
||||
deploy/open_im_demo
|
||||
deploy/open_im_api
|
||||
deploy/open_im_msg_gateway
|
||||
|
||||
@@ -92,6 +92,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
|
||||
4. Start docker-compose with one click(Docker automatically pulls all images)
|
||||
|
||||
```
|
||||
cd Open-IM-Server
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
@@ -99,6 +100,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server
|
||||
|
||||
```
|
||||
./docker_check_service.sh
|
||||
./check_all.sh
|
||||
```
|
||||
|
||||

|
||||
|
||||
+1
-1
Submodule cmd/Open-IM-SDK-Core updated: a06dfeeda5...b0897aa3ab
+76
-8
@@ -7,27 +7,44 @@ import (
|
||||
"Open_IM/internal/api/friend"
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/api/manage"
|
||||
"Open_IM/internal/api/office"
|
||||
"Open_IM/internal/api/organization"
|
||||
apiThird "Open_IM/internal/api/third"
|
||||
"Open_IM/internal/api/user"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
//"syscall"
|
||||
"Open_IM/pkg/common/constant"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
f, _ := os.Create("../logs/api.log")
|
||||
gin.DefaultWriter = io.MultiWriter(f)
|
||||
gin.SetMode(gin.DebugMode)
|
||||
r := gin.Default()
|
||||
r.Use(utils.CorsHandler())
|
||||
|
||||
log.Info("load config: ", config.Config)
|
||||
// user routing group, which handles user registration and login services
|
||||
userRouterGroup := r.Group("/user")
|
||||
{
|
||||
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
|
||||
userRouterGroup.POST("/get_users_info", user.GetUsersInfo) //1
|
||||
userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1
|
||||
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
|
||||
userRouterGroup.POST("/get_users_info", user.GetUsersInfo) //1
|
||||
userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1
|
||||
userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus) //1
|
||||
userRouterGroup.POST("/get_users_info_from_cache", user.GetUsersInfoFromCache)
|
||||
userRouterGroup.POST("/get_user_friend_from_cache", user.GetFriendIDListFromCache)
|
||||
userRouterGroup.POST("/get_black_list_from_cache", user.GetBlackIDListFromCache)
|
||||
}
|
||||
//friend routing group
|
||||
friendRouterGroup := r.Group("/friend")
|
||||
@@ -66,7 +83,14 @@ func main() {
|
||||
groupRouterGroup.POST("/get_group_members_info", group.GetGroupMembersInfo) //1
|
||||
groupRouterGroup.POST("/invite_user_to_group", group.InviteUserToGroup) //1
|
||||
groupRouterGroup.POST("/get_joined_group_list", group.GetJoinedGroupList) //1
|
||||
groupRouterGroup.POST("/dismiss_group", group.DismissGroup)
|
||||
groupRouterGroup.POST("/dismiss_group", group.DismissGroup) //
|
||||
groupRouterGroup.POST("/mute_group_member", group.MuteGroupMember)
|
||||
groupRouterGroup.POST("/cancel_mute_group_member", group.CancelMuteGroupMember) //MuteGroup
|
||||
groupRouterGroup.POST("/mute_group", group.MuteGroup)
|
||||
groupRouterGroup.POST("/cancel_mute_group", group.CancelMuteGroup)
|
||||
|
||||
groupRouterGroup.POST("/set_group_member_nickname", group.SetGroupMemberNickname)
|
||||
|
||||
}
|
||||
//certificate
|
||||
authRouterGroup := r.Group("/auth")
|
||||
@@ -78,6 +102,7 @@ func main() {
|
||||
thirdGroup := r.Group("/third")
|
||||
{
|
||||
thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential)
|
||||
thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential)
|
||||
thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential)
|
||||
thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile)
|
||||
}
|
||||
@@ -107,13 +132,56 @@ func main() {
|
||||
conversationGroup.POST("/set_conversation", conversation.SetConversation)
|
||||
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
||||
conversationGroup.POST("/modify_conversation_field", conversation.ModifyConversationField)
|
||||
}
|
||||
apiThird.MinioInit()
|
||||
log.NewPrivateLog("api")
|
||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||
// office
|
||||
officeGroup := r.Group("/office")
|
||||
{
|
||||
officeGroup.POST("/get_user_tags", office.GetUserTags)
|
||||
officeGroup.POST("/get_user_tag_by_id", office.GetUserTagByID)
|
||||
officeGroup.POST("/create_tag", office.CreateTag)
|
||||
officeGroup.POST("/delete_tag", office.DeleteTag)
|
||||
officeGroup.POST("/set_tag", office.SetTag)
|
||||
officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag)
|
||||
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
||||
|
||||
officeGroup.POST("/create_one_work_moment", office.CreateOneWorkMoment)
|
||||
officeGroup.POST("/delete_one_work_moment", office.DeleteOneWorkMoment)
|
||||
officeGroup.POST("/like_one_work_moment", office.LikeOneWorkMoment)
|
||||
officeGroup.POST("/comment_one_work_moment", office.CommentOneWorkMoment)
|
||||
officeGroup.POST("/get_work_moment_by_id", office.GetWorkMomentByID)
|
||||
officeGroup.POST("/get_user_work_moments", office.GetUserWorkMoments)
|
||||
officeGroup.POST("/get_user_friend_work_moments", office.GetUserFriendWorkMoments)
|
||||
officeGroup.POST("/set_user_work_moments_level", office.SetUserWorkMomentsLevel)
|
||||
}
|
||||
|
||||
organizationGroup := r.Group("/organization")
|
||||
{
|
||||
organizationGroup.POST("/create_department", organization.CreateDepartment)
|
||||
organizationGroup.POST("/update_department", organization.UpdateDepartment)
|
||||
organizationGroup.POST("/get_sub_department", organization.GetSubDepartment)
|
||||
organizationGroup.POST("/delete_department", organization.DeleteDepartment)
|
||||
organizationGroup.POST("/get_all_department", organization.GetAllDepartment)
|
||||
|
||||
organizationGroup.POST("/create_organization_user", organization.CreateOrganizationUser)
|
||||
organizationGroup.POST("/update_organization_user", organization.UpdateOrganizationUser)
|
||||
organizationGroup.POST("/delete_organization_user", organization.DeleteOrganizationUser)
|
||||
|
||||
organizationGroup.POST("/create_department_member", organization.CreateDepartmentMember)
|
||||
organizationGroup.POST("/get_user_in_department", organization.GetUserInDepartment)
|
||||
organizationGroup.POST("/update_user_in_department", organization.UpdateUserInDepartment)
|
||||
|
||||
organizationGroup.POST("/get_department_member", organization.GetDepartmentMember)
|
||||
organizationGroup.POST("/delete_user_in_department", organization.DeleteUserInDepartment)
|
||||
|
||||
}
|
||||
|
||||
go apiThird.MinioInit()
|
||||
ginPort := flag.Int("port", 10002, "get ginServerPort from cmd,default 10000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start api server, port: ", *ginPort)
|
||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "start gin failed", err.Error())
|
||||
log.Error("", "run failed ", *ginPort, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/cms_api"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -11,5 +14,10 @@ func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := cms_api.NewGinRouter()
|
||||
router.Use(utils.CorsHandler())
|
||||
router.Run(":" + "8000")
|
||||
ginPort := flag.Int("port", 10006, "get ginServerPort from cmd,default 8000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start cms api server, port: ", ginPort)
|
||||
router.Run(":" + strconv.Itoa(*ginPort))
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -2,20 +2,28 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/demo/register"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
f, _ := os.Create("../logs/api.log")
|
||||
gin.DefaultWriter = io.MultiWriter(f)
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(utils.CorsHandler())
|
||||
|
||||
authRouterGroup := r.Group("/auth")
|
||||
authRouterGroup := r.Group("/demo")
|
||||
{
|
||||
authRouterGroup.POST("/code", register.SendVerificationCode)
|
||||
authRouterGroup.POST("/verify", register.Verify)
|
||||
@@ -23,8 +31,12 @@ func main() {
|
||||
authRouterGroup.POST("/login", register.Login)
|
||||
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||
}
|
||||
log.NewPrivateLog("demo")
|
||||
|
||||
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
||||
flag.Parse()
|
||||
r.Run(":" + strconv.Itoa(*ginPort))
|
||||
fmt.Println("start demo api server, port: ", *ginPort)
|
||||
err := r.Run(":" + strconv.Itoa(*ginPort))
|
||||
if err != nil {
|
||||
log.Error("", "run failed ", *ginPort, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,21 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_gateway/gate"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rpcPort := flag.Int("rpc_port", 10400, "rpc listening port")
|
||||
wsPort := flag.Int("ws_port", 17778, "ws listening port")
|
||||
flag.Parse()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
fmt.Println("start rpc/msg_gateway server, port: ", *rpcPort, *wsPort)
|
||||
gate.Init(*rpcPort, *wsPort)
|
||||
gate.Run()
|
||||
wg.Wait()
|
||||
|
||||
@@ -2,13 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_transfer/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
logic.Init()
|
||||
fmt.Println("start msg_transfer server")
|
||||
logic.Run()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"flag"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -11,6 +14,8 @@ func main() {
|
||||
flag.Parse()
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
fmt.Println("start push rpc server, port: ", *rpcPort)
|
||||
logic.Init(*rpcPort)
|
||||
logic.Run()
|
||||
wg.Wait()
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.NewPrivateLog("timer")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
//for {
|
||||
// fmt.Println("start delete mongodb expired record")
|
||||
// timeUnixBegin := time.Now().Unix()
|
||||
@@ -39,27 +37,27 @@ func main() {
|
||||
// time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
// }
|
||||
//}
|
||||
for {
|
||||
uidList, err := im_mysql_model.SelectAllUserID()
|
||||
if err != nil {
|
||||
//log.NewError("999999", err.Error())
|
||||
} else {
|
||||
for _, v := range uidList {
|
||||
minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||
if err != nil {
|
||||
//log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||
continue
|
||||
} else {
|
||||
err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||
if err != nil {
|
||||
//log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//for {
|
||||
// uidList, err := im_mysql_model.SelectAllUserID()
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", err.Error())
|
||||
// } else {
|
||||
// for _, v := range uidList {
|
||||
// minSeq, err := commonDB.DB.GetMinSeqFromMongo(v)
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", "get user minSeq err", err.Error(), v)
|
||||
// continue
|
||||
// } else {
|
||||
// err := commonDB.DB.SetUserMinSeq(v, minSeq)
|
||||
// if err != nil {
|
||||
// //log.NewError("999999", "set user minSeq err", err.Error(), v)
|
||||
// }
|
||||
// }
|
||||
// time.Sleep(time.Duration(100) * time.Millisecond)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package main
|
||||
import (
|
||||
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11000, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start cms rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcAuth "Open_IM/internal/rpc/auth"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
|
||||
flag.Parse()
|
||||
fmt.Println("start auth rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_cache
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpcCache "Open_IM/internal/rpc/cache"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
|
||||
flag.Parse()
|
||||
fmt.Println("start auth rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcCache.NewCacheServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_conversation
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpcConversation "Open_IM/internal/rpc/conversation"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11400, "RpcConversation default listen port 11300")
|
||||
flag.Parse()
|
||||
fmt.Println("start conversation rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcConversation.NewRpcConversationServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
|
||||
}
|
||||
@@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/friend"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start friend rpc server, port: ", *rpcPort)
|
||||
rpcServer := friend.NewFriendServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/group"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10500, "get RpcGroupPort from cmd,default 16000 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start group rpc server, port: ", *rpcPort)
|
||||
rpcServer := group.NewGroupServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10900, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start msg cms rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
rpcChat "Open_IM/internal/rpc/msg"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10300, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start msg rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_office
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
||||
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpc "Open_IM/internal/rpc/office"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11100, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start office rpc server, port: ", *rpcPort)
|
||||
rpcServer := rpc.NewOfficeServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
.PHONY: all build run gotool install clean help
|
||||
|
||||
BINARY_NAME=open_im_organization
|
||||
BIN_DIR=../../../bin/
|
||||
|
||||
all: gotool build
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s"
|
||||
|
||||
run:
|
||||
@go run ./
|
||||
|
||||
gotool:
|
||||
go fmt ./
|
||||
go vet ./
|
||||
|
||||
install:
|
||||
make build
|
||||
mv ${BINARY_NAME} ${BIN_DIR}
|
||||
|
||||
clean:
|
||||
@if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/organization"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 11200, "get RpcOrganizationPort from cmd,default 11200 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start organization rpc server, port: ", *rpcPort)
|
||||
rpcServer := organization.NewServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/statistics"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10800, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start statistics rpc server, port: ", *rpcPort)
|
||||
rpcServer := statistics.NewStatisticsServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package main
|
||||
import (
|
||||
"Open_IM/internal/rpc/user"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcPort := flag.Int("port", 10100, "rpc listening port")
|
||||
flag.Parse()
|
||||
fmt.Println("start user rpc server, port: ", *rpcPort)
|
||||
rpcServer := user.NewUserServer(*rpcPort)
|
||||
rpcServer.Run()
|
||||
}
|
||||
|
||||
+164
-21
@@ -19,7 +19,8 @@ mysql:
|
||||
dbMaxLifeTime: 120
|
||||
|
||||
mongo:
|
||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||
dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可
|
||||
dbDirect: false
|
||||
dbTimeout: 10
|
||||
dbDatabase: openIM #mongo db 默认即可
|
||||
@@ -72,40 +73,58 @@ endpoints:
|
||||
rpc_statistic: openim_rpc_statistic
|
||||
rpc_admin_cms: openim_rpc_admin_cms
|
||||
rpc_message_cms: openim_rpc_admin_cms
|
||||
rpc_office: openim_rpc_office
|
||||
|
||||
api:
|
||||
openImApiPort: [ 10000 ] #api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
openImApiPort: [ 10002 ] #api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
cmsapi:
|
||||
openImCmsApiPort: [ 8000 ] #管理后台api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
openImCmsApiPort: [ 10006 ] #管理后台api服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
sdk:
|
||||
openImSdkWsPort: [ 30000 ] #jssdk服务端口,默认即可,项目中使用jssdk才需开放此端口或做nginx转发
|
||||
openImSdkWsPort: [ 10003 ] #jssdk服务端口,默认即可,项目中使用jssdk才需开放此端口或做nginx转发
|
||||
#对象存储服务,以下配置二选一,目前支持两种,腾讯云和minio,二者配置好其中一种即可(如果使用minio参考https://doc.rentsoft.cn/#/qa/minio搭建minio服务器)
|
||||
credential: #腾讯cos,发送图片、视频、文件时需要,请自行申请后替换,必须修改
|
||||
tencent:
|
||||
appID: 1302656840
|
||||
region: ap-chengdu
|
||||
bucket: echat-1302656840
|
||||
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC
|
||||
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe
|
||||
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC1
|
||||
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe1
|
||||
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio
|
||||
bucket: openim
|
||||
location: us-east-1
|
||||
endpoint: http://43.128.5.63:9000
|
||||
endpoint: http://127.0.0.1:10005 #minio外网ip 这个ip是给客户端访问的
|
||||
endpointInner: http://127.0.0.1:10005 #minio内网地址 如果im server 可以通过内网访问到 minio就可以填写
|
||||
endpointInnerEnable: true #是否启用minio内网地址 启用可以让桶初始化,IM server连接minio走内网地址访问
|
||||
accessKeyID: user12345
|
||||
secretAccessKey: key12345
|
||||
ali: # ali oss
|
||||
regionID: "oss-cn-beijing"
|
||||
accessKeyID: ""
|
||||
accessKeySecret: ""
|
||||
stsEndpoint: "sts.cn-beijing.aliyun.com"
|
||||
ossEndpoint: "oss-cn-beijing.aliyuncs.com"
|
||||
bucket: "bucket1"
|
||||
finalHost: "http://bucket1.oss-cn-beijing.aliyuncs.com"
|
||||
stsDurationSeconds: 3600
|
||||
OssRoleArn: "acs:ram::xxx:role/xxx"
|
||||
|
||||
|
||||
|
||||
rpcport: #rpc服务端口 默认即可
|
||||
openImUserPort: [ 10100 ]
|
||||
openImFriendPort: [ 10200 ]
|
||||
openImOfflineMessagePort: [ 10300 ]
|
||||
openImOnlineRelayPort: [ 10400 ]
|
||||
openImGroupPort: [ 10500 ]
|
||||
openImAuthPort: [ 10600 ]
|
||||
openImPushPort: [ 10700 ]
|
||||
openImStatisticsPort: [ 10800 ]
|
||||
openImMessageCmsPort: [ 10900 ]
|
||||
openImAdminCmsPort: [ 11000 ]
|
||||
openImUserPort: [ 10110 ]
|
||||
openImFriendPort: [ 10120 ]
|
||||
openImMessagePort: [ 10130 ]
|
||||
openImMessageGatewayPort: [ 10140 ]
|
||||
openImGroupPort: [ 10150 ]
|
||||
openImAuthPort: [ 10160 ]
|
||||
openImPushPort: [ 10170 ]
|
||||
openImStatisticsPort: [ 10180 ]
|
||||
openImMessageCmsPort: [ 10190 ]
|
||||
openImAdminCmsPort: [ 10200 ]
|
||||
openImOfficePort: [ 10210 ]
|
||||
openImOrganizationPort: [ 10220 ]
|
||||
openImConversationPort: [ 10230 ]
|
||||
openImCachePort: [10240]
|
||||
c2c:
|
||||
callbackBeforeSendMsg:
|
||||
switch: false
|
||||
@@ -127,6 +146,10 @@ rpcregistername: #rpc注册服务名,默认即可
|
||||
OpenImStatisticsName: Statistics
|
||||
OpenImMessageCMSName: MessageCMS
|
||||
openImAdminCMSName: AdminCMS
|
||||
openImOfficeName: Office
|
||||
openImOrganizationName: Organization
|
||||
openImConversationName: Conversation
|
||||
openImCacheName: Cache
|
||||
|
||||
log:
|
||||
storageLocation: ../logs/
|
||||
@@ -145,11 +168,12 @@ modulename: #日志文件按模块命名,默认即可
|
||||
pushName: push
|
||||
|
||||
longconnsvr:
|
||||
openImWsPort: [ 17778 ] # ws服务端口,默认即可,要开放此端口或做nginx转发
|
||||
openImWsPort: [ 10001 ] # ws服务端口,默认即可,要开放此端口或做nginx转发
|
||||
websocketMaxConnNum: 10000
|
||||
websocketMaxMsgLen: 4096
|
||||
websocketTimeOut: 10
|
||||
|
||||
## 推送只能开启一个 enable代表开启
|
||||
push:
|
||||
tpns: #腾讯推送,暂未测试 暂不要使用
|
||||
ios:
|
||||
@@ -158,11 +182,22 @@ push:
|
||||
android:
|
||||
accessID: 111
|
||||
secretKey: 111
|
||||
enable: false
|
||||
jpns: #极光推送 在极光后台申请后,修改以下四项,必须修改
|
||||
appKey: cf47465a368f24c659608e7e
|
||||
masterSecret: 02204efe3f3832947a236ee5
|
||||
pushUrl: "https://api.jpush.cn/v3/push"
|
||||
pushIntent: "intent:#Intent;component=io.openim.app.enterprisechat/io.openim.app.enterprisechat.MainActivity;end"
|
||||
enable: true
|
||||
getui: #个推推送,暂未测试 暂不要使用
|
||||
pushUrl: "https://restapi.getui.com/v2/$appId"
|
||||
masterSecret: ""
|
||||
appKey: ""
|
||||
intent: ""
|
||||
enable: false
|
||||
|
||||
|
||||
|
||||
manager:
|
||||
#app管理员userID和对应的secret 建议修改。 用于管理后台登录,也可以用户管理后台对应的api
|
||||
appManagerUid: [ "openIM123456","openIM654321", "openIM333", "openIMAdmin"]
|
||||
@@ -173,6 +208,9 @@ secret: tuoyun
|
||||
# 1:多平台登录:Android、iOS、Windows、Mac 每种平台只能一个在线,web端可以多个同时在线
|
||||
multiloginpolicy: 1
|
||||
|
||||
#chat log insert to db
|
||||
chatPersistenceMysql: true
|
||||
|
||||
#token config
|
||||
tokenpolicy:
|
||||
accessSecret: "open_im_server" #token生成相关,默认即可
|
||||
@@ -351,6 +389,84 @@ notification:
|
||||
ext: "groupDismissed ext"
|
||||
defaultTips:
|
||||
tips: "group dismissed"
|
||||
|
||||
|
||||
groupMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMuted title"
|
||||
desc: "groupMuted desc"
|
||||
ext: "groupMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Muted"
|
||||
|
||||
groupCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupCancelMuted title"
|
||||
desc: "groupCancelMuted desc"
|
||||
ext: "groupCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Cancel Muted"
|
||||
|
||||
|
||||
groupMemberMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberMuted title"
|
||||
desc: "groupMemberMuted desc"
|
||||
ext: "groupMemberMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Muted"
|
||||
|
||||
groupMemberCancelMuted:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
unreadCount: true
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberCancelMuted title"
|
||||
desc: "groupMemberCancelMuted desc"
|
||||
ext: "groupMemberCancelMuted ext"
|
||||
defaultTips:
|
||||
tips: "group Member Cancel Muted"
|
||||
|
||||
groupMemberInfoSet:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "groupMemberInfoSet title"
|
||||
desc: "groupMemberInfoSet desc"
|
||||
ext: "groupMemberInfoSet ext"
|
||||
defaultTips:
|
||||
tips: "group member info set"
|
||||
|
||||
|
||||
organizationChanged:
|
||||
conversation:
|
||||
reliabilityLevel: 2
|
||||
unreadCount: false
|
||||
offlinePush:
|
||||
switch: false
|
||||
title: "organizationChanged title"
|
||||
desc: "organizationChanged desc"
|
||||
ext: "organizationChanged ext"
|
||||
defaultTips:
|
||||
tips: "organization changed"
|
||||
|
||||
|
||||
|
||||
#############################friend#################################
|
||||
|
||||
friendApplicationAdded:
|
||||
@@ -486,6 +602,32 @@ notification:
|
||||
defaultTips:
|
||||
tips: "conversation opt update"
|
||||
|
||||
conversationSetPrivate:
|
||||
conversation:
|
||||
reliabilityLevel: 3
|
||||
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"
|
||||
|
||||
###################workMoments################
|
||||
workMomentsNotification:
|
||||
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---------------------#
|
||||
@@ -494,7 +636,7 @@ notification:
|
||||
demoswitch: true
|
||||
demo:
|
||||
#demo对外服务端口,默认即可,需要开放此端口或做nginx转发
|
||||
openImDemoPort: [ 42233 ]
|
||||
openImDemoPort: [ 10004 ]
|
||||
alismsverify: #阿里云短信配置,在阿里云申请成功后修改以下四项,必须修改
|
||||
accessKeyId: LTAI5tJPkn4HuuePdiLdGqe7
|
||||
accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV
|
||||
@@ -510,5 +652,6 @@ demo:
|
||||
smtpAddr: "smtp.qq.com"
|
||||
smtpPort: 25 #需开放此端口 出口方向
|
||||
|
||||
|
||||
|
||||
rtc:
|
||||
port: 11300
|
||||
address: 127.0.0.1
|
||||
@@ -19,6 +19,7 @@ mysql:
|
||||
dbMaxLifeTime: 120
|
||||
|
||||
mongo:
|
||||
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||
dbAddress: [ openim_mongo:27017 ]
|
||||
dbDirect: false
|
||||
dbTimeout: 10
|
||||
|
||||
+2
-1
@@ -32,6 +32,7 @@ services:
|
||||
# - MONGO_INITDB_ROOT_USERNAME=openIM
|
||||
# - MONGO_INITDB_ROOT_PASSWORD=openIM
|
||||
|
||||
|
||||
#TZ: Asia/Shanghai
|
||||
restart: always
|
||||
|
||||
@@ -93,7 +94,7 @@ services:
|
||||
command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new
|
||||
|
||||
open_im_server:
|
||||
image: openim/open_im_server:v2.0.2
|
||||
image: openim/open_im_server:v2.0.8
|
||||
container_name: open_im_server
|
||||
volumes:
|
||||
- ./logs:/Open-IM-Server/logs
|
||||
|
||||
@@ -7,6 +7,7 @@ require (
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0
|
||||
github.com/alibabacloud-go/tea v1.1.17
|
||||
github.com/antonfisher/nested-logrus-formatter v1.3.0
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
@@ -21,7 +22,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.7.0
|
||||
github.com/go-playground/validator/v10 v10.4.1
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang-jwt/jwt/v4 v4.1.0
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
@@ -59,6 +60,7 @@ require (
|
||||
google.golang.org/protobuf v1.27.1
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
sigs.k8s.io/yaml v1.2.0 // indirect
|
||||
|
||||
@@ -53,6 +53,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.7/go.mod h1:6FV1Bt1AItYIlC2rVopPTumrRNtkfPBmrPVAZ8v2bLk=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8=
|
||||
github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU=
|
||||
github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA=
|
||||
@@ -62,8 +63,11 @@ github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 h1:KXMiCg99Jx7B6V+DlRFbWw
|
||||
github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8/go.mod h1:8aL6tSyQIWJygF7W/Vqxdf/QDbN2S+u57k36bEA8hD8=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
|
||||
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.8/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0=
|
||||
github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0 h1:1yVyKz02ES6aKo3xVjmoPLBH1OAmmSqPkhKRdjEkmYs=
|
||||
github.com/alibabacloud-go/sts-20150401 v1.1.0/go.mod h1:QW4O/c7Hp4krHYt+6xwnoG8EyZW3V9GYkl6EgIBmxJc=
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
|
||||
@@ -1095,6 +1099,8 @@ gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
|
||||
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
|
||||
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
|
||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
|
||||
+28
-15
@@ -17,14 +17,16 @@ import (
|
||||
func UserRegister(c *gin.Context) {
|
||||
params := api.UserRegisterReq{}
|
||||
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()})
|
||||
errMsg := " BindJSON failed " + err.Error()
|
||||
log.NewError("0", errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
log.NewError(params.OperationID, "params.Secret != config.Config.Secret", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
errMsg := " params.Secret != config.Config.Secret "
|
||||
log.NewError(params.OperationID, errMsg, params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
req := &rpc.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
||||
@@ -35,17 +37,25 @@ func UserRegister(c *gin.Context) {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := rpc.NewAuthClient(etcdConn)
|
||||
reply, err := client.UserRegister(context.Background(), req)
|
||||
if err != nil || reply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err, reply.CommonResp.ErrCode)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": reply.CommonResp.ErrMsg})
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "client.UserRegister failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
if reply.CommonResp.ErrCode != 0 {
|
||||
errMsg := req.OperationID + " " + " client.UserRegister failed " + reply.CommonResp.ErrMsg + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
||||
replyToken, err := client.UserToken(context.Background(), pbDataToken)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserToken failed ", err.Error(), pbDataToken)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
errMsg := req.OperationID + " " + " client.UserToken failed " + err.Error() + pbDataToken.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
resp := api.UserRegisterResp{CommResp: api.CommResp{ErrCode: replyToken.CommonResp.ErrCode, ErrMsg: replyToken.CommonResp.ErrMsg},
|
||||
@@ -58,14 +68,16 @@ func UserRegister(c *gin.Context) {
|
||||
func UserToken(c *gin.Context) {
|
||||
params := api.UserTokenReq{}
|
||||
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()})
|
||||
errMsg := " BindJSON failed " + err.Error()
|
||||
log.NewError("0", errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
errMsg := params.OperationID + " params.Secret != config.Config.Secret "
|
||||
log.NewError(params.OperationID, "params.Secret != config.Config.Secret", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
req := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
||||
@@ -74,12 +86,13 @@ func UserToken(c *gin.Context) {
|
||||
client := rpc.NewAuthClient(etcdConn)
|
||||
reply, err := client.UserToken(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserToken failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
errMsg := req.OperationID + " UserToken failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
resp := api.UserTokenResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg},
|
||||
UserToken: api.UserTokenInfo{UserID: req.FromUserID, Token: reply.Token, ExpiredTime: reply.ExpiredTime}}
|
||||
log.NewInfo(req.OperationID, "UserRegister return ", resp)
|
||||
log.NewInfo(req.OperationID, "UserToken return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@@ -44,6 +45,37 @@ func SetConversation(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
func ModifyConversationField(c *gin.Context) {
|
||||
var (
|
||||
req api.ModifyConversationFieldReq
|
||||
resp api.ModifyConversationFieldResp
|
||||
reqPb pbConversation.ModifyConversationFieldReq
|
||||
)
|
||||
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
|
||||
}
|
||||
reqPb.Conversation = &pbConversation.Conversation{}
|
||||
err := utils.CopyStructFields(&reqPb, req)
|
||||
err = utils.CopyStructFields(reqPb.Conversation, req.Conversation)
|
||||
if err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName)
|
||||
client := pbConversation.NewConversationClient(etcdConn)
|
||||
respPb, err := client.ModifyConversationField(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func BatchSetConversations(c *gin.Context) {
|
||||
var (
|
||||
@@ -128,7 +160,7 @@ func GetConversation(c *gin.Context) {
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -192,7 +224,7 @@ func SetRecvMsgOpt(c *gin.Context) {
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetRecvMsgOpt rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -201,3 +233,18 @@ func SetRecvMsgOpt(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func SetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
//Deprecated
|
||||
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
+167
-1
@@ -259,7 +259,7 @@ func CreateGroup(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.OwnerUserID = req.OpUserID
|
||||
req.OwnerUserID = params.OwnerUserID
|
||||
req.OperationID = params.OperationID
|
||||
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
||||
|
||||
@@ -568,3 +568,169 @@ func DismissGroup(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func MuteGroupMember(c *gin.Context) {
|
||||
params := api.MuteGroupMemberReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.MuteGroupMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.MuteGroupMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.MuteGroupMemberResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CancelMuteGroupMember(c *gin.Context) {
|
||||
params := api.CancelMuteGroupMemberReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.CancelMuteGroupMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.CancelMuteGroupMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CancelMuteGroupMemberResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func MuteGroup(c *gin.Context) {
|
||||
params := api.MuteGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.MuteGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.MuteGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.MuteGroupResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CancelMuteGroup(c *gin.Context) {
|
||||
params := api.CancelMuteGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.CancelMuteGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.CancelMuteGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CancelMuteGroupResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//SetGroupMemberNickname
|
||||
|
||||
func SetGroupMemberNickname(c *gin.Context) {
|
||||
params := api.SetGroupMemberNicknameReq{}
|
||||
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.SetGroupMemberNicknameReq{}
|
||||
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.SetGroupMemberNickname(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.SetGroupMemberNicknameResp{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 GetGroupMemberIDListFromCache(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -29,6 +30,7 @@ var validate *validator.Validate
|
||||
|
||||
func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
var newContent string
|
||||
var err error
|
||||
switch params.ContentType {
|
||||
case constant.Text:
|
||||
newContent = params.Content["text"].(string)
|
||||
@@ -42,6 +44,7 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
newContent = utils.StructToJsonString(params.Content)
|
||||
case constant.Revoke:
|
||||
newContent = params.Content["revokeMsgClientID"].(string)
|
||||
|
||||
default:
|
||||
}
|
||||
var options map[string]bool
|
||||
@@ -72,6 +75,14 @@ func newUserSendMsgReq(params *ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||
OfflinePushInfo: params.OfflinePushInfo,
|
||||
},
|
||||
}
|
||||
if params.ContentType == constant.OANotification {
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.JsonDetail = utils.StructToJsonString(params.Content)
|
||||
pbData.MsgData.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(params.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
}
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
func init() {
|
||||
@@ -107,6 +118,9 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
data = CustomElem{}
|
||||
case constant.Revoke:
|
||||
data = RevokeElem{}
|
||||
case constant.OANotification:
|
||||
data = OANotificationElem{}
|
||||
params.SessionType = constant.NotificationChatType
|
||||
//case constant.HasReadReceipt:
|
||||
//case constant.Typing:
|
||||
//case constant.Quote:
|
||||
@@ -126,7 +140,7 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
}
|
||||
log.NewInfo("", data, params)
|
||||
token := c.Request.Header.Get("token")
|
||||
claims, err := token_verify.ParseToken(token)
|
||||
claims, err := token_verify.ParseToken(token, params.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||
@@ -204,16 +218,16 @@ type ManagementSendMsgReq struct {
|
||||
|
||||
type PictureBaseInfo struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
Type string `mapstructure:"type" validate:"required"`
|
||||
Size int64 `mapstructure:"size" validate:"required"`
|
||||
Width int32 `mapstructure:"width" validate:"required"`
|
||||
Height int32 `mapstructure:"height" validate:"required"`
|
||||
Url string `mapstructure:"url" validate:"required"`
|
||||
Type string `mapstructure:"type" `
|
||||
Size int64 `mapstructure:"size" `
|
||||
Width int32 `mapstructure:"width" `
|
||||
Height int32 `mapstructure:"height"`
|
||||
Url string `mapstructure:"url" `
|
||||
}
|
||||
|
||||
type PictureElem struct {
|
||||
SourcePath string `mapstructure:"sourcePath"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
|
||||
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
||||
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
||||
}
|
||||
@@ -267,3 +281,16 @@ type TextElem struct {
|
||||
type RevokeElem struct {
|
||||
RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"`
|
||||
}
|
||||
type OANotificationElem struct {
|
||||
NotificationName string `mapstructure:"notificationName" validate:"required"`
|
||||
NotificationFaceURL string `mapstructure:"notificationFaceURL" validate:"required"`
|
||||
NotificationType int32 `mapstructure:"notificationType" validate:"required"`
|
||||
Text string `mapstructure:"text" validate:"required"`
|
||||
Url string `mapstructure:"url"`
|
||||
MixType int32 `mapstructure:"mixType"`
|
||||
PictureElem PictureElem `mapstructure:"pictureElem"`
|
||||
SoundElem SoundElem `mapstructure:"soundElem"`
|
||||
VideoElem VideoElem `mapstructure:"videoElem"`
|
||||
FileElem FileElem `mapstructure:"fileElem"`
|
||||
Ex string `mapstructure:"ex"`
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ func AccountCheck(c *gin.Context) {
|
||||
log.NewInfo(req.OperationID, "AccountCheck api return", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := api.GetUsersOnlineStatusReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
@@ -133,6 +134,7 @@ func GetUsersOnlineStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(params.OperationID, "GetUsersOnlineStatus args ", req.String())
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
@@ -176,5 +178,4 @@ func GetUsersOnlineStatus(c *gin.Context) {
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
apistruct "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserTags(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetUserTagsReq
|
||||
resp apistruct.GetUserTagsResp
|
||||
reqPb pbOffice.GetUserTagsReq
|
||||
respPb *pbOffice.GetUserTagsResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTags(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserTags rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
if respPb.Tags != nil {
|
||||
resp.Data.Tags = respPb.Tags
|
||||
} else {
|
||||
resp.Data.Tags = []*pbOffice.Tag{}
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CreateTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.CreateTagReq
|
||||
resp apistruct.CreateTagResp
|
||||
reqPb pbOffice.CreateTagReq
|
||||
respPb *pbOffice.CreateTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.CreateTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.DeleteTagReq
|
||||
resp apistruct.DeleteTagResp
|
||||
reqPb pbOffice.DeleteTagReq
|
||||
respPb *pbOffice.DeleteTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.DeleteTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetTag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SetTagReq
|
||||
resp apistruct.SetTagResp
|
||||
reqPb pbOffice.SetTagReq
|
||||
respPb *pbOffice.SetTagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SetTag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SendMsg2Tag(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.SendMsg2TagReq
|
||||
resp apistruct.SendMsg2TagResp
|
||||
reqPb pbOffice.SendMsg2TagReq
|
||||
respPb *pbOffice.SendMsg2TagResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.SendID = userID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.SendMsg2Tag(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetTagSendLogs(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetTagSendLogsReq
|
||||
resp apistruct.GetTagSendLogsResp
|
||||
reqPb pbOffice.GetTagSendLogsReq
|
||||
respPb *pbOffice.GetTagSendLogsResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetTagSendLogs(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTags failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
if respPb.TagSendLogs != nil {
|
||||
resp.Data.Logs = respPb.TagSendLogs
|
||||
} else {
|
||||
resp.Data.Logs = []*pbOffice.TagSendLog{}
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserTagByID(c *gin.Context) {
|
||||
var (
|
||||
req apistruct.GetUserTagByIDReq
|
||||
resp apistruct.GetUserTagByIDResp
|
||||
reqPb pbOffice.GetUserTagByIDReq
|
||||
respPb *pbOffice.GetUserTagByIDResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
reqPb.UserID = userID
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.TagID = req.TagID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetUserTagByID(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserTagByID failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateTag rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.CommResp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.Tag = respPb.Tag
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
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 CreateOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.CreateOneWorkMomentReq
|
||||
resp apiStruct.CreateOneWorkMomentResp
|
||||
reqPb pbOffice.CreateOneWorkMomentReq
|
||||
respPb *pbOffice.CreateOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
reqPb.WorkMoment.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.CreateOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CreateOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.CommResp = apiStruct.CommResp{
|
||||
ErrCode: respPb.CommonResp.ErrCode,
|
||||
ErrMsg: respPb.CommonResp.ErrMsg,
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.DeleteOneWorkMomentReq
|
||||
resp apiStruct.DeleteOneWorkMomentResp
|
||||
reqPb pbOffice.DeleteOneWorkMomentReq
|
||||
respPb *pbOffice.DeleteOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
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.DeleteOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "DeleteOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func LikeOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.LikeOneWorkMomentReq
|
||||
resp apiStruct.LikeOneWorkMomentResp
|
||||
reqPb pbOffice.LikeOneWorkMomentReq
|
||||
respPb *pbOffice.LikeOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
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.LikeOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "LikeOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func CommentOneWorkMoment(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.CommentOneWorkMomentReq
|
||||
resp apiStruct.CommentOneWorkMomentResp
|
||||
reqPb pbOffice.CommentOneWorkMomentReq
|
||||
respPb *pbOffice.CommentOneWorkMomentResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
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.CommentOneWorkMoment(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CommentOneWorkMoment rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "CommentOneWorkMoment rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetWorkMomentByID(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetWorkMomentByIDReq
|
||||
resp apiStruct.GetWorkMomentByIDResp
|
||||
reqPb pbOffice.GetWorkMomentByIDReq
|
||||
respPb *pbOffice.GetWorkMomentByIDResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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.OperationID = req.OperationID
|
||||
reqPb.OpUserID = userID
|
||||
reqPb.WorkMomentID = req.WorkMomentID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfficeName)
|
||||
client := pbOffice.NewOfficeServiceClient(etcdConn)
|
||||
respPb, err := client.GetWorkMomentByID(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.Data.WorkMoment = &apiStruct.WorkMoment{LikeUserList: []*apiStruct.WorkMomentUser{}, Comments: []*apiStruct.Comment{}, AtUserList: []*apiStruct.WorkMomentUser{}}
|
||||
if err := utils.CopyStructFields(&resp.Data.WorkMoment, respPb.WorkMoment); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserWorkMoments(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetUserWorkMomentsReq
|
||||
resp apiStruct.GetUserWorkMomentsResp
|
||||
reqPb pbOffice.GetUserWorkMomentsReq
|
||||
respPb *pbOffice.GetUserWorkMomentsResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
ok, 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
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
reqPb.OpUserID = opUserID
|
||||
reqPb.UserID = req.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.GetUserWorkMoments(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.Data.WorkMoments = []*apiStruct.WorkMoment{}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
//if err := utils.CopyStructFields(&resp.Data.WorkMoments, respPb.WorkMoments); err != nil {
|
||||
// log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
//}
|
||||
for _, v := range respPb.WorkMoments {
|
||||
workMoment := apiStruct.WorkMoment{
|
||||
WorkMomentID: v.WorkMomentID,
|
||||
UserID: v.UserID,
|
||||
Content: v.Content,
|
||||
FaceURL: v.FaceURL,
|
||||
UserName: v.UserName,
|
||||
CreateTime: v.CreateTime,
|
||||
Comments: make([]*apiStruct.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*apiStruct.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*apiStruct.WorkMomentUser, len(v.AtUserList)),
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
workMoment.Comments[i] = &apiStruct.Comment{
|
||||
UserID: comment.UserID,
|
||||
UserName: comment.UserName,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
}
|
||||
for i, likeUser := range v.LikeUserList {
|
||||
workMoment.LikeUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: likeUser.UserID,
|
||||
UserName: likeUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, atUser := range v.AtUserList {
|
||||
workMoment.AtUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: atUser.UserID,
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserFriendWorkMoments(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetUserFriendWorkMomentsReq
|
||||
resp apiStruct.GetUserFriendWorkMomentsResp
|
||||
reqPb pbOffice.GetUserFriendWorkMomentsReq
|
||||
respPb *pbOffice.GetUserFriendWorkMomentsResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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.OperationID = req.OperationID
|
||||
reqPb.Pagination = &pbCommon.RequestPagination{
|
||||
PageNumber: req.PageNumber,
|
||||
ShowNumber: req.ShowNumber,
|
||||
}
|
||||
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.GetUserFriendWorkMoments(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserFriendWorkMoments rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
//if err := utils.CopyStructFields(&resp.Data.WorkMoments, respPb.WorkMoments); err != nil {
|
||||
// log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
//}
|
||||
resp.Data.WorkMoments = []*apiStruct.WorkMoment{}
|
||||
for _, v := range respPb.WorkMoments {
|
||||
workMoment := apiStruct.WorkMoment{
|
||||
WorkMomentID: v.WorkMomentID,
|
||||
UserID: v.UserID,
|
||||
Content: v.Content,
|
||||
FaceURL: v.FaceURL,
|
||||
UserName: v.UserName,
|
||||
CreateTime: v.CreateTime,
|
||||
Comments: make([]*apiStruct.Comment, len(v.Comments)),
|
||||
LikeUserList: make([]*apiStruct.WorkMomentUser, len(v.LikeUserList)),
|
||||
AtUserList: make([]*apiStruct.WorkMomentUser, len(v.AtUserList)),
|
||||
}
|
||||
for i, comment := range v.Comments {
|
||||
workMoment.Comments[i] = &apiStruct.Comment{
|
||||
UserID: comment.UserID,
|
||||
UserName: comment.UserName,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
}
|
||||
for i, likeUser := range v.LikeUserList {
|
||||
workMoment.LikeUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: likeUser.UserID,
|
||||
UserName: likeUser.UserName,
|
||||
}
|
||||
}
|
||||
for i, atUser := range v.AtUserList {
|
||||
workMoment.AtUserList[i] = &apiStruct.WorkMomentUser{
|
||||
UserID: atUser.UserID,
|
||||
UserName: atUser.UserName,
|
||||
}
|
||||
}
|
||||
resp.Data.WorkMoments = append(resp.Data.WorkMoments, &workMoment)
|
||||
}
|
||||
resp.Data.ShowNumber = respPb.Pagination.ShowNumber
|
||||
resp.Data.CurrentPage = respPb.Pagination.CurrentPage
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetUserWorkMomentsLevel(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.SetUserWorkMomentsLevelReq
|
||||
resp apiStruct.SetUserWorkMomentsLevelResp
|
||||
reqPb pbOffice.SetUserWorkMomentsLevelReq
|
||||
respPb *pbOffice.SetUserWorkMomentsLevelResp
|
||||
)
|
||||
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
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
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
|
||||
}
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
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.SetUserWorkMomentsLevel(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetUserWorkMomentsLevel rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "SetUserWorkMomentsLevel rpc server failed" + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp, respPb.CommonResp); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@@ -0,0 +1,443 @@
|
||||
package organization
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
api "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"
|
||||
rpc "Open_IM/pkg/proto/organization"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CreateDepartment(c *gin.Context) {
|
||||
params := api.CreateDepartmentReq{}
|
||||
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.CreateDepartmentReq{DepartmentInfo: &open_im_sdk.Department{}}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
utils.CopyStructFields(req.DepartmentInfo, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + " " + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.CreateDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc CreateDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.CreateDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Department: RpcResp.DepartmentInfo}
|
||||
apiResp.Data = jsonData.JsonDataOne(RpcResp.DepartmentInfo)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func UpdateDepartment(c *gin.Context) {
|
||||
params := api.UpdateDepartmentReq{}
|
||||
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.UpdateDepartmentReq{DepartmentInfo: &open_im_sdk.Department{}}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
utils.CopyStructFields(req.DepartmentInfo, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.UpdateDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc UpdateDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.UpdateDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func GetSubDepartment(c *gin.Context) {
|
||||
params := api.GetSubDepartmentReq{}
|
||||
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.GetSubDepartmentReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.GetSubDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc GetDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.GetSubDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, DepartmentList: RpcResp.DepartmentList}
|
||||
apiResp.Data = jsonData.JsonDataList(RpcResp.DepartmentList)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func GetAllDepartment(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func DeleteDepartment(c *gin.Context) {
|
||||
params := api.DeleteDepartmentReq{}
|
||||
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.DeleteDepartmentReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.DeleteDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc DeleteDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.DeleteDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func CreateOrganizationUser(c *gin.Context) {
|
||||
params := api.CreateOrganizationUserReq{}
|
||||
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.CreateOrganizationUserReq{OrganizationUser: &open_im_sdk.OrganizationUser{}}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
utils.CopyStructFields(req.OrganizationUser, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.CreateOrganizationUser(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc CreateOrganizationUser failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.CreateOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func UpdateOrganizationUser(c *gin.Context) {
|
||||
params := api.UpdateOrganizationUserReq{}
|
||||
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.UpdateOrganizationUserReq{OrganizationUser: &open_im_sdk.OrganizationUser{}}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
utils.CopyStructFields(req.OrganizationUser, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.UpdateOrganizationUser(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc UpdateOrganizationUser failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.UpdateOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func CreateDepartmentMember(c *gin.Context) {
|
||||
params := api.CreateDepartmentMemberReq{}
|
||||
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.CreateDepartmentMemberReq{DepartmentMember: &open_im_sdk.DepartmentMember{}}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
utils.CopyStructFields(req.DepartmentMember, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.CreateDepartmentMember(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc CreateDepartmentMember failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.CreateDepartmentMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func GetUserInDepartment(c *gin.Context) {
|
||||
params := api.GetUserInDepartmentReq{}
|
||||
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.GetUserInDepartmentReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc GetUserInDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.GetUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, UserInDepartment: RpcResp.UserInDepartment}
|
||||
apiResp.Data = jsonData.JsonDataOne(RpcResp.UserInDepartment)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func UpdateUserInDepartment(c *gin.Context) {
|
||||
params := api.UpdateUserInDepartmentReq{}
|
||||
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.UpdateUserInDepartmentReq{DepartmentMember: &open_im_sdk.DepartmentMember{}}
|
||||
utils.CopyStructFields(req.DepartmentMember, ¶ms)
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.UpdateUserInDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc UpdateUserInDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.UpdateUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func DeleteOrganizationUser(c *gin.Context) {
|
||||
params := api.DeleteOrganizationUserReq{}
|
||||
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.DeleteOrganizationUserReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.DeleteOrganizationUser(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc DeleteOrganizationUser failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.DeleteOrganizationUserResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func GetDepartmentMember(c *gin.Context) {
|
||||
params := api.GetDepartmentMemberReq{}
|
||||
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.GetDepartmentMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.GetDepartmentMember(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc GetDepartmentMember failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.GetDepartmentMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, UserInDepartmentList: RpcResp.UserDepartmentMemberList}
|
||||
apiResp.Data = jsonData.JsonDataList(RpcResp.UserDepartmentMemberList)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
|
||||
func DeleteUserInDepartment(c *gin.Context) {
|
||||
params := api.DeleteUserInDepartmentReq{}
|
||||
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.DeleteUserInDepartmentReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
err, opUserID := token_verify.ParseTokenGetUserID(c.Request.Header.Get("token"), req.OperationID)
|
||||
req.OpUserID = opUserID
|
||||
if err != nil {
|
||||
errMsg := "ParseTokenGetUserID failed " + err.Error() + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api args ", req.String(), "params", params)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOrganizationName)
|
||||
client := rpc.NewOrganizationClient(etcdConn)
|
||||
RpcResp, err := client.DeleteUserInDepartment(context.Background(), req)
|
||||
if err != nil {
|
||||
errMsg := "rpc DeleteUserInDepartment failed " + err.Error() + req.String()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
apiResp := api.DeleteUserInDepartmentResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "api return ", apiResp)
|
||||
c.JSON(http.StatusOK, apiResp)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/policy"
|
||||
url2 "net/url"
|
||||
)
|
||||
|
||||
@@ -15,18 +16,28 @@ var (
|
||||
)
|
||||
|
||||
func MinioInit() {
|
||||
log.NewInfo("", utils.GetSelfFuncName())
|
||||
minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio config: ", config.Config.Credential.Minio)
|
||||
var initUrl string
|
||||
if config.Config.Credential.Minio.EndpointInnerEnable {
|
||||
initUrl = config.Config.Credential.Minio.EndpointInner
|
||||
} else {
|
||||
initUrl = config.Config.Credential.Minio.Endpoint
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "use initUrl: ", initUrl)
|
||||
minioUrl, err := url2.Parse(initUrl)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "Parse ok ", config.Config.Credential.Minio)
|
||||
minioClient, err = minio.New(minioUrl.Host, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
|
||||
Secure: false,
|
||||
})
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "new ok ", config.Config.Credential.Minio)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "init minio client failed", err.Error())
|
||||
return
|
||||
}
|
||||
opt := minio.MakeBucketOptions{
|
||||
@@ -35,23 +46,23 @@ func MinioInit() {
|
||||
}
|
||||
err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
|
||||
if err != nil {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "MakeBucket failed ", err.Error())
|
||||
exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
|
||||
if err == nil && exists {
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket)
|
||||
log.NewWarn(operationID, utils.GetSelfFuncName(), "We already own ", config.Config.Credential.Minio.Bucket)
|
||||
} else {
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), err.Error())
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "create bucket failed and bucket not exists")
|
||||
return
|
||||
}
|
||||
}
|
||||
// 自动化桶public的代码
|
||||
//err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
|
||||
//if err != nil {
|
||||
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||
// return
|
||||
//}
|
||||
log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success")
|
||||
err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
|
||||
if err != nil {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "minio create and set policy success")
|
||||
}
|
||||
|
||||
@@ -33,8 +33,15 @@ func MinioUploadFile(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
switch req.FileType {
|
||||
// videoType upload snapShot
|
||||
case constant.VideoType:
|
||||
snapShotFile, err := c.FormFile("snapShot")
|
||||
if err != nil {
|
||||
@@ -74,7 +81,7 @@ func MinioUploadFile(c *gin.Context) {
|
||||
_, err = minioClient.PutObject(context.Background(), config.Config.Credential.Minio.Bucket, newName, fileObj, file.Size, minio.PutObjectOptions{ContentType: newType})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "open file error")
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "invalid file path" + err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "invalid file path" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.NewName = newName
|
||||
@@ -104,7 +111,13 @@ func MinioStorageCredential(c *gin.Context) {
|
||||
stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID
|
||||
stsOpts.SecretKey = config.Config.Credential.Minio.SecretAccessKey
|
||||
stsOpts.DurationSeconds = constant.MinioDurationTimes
|
||||
li, err := cr.NewSTSAssumeRole(config.Config.Credential.Minio.Endpoint, stsOpts)
|
||||
var endpoint string
|
||||
if config.Config.Credential.Minio.EndpointInnerEnable {
|
||||
endpoint = config.Config.Credential.Minio.EndpointInner
|
||||
} else {
|
||||
endpoint = config.Config.Credential.Minio.Endpoint
|
||||
}
|
||||
li, err := cr.NewSTSAssumeRole(endpoint, stsOpts)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "NewSTSAssumeRole failed", err.Error(), stsOpts, config.Config.Credential.Minio.Endpoint)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
|
||||
@@ -4,9 +4,12 @@ import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
cacheRpc "Open_IM/pkg/proto/cache"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
rpc "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -16,6 +19,214 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUsersInfoFromCache(c *gin.Context) {
|
||||
params := api.GetUsersInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserInfoReq{}
|
||||
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(params.OperationID, "GetUserInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
||||
for _, v := range RpcResp.UserInfoList {
|
||||
publicUserInfoList = append(publicUserInfoList,
|
||||
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex})
|
||||
}
|
||||
|
||||
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//func GetUsersInfoFromCache(c *gin.Context) {
|
||||
// params := api.GetUsersInfoReq{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError("0", "BindJSON failed ", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// getUserInfoReq := &rpc.GetUserInfoReq{}
|
||||
// getUserInfoReq.OperationID = params.OperationID
|
||||
// var ok bool
|
||||
// ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID)
|
||||
// if !ok {
|
||||
// log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String())
|
||||
// reqCacheGetUserInfo := &cacheRpc.GetUserInfoFromCacheReq{}
|
||||
// utils.CopyStructFields(reqCacheGetUserInfo, ¶ms)
|
||||
// var userInfoList []*open_im_sdk.UserInfo
|
||||
// var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
// cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
// cacheResp, err := cacheClient.GetUserInfoFromCache(context.Background(), reqCacheGetUserInfo)
|
||||
// if err != nil {
|
||||
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// if cacheResp.CommonResp.ErrCode != 0 {
|
||||
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
||||
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
||||
// resp.Data = []map[string]interface{}{}
|
||||
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String())
|
||||
// userInfoList = cacheResp.UserInfoList
|
||||
// var needCacheUserIDList []string
|
||||
// for _, userID := range reqCacheGetUserInfo.UserIDList {
|
||||
// isGetUserInfoFromCache := false
|
||||
// for _, cacheUser := range userInfoList {
|
||||
// if cacheUser.UserID == userID {
|
||||
// isGetUserInfoFromCache = true
|
||||
// }
|
||||
// }
|
||||
// if !isGetUserInfoFromCache {
|
||||
// needCacheUserIDList = append(needCacheUserIDList, userID)
|
||||
// }
|
||||
// }
|
||||
// if len(needCacheUserIDList) == 0 {
|
||||
// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success")
|
||||
// for _, v := range userInfoList {
|
||||
// publicUserInfoList = append(publicUserInfoList,
|
||||
// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex})
|
||||
// }
|
||||
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList)
|
||||
// getUserInfoReq.UserIDList = needCacheUserIDList
|
||||
// etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := rpc.NewUserClient(etcdConn)
|
||||
// rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq)
|
||||
// if err != nil {
|
||||
// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// if rpcResp.CommonResp.ErrCode != 0 {
|
||||
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
||||
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
||||
// resp.Data = []map[string]interface{}{}
|
||||
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// return
|
||||
// }
|
||||
// userInfoList = append(userInfoList, rpcResp.UserInfoList...)
|
||||
// cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoToCacheReq{
|
||||
// UserInfoList: rpcResp.UserInfoList,
|
||||
// OperationID: getUserInfoReq.OperationID,
|
||||
// }
|
||||
// _, err = cacheClient.UpdateUserInfoToCache(context.Background(), cacheUpdateUserInfoReq)
|
||||
// if err != nil {
|
||||
// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// userInfoList = rpcResp.UserInfoList
|
||||
// for _, v := range userInfoList {
|
||||
// publicUserInfoList = append(publicUserInfoList,
|
||||
// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex})
|
||||
// }
|
||||
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||
// resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
|
||||
func GetFriendIDListFromCache(c *gin.Context) {
|
||||
var (
|
||||
req api.GetFriendIDListFromCacheReq
|
||||
resp api.GetFriendIDListFromCacheResp
|
||||
reqPb cacheRpc.GetFriendIDListFromCacheReq
|
||||
respPb *cacheRpc.GetFriendIDListFromCacheResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
var ok bool
|
||||
ok, reqPb.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
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
client := cacheRpc.NewCacheClient(etcdConn)
|
||||
respPb, err := client.GetFriendIDListFromCache(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.UserIDList = respPb.UserIDList
|
||||
resp.CommResp = api.CommResp{ErrMsg: respPb.CommonResp.ErrMsg, ErrCode: respPb.CommonResp.ErrCode}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetBlackIDListFromCache(c *gin.Context) {
|
||||
var (
|
||||
req api.GetBlackIDListFromCacheReq
|
||||
resp api.GetBlackIDListFromCacheResp
|
||||
reqPb cacheRpc.GetBlackIDListFromCacheReq
|
||||
respPb *cacheRpc.GetBlackIDListFromCacheResp
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
reqPb.OperationID = req.OperationID
|
||||
var ok bool
|
||||
ok, reqPb.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
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
client := cacheRpc.NewCacheClient(etcdConn)
|
||||
respPb, err := client.GetBlackIDListFromCache(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.UserIDList = respPb.UserIDList
|
||||
resp.CommResp = api.CommResp{ErrMsg: respPb.CommonResp.ErrMsg, ErrCode: respPb.CommonResp.ErrCode}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUsersInfo(c *gin.Context) {
|
||||
params := api.GetUsersInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
@@ -127,3 +338,70 @@ func GetSelfUserInfo(c *gin.Context) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := api.GetUsersOnlineStatusReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbRelay.GetUsersOnlineStatusReq{}
|
||||
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
|
||||
}
|
||||
if len(config.Config.Manager.AppManagerUid) == 0 {
|
||||
log.NewError(req.OperationID, "Manager == 0")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "Manager == 0"})
|
||||
return
|
||||
}
|
||||
req.OpUserID = config.Config.Manager.AppManagerUid[0]
|
||||
|
||||
log.NewInfo(params.OperationID, "GetUsersOnlineStatus args ", req.String())
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
continue
|
||||
} else {
|
||||
if reply.ErrCode == 0 {
|
||||
wsResult = append(wsResult, reply.SuccessResult...)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewInfo(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
//Online data merge of each node
|
||||
for _, v1 := range params.UserIDList {
|
||||
flag = false
|
||||
temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
for _, v2 := range wsResult {
|
||||
if v2.UserID == v1 {
|
||||
flag = true
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OnlineStatus
|
||||
temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
}
|
||||
|
||||
}
|
||||
if !flag {
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OfflineStatus
|
||||
}
|
||||
respResult = append(respResult, temp)
|
||||
}
|
||||
resp := api.GetUsersOnlineStatusResp{CommResp: api.CommResp{ErrCode: 0, ErrMsg: ""}, SuccessResult: respResult}
|
||||
if len(respResult) == 0 {
|
||||
resp.SuccessResult = []*pbRelay.GetUsersOnlineStatusResp_SuccessResult{}
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func GetGroupById(c *gin.Context) {
|
||||
resp.ProfilePhoto = respPb.CMSGroup.GroupInfo.FaceURL
|
||||
resp.GroupMasterName = respPb.CMSGroup.GroupMasterName
|
||||
resp.GroupMasterId = respPb.CMSGroup.GroupMasterId
|
||||
resp.IsBanChat = constant.GroupIsBanChat(respPb.CMSGroup.GroupInfo.Status)
|
||||
openIMHttp.RespHttp200(c, constant.OK, resp)
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ func GetGroups(c *gin.Context) {
|
||||
GroupMasterName: v.GroupMasterName,
|
||||
GroupMasterId: v.GroupMasterId,
|
||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||
IsBanChat: false,
|
||||
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||
IsBanPrivateChat: false,
|
||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||
})
|
||||
@@ -114,7 +115,7 @@ func GetGroupByName(c *gin.Context) {
|
||||
GroupMasterName: v.GroupMasterName,
|
||||
GroupMasterId: v.GroupMasterId,
|
||||
CreateTime: (utils.UnixSecondToTime(int64(v.GroupInfo.CreateTime))).String(),
|
||||
IsBanChat: false,
|
||||
IsBanChat: constant.GroupIsBanChat(v.GroupInfo.Status),
|
||||
IsBanPrivateChat: false,
|
||||
ProfilePhoto: v.GroupInfo.FaceURL,
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func NewGinRouter() *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
baseRouter := gin.Default()
|
||||
router := baseRouter.Group("/api")
|
||||
router := baseRouter.Group("/cms")
|
||||
router.Use(middleware.CorsHandler())
|
||||
adminRouterGroup := router.Group("/admin")
|
||||
{
|
||||
|
||||
@@ -42,11 +42,11 @@ func Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if r.Password != params.Password {
|
||||
log.NewError(params.OperationID, "password err", params.Password, account, r.Password, r.Account)
|
||||
log.NewError(params.OperationID, "password err", params.Password, account, r.Password, r.Account)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "password err"})
|
||||
return
|
||||
}
|
||||
url := fmt.Sprintf("http://%s:10000/auth/user_token", utils.ServerIP)
|
||||
url := fmt.Sprintf("http://%s:%d/auth/user_token", utils.ServerIP, config.Config.Api.GinPort[0])
|
||||
openIMGetUserToken := api.UserTokenReq{}
|
||||
openIMGetUserToken.OperationID = params.OperationID
|
||||
openIMGetUserToken.Platform = params.Platform
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
type ParamsSetPassword struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
Password string `json:"password"`
|
||||
VerificationCode string `json:"verificationCode"`
|
||||
@@ -38,6 +39,9 @@ func SetPassword(c *gin.Context) {
|
||||
} else {
|
||||
account = params.PhoneNumber
|
||||
}
|
||||
if params.Name == "" {
|
||||
params.Name = account
|
||||
}
|
||||
if params.VerificationCode != config.Config.Demo.SuperCode {
|
||||
accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
@@ -49,12 +53,12 @@ func SetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
url := fmt.Sprintf("http://%s:10000/auth/user_register", utils.ServerIP)
|
||||
url := fmt.Sprintf("http://%s:%d/auth/user_register", utils.ServerIP, config.Config.Api.GinPort[0])
|
||||
openIMRegisterReq := api.UserRegisterReq{}
|
||||
openIMRegisterReq.OperationID = params.OperationID
|
||||
openIMRegisterReq.Platform = params.Platform
|
||||
openIMRegisterReq.UserID = account
|
||||
openIMRegisterReq.Nickname = account
|
||||
openIMRegisterReq.Nickname = params.Name
|
||||
openIMRegisterReq.Secret = config.Config.Secret
|
||||
openIMRegisterResp := api.UserRegisterResp{}
|
||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||
@@ -69,7 +73,7 @@ func SetPassword(c *gin.Context) {
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: "+openIMRegisterResp.ErrMsg})
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
||||
|
||||
@@ -2,7 +2,7 @@ package gate
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
||||
"Open_IM/pkg/statistics"
|
||||
"fmt"
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -20,7 +20,7 @@ var (
|
||||
|
||||
func Init(rpcPort, wsPort int) {
|
||||
//log initialization
|
||||
log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName)
|
||||
|
||||
rwLock = new(sync.RWMutex)
|
||||
validate = validator.New()
|
||||
statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300)
|
||||
|
||||
@@ -6,13 +6,17 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/gorilla/websocket"
|
||||
"google.golang.org/grpc"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -200,38 +204,61 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||
nReply := new(pbChat.SendMsgResp)
|
||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg)
|
||||
if isPass {
|
||||
isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
||||
if isPass2 {
|
||||
signalResp := pbRtc.SignalResp{}
|
||||
//isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq), m.OperationID)
|
||||
connGrpc, err := grpc.Dial(config.Config.Rtc.Address+":"+strconv.Itoa(config.Config.Rtc.Port), grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), "grpc.Dial failed", err.Error())
|
||||
ws.sendSignalMsgResp(conn, 204, "create grpc failed"+err.Error(), m, nil)
|
||||
return
|
||||
}
|
||||
rtcClient := pbRtc.NewRtcServiceClient(connGrpc)
|
||||
req := &pbRtc.SignalMessageAssembleReq{
|
||||
SignalReq: pData.(*pbRtc.SignalReq),
|
||||
OperationID: m.OperationID,
|
||||
}
|
||||
respPb, err := rtcClient.SignalMessageAssemble(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), "SignalMessageAssemble", err.Error(), config.Config.Rtc.Address+":"+strconv.Itoa(config.Config.Rtc.Port))
|
||||
ws.sendSignalMsgResp(conn, 204, "grpc SignalMessageAssemble failed: "+err.Error(), m, &signalResp)
|
||||
return
|
||||
}
|
||||
signalResp.Payload = respPb.SignalResp.Payload
|
||||
msgData := sdk_ws.MsgData{}
|
||||
utils.CopyStructFields(&msgData, respPb.MsgData)
|
||||
log.NewInfo(m.OperationID, utils.GetSelfFuncName(), respPb.String())
|
||||
if respPb.IsPass {
|
||||
pbData := pbChat.SendMsgReq{
|
||||
Token: m.Token,
|
||||
OperationID: m.OperationID,
|
||||
MsgData: msgData,
|
||||
MsgData: &msgData,
|
||||
}
|
||||
log.NewInfo(m.OperationID, utils.GetSelfFuncName(), "pbData: ", pbData)
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, msgData)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, "rpc sendMsg err", err.Error())
|
||||
log.NewError(pbData.OperationID, utils.GetSelfFuncName(), "rpc sendMsg err", err.Error())
|
||||
nReply.ErrCode = 200
|
||||
nReply.ErrMsg = err.Error()
|
||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, signalResp)
|
||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, &signalResp)
|
||||
} else {
|
||||
log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String())
|
||||
ws.sendSignalMsgResp(conn, 0, "", m, signalResp)
|
||||
ws.sendSignalMsgResp(conn, 0, "", m, &signalResp)
|
||||
}
|
||||
} else {
|
||||
log.NewError(m.OperationID, isPass2, errCode2, errMsg2)
|
||||
ws.sendSignalMsgResp(conn, errCode2, errMsg2, m, signalResp)
|
||||
log.NewError(m.OperationID, utils.GetSelfFuncName(), respPb.IsPass, respPb.CommonResp.ErrCode, respPb.CommonResp.ErrMsg)
|
||||
ws.sendSignalMsgResp(conn, respPb.CommonResp.ErrCode, respPb.CommonResp.ErrMsg, m, &signalResp)
|
||||
}
|
||||
} else {
|
||||
ws.sendSignalMsgResp(conn, errCode, errMsg, m, nil)
|
||||
}
|
||||
|
||||
}
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, errCode int32, errMsg string, m *Req, pb *sdk_ws.SignalResp) {
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, errCode int32, errMsg string, m *Req, pb *pbRtc.SignalResp) {
|
||||
// := make(map[string]interface{})
|
||||
|
||||
log.Debug(m.OperationID, "SignalMsgResp is", pb.String())
|
||||
b, _ := proto.Marshal(pb)
|
||||
mReply := Resp{
|
||||
ReqIdentifier: m.ReqIdentifier,
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
package open_im_media
|
||||
|
||||
import (
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/jinzhu/copier"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
// Address gRPC服务地址
|
||||
Address = "127.0.0.1:11300"
|
||||
@@ -23,35 +14,35 @@ func NewMedia() *Media {
|
||||
return &Media{}
|
||||
}
|
||||
|
||||
func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
||||
var newData pbRtc.ParticipantMetaData
|
||||
copier.Copy(&newData, data)
|
||||
conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
defer conn.Close()
|
||||
c := pbRtc.NewRtcServiceClient(conn)
|
||||
req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
||||
resp, err := c.GetJoinToken(context.Background(), req)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if resp.CommonResp.ErrCode != 0 {
|
||||
return "", "", errors.New(resp.CommonResp.ErrMsg)
|
||||
}
|
||||
return resp.Jwt, resp.LiveURL, nil
|
||||
//at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
||||
//grant := &auth.VideoGrant{
|
||||
// RoomJoin: true,
|
||||
// Room: room,
|
||||
//}
|
||||
//at.AddGrant(grant).
|
||||
// SetIdentity(identity).
|
||||
// SetValidFor(time.Hour)
|
||||
//
|
||||
//return at.ToJWT()
|
||||
}
|
||||
//func (m *Media) GetJoinToken(room, identity string, operationID string, data *open_im_sdk.ParticipantMetaData) (string, string, error) {
|
||||
// var newData pbRtc.ParticipantMetaData
|
||||
// copier.Copy(&newData, data)
|
||||
// conn, err := grpc.Dial(Address, grpc.WithInsecure())
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// defer conn.Close()
|
||||
// c := pbRtc.NewRtcServiceClient(conn)
|
||||
// req := &pbRtc.GetJoinTokenReq{Room: room, OperationID: operationID, Identity: identity, MetaData: &newData}
|
||||
// resp, err := c.GetJoinToken(context.Background(), req)
|
||||
// if err != nil {
|
||||
// return "", "", err
|
||||
// }
|
||||
// if resp.CommonResp.ErrCode != 0 {
|
||||
// return "", "", errors.New(resp.CommonResp.ErrMsg)
|
||||
// }
|
||||
// return resp.Jwt, resp.LiveURL, nil
|
||||
// //at := auth.NewAccessToken(m.ApiKey, m.ApiSecret)
|
||||
// //grant := &auth.VideoGrant{
|
||||
// // RoomJoin: true,
|
||||
// // Room: room,
|
||||
// //}
|
||||
// //at.AddGrant(grant).
|
||||
// // SetIdentity(identity).
|
||||
// // SetValidFor(time.Hour)
|
||||
// //
|
||||
// //return at.ToJWT()
|
||||
//}
|
||||
|
||||
func init() {
|
||||
//roomClient = lksdk.NewRoomServiceClient(MediaAddress, ApiKey, ApiSecret)
|
||||
|
||||
@@ -101,7 +101,7 @@ func (r *RPCServer) OnlinePushMsg(_ context.Context, in *pbRelay.OnlinePushMsgRe
|
||||
}
|
||||
func (r *RPCServer) GetUsersOnlineStatus(_ context.Context, req *pbRelay.GetUsersOnlineStatusReq) (*pbRelay.GetUsersOnlineStatusResp, error) {
|
||||
log.NewInfo(req.OperationID, "rpc GetUsersOnlineStatus arrived server", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "no permission GetUsersOnlineStatus ", req.OpUserID)
|
||||
return &pbRelay.GetUsersOnlineStatusResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
package gate
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_gateway/gate/open_im_media"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbRtc "Open_IM/pkg/proto/rtc"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -74,7 +72,7 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
}
|
||||
return true, 0, "", data
|
||||
case constant.WSSendSignalMsg:
|
||||
data := open_im_sdk.SignalReq{}
|
||||
data := pbRtc.SignalReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||
return false, 203, err.Error(), nil
|
||||
@@ -117,138 +115,139 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
|
||||
}
|
||||
|
||||
func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq, operationID string) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) {
|
||||
var msg open_im_sdk.MsgData
|
||||
var resp open_im_sdk.SignalResp
|
||||
media := open_im_media.NewMedia()
|
||||
msg.MsgFrom = constant.UserMsgType
|
||||
msg.ContentType = constant.SignalingNotification
|
||||
reqData, e := proto.Marshal(s)
|
||||
if e != nil {
|
||||
return false, 201, e.Error(), nil, nil
|
||||
}
|
||||
msg.Content = reqData
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
options := make(map[string]bool, 6)
|
||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||
msg.Options = options
|
||||
switch payload := s.Payload.(type) {
|
||||
case *open_im_sdk.SignalReq_Invite:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
||||
if err2 != nil {
|
||||
return false, 202, err2.Error(), nil, nil
|
||||
}
|
||||
invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||
Token: token,
|
||||
RoomID: payload.Invite.Invitation.RoomID,
|
||||
LiveURL: liveURL,
|
||||
}}
|
||||
resp.Payload = &invite
|
||||
msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||
msg.SessionType = payload.Invite.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||
msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||
if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||
} else {
|
||||
return false, 203, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_InviteInGroup:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
||||
if err2 != nil {
|
||||
return false, 204, err2.Error(), nil, nil
|
||||
}
|
||||
inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||
RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||
Token: token,
|
||||
LiveURL: liveURL,
|
||||
}}
|
||||
resp.Payload = &inviteGroup
|
||||
msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||
msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||
msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||
if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||
} else {
|
||||
return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_Cancel:
|
||||
cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
||||
resp.Payload = &cancel
|
||||
msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
||||
msg.SendID = payload.Cancel.Invitation.InviterUserID
|
||||
msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
||||
msg.SessionType = payload.Cancel.Invitation.SessionType
|
||||
if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Cancel.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Cancel.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_Accept:
|
||||
token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
||||
if err2 != nil {
|
||||
return false, 207, err2.Error(), nil, nil
|
||||
}
|
||||
accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
||||
Token: token,
|
||||
LiveURL: liveURL,
|
||||
RoomID: payload.Accept.Invitation.RoomID,
|
||||
}}
|
||||
resp.Payload = &accept
|
||||
msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
||||
msg.SendID = payload.Accept.OpUserID
|
||||
msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
||||
msg.SessionType = payload.Accept.Invitation.SessionType
|
||||
if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Accept.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Accept.Invitation.InviterUserID
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Accept.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_HungUp:
|
||||
case *open_im_sdk.SignalReq_Reject:
|
||||
reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
||||
resp.Payload = &reject
|
||||
msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
||||
msg.SendID = payload.Reject.OpUserID
|
||||
msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
||||
msg.SessionType = payload.Reject.Invitation.SessionType
|
||||
if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
||||
switch payload.Reject.Invitation.SessionType {
|
||||
case constant.SingleChatType:
|
||||
msg.RecvID = payload.Reject.Invitation.InviterUserID
|
||||
case constant.GroupChatType:
|
||||
msg.GroupID = payload.Reject.Invitation.GroupID
|
||||
}
|
||||
} else {
|
||||
return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
}
|
||||
return false, 210, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
//func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq, operationID string) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) {
|
||||
// var msg open_im_sdk.MsgData
|
||||
// var resp open_im_sdk.SignalResp
|
||||
// media := open_im_media.NewMedia()
|
||||
// msg.MsgFrom = constant.UserMsgType
|
||||
// msg.ContentType = constant.SignalingNotification
|
||||
// reqData, e := proto.Marshal(s)
|
||||
// if e != nil {
|
||||
// return false, 201, e.Error(), nil, nil
|
||||
// }
|
||||
// msg.Content = reqData
|
||||
// msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
// options := make(map[string]bool, 6)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsSenderSync, true)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||
// msg.Options = options
|
||||
// switch payload := s.Payload.(type) {
|
||||
// case *open_im_sdk.SignalReq_Invite:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID, operationID, payload.Invite.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 202, err2.Error(), nil, nil
|
||||
// }
|
||||
// invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||
// Token: token,
|
||||
// RoomID: payload.Invite.Invitation.RoomID,
|
||||
// LiveURL: liveURL,
|
||||
// }}
|
||||
// resp.Payload = &invite
|
||||
// msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Invite.Invitation.SessionType
|
||||
// msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||
// msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||
// if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||
// msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||
// } else {
|
||||
// return false, 203, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_InviteInGroup:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID, operationID, payload.InviteInGroup.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 204, err2.Error(), nil, nil
|
||||
// }
|
||||
// inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||
// RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||
// Token: token,
|
||||
// LiveURL: liveURL,
|
||||
// }}
|
||||
// resp.Payload = &inviteGroup
|
||||
// msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||
// msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||
// msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||
// msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||
// if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||
// msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||
// } else {
|
||||
// return false, 205, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||
//
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_Cancel:
|
||||
// cancel := open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{}}
|
||||
// resp.Payload = &cancel
|
||||
// msg.OfflinePushInfo = payload.Cancel.OfflinePushInfo
|
||||
// msg.SendID = payload.Cancel.Invitation.InviterUserID
|
||||
// msg.SenderPlatformID = payload.Cancel.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Cancel.Invitation.SessionType
|
||||
// if len(payload.Cancel.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Cancel.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Cancel.Invitation.InviteeUserIDList[0]
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Cancel.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 206, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Cancel.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_Accept:
|
||||
// token, liveURL, err2 := media.GetJoinToken(payload.Accept.Invitation.RoomID, payload.Accept.OpUserID, operationID, payload.Accept.Participant)
|
||||
// if err2 != nil {
|
||||
// return false, 207, err2.Error(), nil, nil
|
||||
// }
|
||||
// accept := open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalAcceptReply{
|
||||
// Token: token,
|
||||
// LiveURL: liveURL,
|
||||
// RoomID: payload.Accept.Invitation.RoomID,
|
||||
// }}
|
||||
// resp.Payload = &accept
|
||||
// msg.OfflinePushInfo = payload.Accept.OfflinePushInfo
|
||||
// msg.SendID = payload.Accept.OpUserID
|
||||
// msg.SenderPlatformID = payload.Accept.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Accept.Invitation.SessionType
|
||||
// if len(payload.Accept.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Accept.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Accept.Invitation.InviterUserID
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Accept.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 208, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Accept.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// case *open_im_sdk.SignalReq_HungUp:
|
||||
// case *open_im_sdk.SignalReq_Reject:
|
||||
// reject := open_im_sdk.SignalResp_Reject{&open_im_sdk.SignalRejectReply{}}
|
||||
// resp.Payload = &reject
|
||||
// msg.OfflinePushInfo = payload.Reject.OfflinePushInfo
|
||||
// msg.SendID = payload.Reject.OpUserID
|
||||
// msg.SenderPlatformID = payload.Reject.Invitation.PlatformID
|
||||
// msg.SessionType = payload.Reject.Invitation.SessionType
|
||||
// if len(payload.Reject.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Reject.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Reject.Invitation.InviterUserID
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Reject.Invitation.GroupID
|
||||
// }
|
||||
// } else {
|
||||
// return false, 209, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Reject.OpUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
// }
|
||||
// return false, 210, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
//}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
conn, err := ws.wsUpGrader.Upgrade(w, r, nil) //Conn is obtained through the upgraded escalator
|
||||
if err != nil {
|
||||
log.ErrorByKv("upgrade http conn err", "", "err", err)
|
||||
log.ErrorByKv("upgrade http conn err", "", "err", err, query)
|
||||
return
|
||||
} else {
|
||||
//Connection mapping relationship,
|
||||
@@ -196,6 +196,7 @@ func (ws *WServer) addUserConn(uid string, platformID int32, conn *UserConn, tok
|
||||
func (ws *WServer) delUserConn(conn *UserConn) {
|
||||
rwLock.Lock()
|
||||
defer rwLock.Unlock()
|
||||
operationID := utils.OperationIDGenerator()
|
||||
var platform, uid string
|
||||
if oldStringMap, ok := ws.wsConnToUser[conn]; ok {
|
||||
for k, v := range oldStringMap {
|
||||
@@ -212,9 +213,9 @@ func (ws *WServer) delUserConn(conn *UserConn) {
|
||||
for _, v := range ws.wsUserToConn {
|
||||
count = count + len(v)
|
||||
}
|
||||
log.WarnByKv("WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "disconnection_uid", uid, "disconnection_platform", platform, "online_user_num", len(ws.wsUserToConn), "online_conn_num", count)
|
||||
log.NewWarn(operationID, "WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "disconnection_uid", uid, "disconnection_platform", platform, "online_user_num", len(ws.wsUserToConn), "online_conn_num", count)
|
||||
} else {
|
||||
log.WarnByKv("WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "disconnection_uid", uid, "disconnection_platform", platform, "online_user_num", len(ws.wsUserToConn))
|
||||
log.NewWarn(operationID, "WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "disconnection_uid", uid, "disconnection_platform", platform, "online_user_num", len(ws.wsUserToConn))
|
||||
}
|
||||
userCount = uint64(len(ws.wsUserToConn))
|
||||
delete(ws.wsConnToUser, conn)
|
||||
@@ -222,8 +223,7 @@ func (ws *WServer) delUserConn(conn *UserConn) {
|
||||
}
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
log.ErrorByKv("close err", "", "uid", uid, "platform", platform)
|
||||
|
||||
log.Error(operationID, " close err", "", "uid", uid, "platform", platform)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -262,20 +262,26 @@ func (ws *WServer) getUserUid(conn *UserConn) (uid, platform string) {
|
||||
func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request) bool {
|
||||
status := http.StatusUnauthorized
|
||||
query := r.URL.Query()
|
||||
operationID := ""
|
||||
if len(query["operationID"]) != 0 {
|
||||
operationID = query["operationID"][0]
|
||||
}
|
||||
if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 {
|
||||
if ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0]); !ok {
|
||||
e := err.(*constant.ErrInfo)
|
||||
log.ErrorByKv("Token verify failed", "", "query", query, msg)
|
||||
if ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0], operationID); !ok {
|
||||
// e := err.(*constant.ErrInfo)
|
||||
log.Error(operationID, "Token verify failed ", "query ", query, msg, err.Error())
|
||||
w.Header().Set("Sec-Websocket-Version", "13")
|
||||
http.Error(w, e.ErrMsg, int(e.ErrCode))
|
||||
w.Header().Set("ws_err_msg", err.Error())
|
||||
http.Error(w, err.Error(), status)
|
||||
return false
|
||||
} else {
|
||||
log.InfoByKv("Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0])
|
||||
log.Info(operationID, "Connection Authentication Success", "", "token", query["token"][0], "userID", query["sendID"][0])
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
log.ErrorByKv("Args err", "", "query", query)
|
||||
log.Error(operationID, "Args err", "query", query)
|
||||
w.Header().Set("Sec-Websocket-Version", "13")
|
||||
w.Header().Set("ws_err_msg", "args err, need token, sendID, platformID")
|
||||
http.Error(w, http.StatusText(status), status)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type fcb func(msg []byte, msgKey string)
|
||||
@@ -38,7 +39,7 @@ func (mc *HistoryConsumerHandler) Init() {
|
||||
}
|
||||
|
||||
func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) {
|
||||
time := utils.GetCurrentTimestampByNano()
|
||||
now := time.Now()
|
||||
msgFromMQ := pbMsg.MsgDataToMQ{}
|
||||
err := proto.Unmarshal(msg, &msgFromMQ)
|
||||
if err != nil {
|
||||
@@ -62,13 +63,13 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
|
||||
return
|
||||
}
|
||||
mc.singleMsgCount++
|
||||
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", time.Since(now))
|
||||
}
|
||||
if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID {
|
||||
} else {
|
||||
go sendMessageToPush(&msgFromMQ, msgKey)
|
||||
}
|
||||
log.NewDebug(operationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||
log.NewDebug(operationID, "saveUserChat cost time ", time.Since(now))
|
||||
case constant.GroupChatType:
|
||||
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = GroupChatType", isHistory, isPersist)
|
||||
if isHistory {
|
||||
@@ -80,6 +81,22 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
|
||||
mc.groupMsgCount++
|
||||
}
|
||||
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
|
||||
case constant.NotificationChatType:
|
||||
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = NotificationChatType", isHistory, isPersist)
|
||||
if isHistory {
|
||||
err := saveUserChat(msgKey, &msgFromMQ)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
|
||||
return
|
||||
}
|
||||
mc.singleMsgCount++
|
||||
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", time.Since(now))
|
||||
}
|
||||
if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID {
|
||||
} else {
|
||||
go sendMessageToPush(&msgFromMQ, msgKey)
|
||||
}
|
||||
log.NewDebug(operationID, "saveUserChat cost time ", time.Since(now))
|
||||
default:
|
||||
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ package logic
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -13,13 +13,17 @@ var (
|
||||
)
|
||||
|
||||
func Init() {
|
||||
log.NewPrivateLog(config.Config.ModuleName.MsgTransferName)
|
||||
|
||||
persistentCH.Init()
|
||||
historyCH.Init()
|
||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
||||
}
|
||||
func Run() {
|
||||
//register mysqlConsumerHandler to
|
||||
go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH)
|
||||
if config.Config.ChatPersistenceMysql {
|
||||
go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH)
|
||||
} else {
|
||||
fmt.Println("not start mysql consumer")
|
||||
}
|
||||
go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH)
|
||||
}
|
||||
|
||||
@@ -34,26 +34,31 @@ func (pc *PersistentConsumerHandler) Init() {
|
||||
|
||||
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
|
||||
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
||||
var tag bool
|
||||
msgFromMQ := pbMsg.MsgDataToMQ{}
|
||||
err := proto.Unmarshal(msg, &msgFromMQ)
|
||||
if err != nil {
|
||||
log.ErrorByKv("msg_transfer Unmarshal msg err", "", "msg", string(msg), "err", err.Error())
|
||||
log.NewError(msgFromMQ.OperationID, "msg_transfer Unmarshal msg err", "msg", string(msg), "err", err.Error())
|
||||
return
|
||||
}
|
||||
//Control whether to store history messages (mysql)
|
||||
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
||||
//Only process receiver data
|
||||
if isPersist {
|
||||
if msgKey == msgFromMQ.MsgData.RecvID && msgFromMQ.MsgData.SessionType == constant.SingleChatType {
|
||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
||||
return
|
||||
switch msgFromMQ.MsgData.SessionType {
|
||||
case constant.SingleChatType, constant.NotificationChatType:
|
||||
if msgKey == msgFromMQ.MsgData.RecvID {
|
||||
tag = true
|
||||
}
|
||||
} else if msgFromMQ.MsgData.SessionType == constant.GroupChatType && msgKey == msgFromMQ.MsgData.SendID {
|
||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
||||
case constant.GroupChatType:
|
||||
if msgKey == msgFromMQ.MsgData.SendID || utils.IsContain(msgFromMQ.MsgData.SendID, config.Config.Manager.AppManagerUid) {
|
||||
tag = true
|
||||
}
|
||||
}
|
||||
if tag {
|
||||
log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg))
|
||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
||||
log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
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"
|
||||
"errors"
|
||||
|
||||
//"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
GetuiClient *Getui
|
||||
|
||||
TokenExpireError = errors.New("token expire")
|
||||
)
|
||||
|
||||
const (
|
||||
PushURL = "/push/single/alias"
|
||||
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 {
|
||||
Alias []string `json:"alias"`
|
||||
} `json:"audience"`
|
||||
PushMessage struct {
|
||||
Notification Notification `json:"notification,omitempty"`
|
||||
Transmission string `json:"transmission,omitempty"`
|
||||
} `json:"push_message"`
|
||||
PushChannel struct {
|
||||
Ios Ios `json:"ios"`
|
||||
Android Android `json:"android"`
|
||||
} `json:"push_channel"`
|
||||
}
|
||||
|
||||
type Ios struct {
|
||||
Aps struct {
|
||||
Sound string `json:"sound"`
|
||||
Alert Alert `json:"alert"`
|
||||
} `json:"aps"`
|
||||
}
|
||||
|
||||
type Alert struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type Android struct {
|
||||
Ups struct {
|
||||
Notification Notification `json:"notification"`
|
||||
} `json:"ups"`
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
ClickType string `json:"click_type"`
|
||||
}
|
||||
|
||||
type PushResp struct {
|
||||
}
|
||||
|
||||
func newGetuiClient() *Getui {
|
||||
return &Getui{}
|
||||
}
|
||||
|
||||
func (g *Getui) Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error) {
|
||||
token, err := db.DB.GetGetuiToken()
|
||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "token:", token)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error())
|
||||
}
|
||||
if token == "" || err != nil {
|
||||
token, err = g.getTokenAndSave2Redis(operationID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis failed", err.Error())
|
||||
return "", utils.Wrap(err, "")
|
||||
}
|
||||
}
|
||||
pushReq := PushReq{
|
||||
RequestID: utils.OperationIDGenerator(),
|
||||
Audience: struct {
|
||||
Alias []string `json:"alias"`
|
||||
}{Alias: []string{userIDList[0]}},
|
||||
}
|
||||
pushReq.PushMessage.Notification = Notification{
|
||||
Title: alert,
|
||||
Body: alert,
|
||||
ClickType: "startapp",
|
||||
}
|
||||
pushReq.PushChannel.Ios.Aps.Sound = "default"
|
||||
pushReq.PushChannel.Ios.Aps.Alert = Alert{
|
||||
Title: alert,
|
||||
Body: alert,
|
||||
}
|
||||
pushReq.PushChannel.Android.Ups.Notification = Notification{
|
||||
Title: alert,
|
||||
Body: alert,
|
||||
ClickType: "startapp",
|
||||
}
|
||||
pushResp := PushResp{}
|
||||
err = g.request(PushURL, pushReq, token, &pushResp, operationID)
|
||||
switch err {
|
||||
case TokenExpireError:
|
||||
token, err = g.getTokenAndSave2Redis(operationID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis failed, ", err.Error())
|
||||
} else {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "getTokenAndSave2Redis: ", token)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "push failed")
|
||||
}
|
||||
respBytes, err := json.Marshal(pushResp)
|
||||
return string(respBytes), utils.Wrap(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))
|
||||
commonResp := GetuiCommonResp{}
|
||||
commonResp.Data = returnStruct
|
||||
if err := json.Unmarshal(result, &commonResp); err != nil {
|
||||
return err
|
||||
}
|
||||
if commonResp.Code == 10001 {
|
||||
return TokenExpireError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Getui) getTokenAndSave2Redis(operationID string) (token string, err error) {
|
||||
token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Auth failed")
|
||||
}
|
||||
log.NewDebug(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err)
|
||||
err = db.DB.SetGetuiToken(token, 60*60*23)
|
||||
if err != nil {
|
||||
return "", utils.Wrap(err, "Auth failed")
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
+27
-11
@@ -10,17 +10,35 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type JPushResp struct {
|
||||
var (
|
||||
JPushClient *JPush
|
||||
)
|
||||
|
||||
func init() {
|
||||
JPushClient = newGetuiClient()
|
||||
}
|
||||
|
||||
func JGAccountListPush(accounts []string, alert, detailContent, platform string) ([]byte, error) {
|
||||
type JPush struct{}
|
||||
|
||||
func newGetuiClient() *JPush {
|
||||
return &JPush{}
|
||||
}
|
||||
|
||||
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (j *JPush) Push(accounts []string, alert, detailContent, operationID string) (string, error) {
|
||||
var pf requestBody.Platform
|
||||
_ = pf.SetPlatform(platform)
|
||||
pf.SetAll()
|
||||
var au requestBody.Audience
|
||||
au.SetAlias(accounts)
|
||||
var no requestBody.Notification
|
||||
no.SetAlert(alert, platform)
|
||||
no.SetAlert(alert)
|
||||
var me requestBody.Message
|
||||
me.SetMsgContent(detailContent)
|
||||
var o requestBody.Options
|
||||
@@ -34,25 +52,23 @@ func JGAccountListPush(accounts []string, alert, detailContent, platform string)
|
||||
|
||||
con, err := json.Marshal(po)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", common.GetAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret))
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
result, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
return result, nil
|
||||
return string(result), nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package requestBody
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
)
|
||||
|
||||
type Notification struct {
|
||||
@@ -23,18 +22,14 @@ type Ios struct {
|
||||
Badge string `json:"badge,omitempty"`
|
||||
}
|
||||
|
||||
func (n *Notification) SetAlert(alert, platform string) {
|
||||
func (n *Notification) SetAlert(alert string) {
|
||||
n.Alert = alert
|
||||
switch platform {
|
||||
case constant.AndroidPlatformStr:
|
||||
n.Android.Alert = alert
|
||||
n.SetAndroidIntent()
|
||||
case constant.IOSPlatformStr:
|
||||
n.IOS.Alert = alert
|
||||
n.IOS.Sound = "default"
|
||||
n.IOS.Badge = "+1"
|
||||
default:
|
||||
}
|
||||
n.Android.Alert = alert
|
||||
n.SetAndroidIntent()
|
||||
n.IOS.Alert = alert
|
||||
n.IOS.Sound = "default"
|
||||
n.IOS.Badge = "+1"
|
||||
|
||||
}
|
||||
func (n *Notification) SetAndroidIntent() {
|
||||
n.Android.Intent.URL = config.Config.Push.Jpns.PushIntent
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/statistics"
|
||||
"fmt"
|
||||
)
|
||||
@@ -24,7 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func Init(rpcPort int) {
|
||||
log.NewPrivateLog(config.Config.ModuleName.PushName)
|
||||
|
||||
rpcServer.Init(rpcPort)
|
||||
pushCh.Init()
|
||||
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
push "Open_IM/internal/push/jpush"
|
||||
pusher "Open_IM/internal/push"
|
||||
"Open_IM/internal/push/getui"
|
||||
jpush "Open_IM/internal/push/jpush"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
@@ -35,7 +37,7 @@ type AtContent struct {
|
||||
func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
||||
var wsResult []*pbRelay.SingleMsgToUser
|
||||
isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush)
|
||||
log.Debug("Get msg from msg_transfer And push msg", pushMsg.OperationID, "PushData", pushMsg.String())
|
||||
log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
//Online push message
|
||||
log.Debug("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
|
||||
@@ -43,72 +45,80 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
||||
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserID: pushMsg.PushToUserID})
|
||||
if err != nil {
|
||||
log.InfoByKv("push data to client rpc err", pushMsg.OperationID, "err", err)
|
||||
log.NewError("push data to client rpc err", pushMsg.OperationID, "err", err)
|
||||
continue
|
||||
}
|
||||
if reply != nil && reply.Resp != nil {
|
||||
wsResult = append(wsResult, reply.Resp...)
|
||||
}
|
||||
}
|
||||
log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData)
|
||||
log.NewInfo(pushMsg.OperationID, "push_result", wsResult, "sendData", pushMsg.MsgData)
|
||||
count++
|
||||
if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID {
|
||||
for _, v := range wsResult {
|
||||
if v.ResultCode == 0 {
|
||||
continue
|
||||
}
|
||||
//supported terminal
|
||||
for _, t := range pushTerminal {
|
||||
if v.RecvPlatFormID == t {
|
||||
//Use offline push messaging
|
||||
var UIDList []string
|
||||
UIDList = append(UIDList, v.RecvID)
|
||||
customContent := OpenIMContent{
|
||||
SessionType: int(pushMsg.MsgData.SessionType),
|
||||
From: pushMsg.MsgData.SendID,
|
||||
To: pushMsg.MsgData.RecvID,
|
||||
Seq: pushMsg.MsgData.Seq,
|
||||
}
|
||||
bCustomContent, _ := json.Marshal(customContent)
|
||||
jsonCustomContent := string(bCustomContent)
|
||||
var content string
|
||||
if pushMsg.MsgData.OfflinePushInfo != nil {
|
||||
content = pushMsg.MsgData.OfflinePushInfo.Title
|
||||
|
||||
} else {
|
||||
switch pushMsg.MsgData.ContentType {
|
||||
case constant.Text:
|
||||
content = constant.ContentType2PushContent[constant.Text]
|
||||
case constant.Picture:
|
||||
content = constant.ContentType2PushContent[constant.Picture]
|
||||
case constant.Voice:
|
||||
content = constant.ContentType2PushContent[constant.Voice]
|
||||
case constant.Video:
|
||||
content = constant.ContentType2PushContent[constant.Video]
|
||||
case constant.File:
|
||||
content = constant.ContentType2PushContent[constant.File]
|
||||
case constant.AtText:
|
||||
a := AtContent{}
|
||||
_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
||||
if utils.IsContain(v.RecvID, a.AtUserList) {
|
||||
content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
||||
} else {
|
||||
content = constant.ContentType2PushContent[constant.GroupMsg]
|
||||
}
|
||||
default:
|
||||
content = constant.ContentType2PushContent[constant.Common]
|
||||
}
|
||||
}
|
||||
|
||||
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
|
||||
} else {
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t))
|
||||
}
|
||||
|
||||
if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) {
|
||||
//Use offline push messaging
|
||||
var UIDList []string
|
||||
UIDList = append(UIDList, v.RecvID)
|
||||
customContent := OpenIMContent{
|
||||
SessionType: int(pushMsg.MsgData.SessionType),
|
||||
From: pushMsg.MsgData.SendID,
|
||||
To: pushMsg.MsgData.RecvID,
|
||||
Seq: pushMsg.MsgData.Seq,
|
||||
}
|
||||
bCustomContent, _ := json.Marshal(customContent)
|
||||
jsonCustomContent := string(bCustomContent)
|
||||
var content string
|
||||
if pushMsg.MsgData.OfflinePushInfo != nil {
|
||||
content = pushMsg.MsgData.OfflinePushInfo.Title
|
||||
|
||||
} else {
|
||||
switch pushMsg.MsgData.ContentType {
|
||||
case constant.Text:
|
||||
content = constant.ContentType2PushContent[constant.Text]
|
||||
case constant.Picture:
|
||||
content = constant.ContentType2PushContent[constant.Picture]
|
||||
case constant.Voice:
|
||||
content = constant.ContentType2PushContent[constant.Voice]
|
||||
case constant.Video:
|
||||
content = constant.ContentType2PushContent[constant.Video]
|
||||
case constant.File:
|
||||
content = constant.ContentType2PushContent[constant.File]
|
||||
case constant.AtText:
|
||||
a := AtContent{}
|
||||
_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
||||
if utils.IsContain(v.RecvID, a.AtUserList) {
|
||||
content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
||||
} else {
|
||||
content = constant.ContentType2PushContent[constant.GroupMsg]
|
||||
}
|
||||
default:
|
||||
content = constant.ContentType2PushContent[constant.Common]
|
||||
}
|
||||
}
|
||||
var offlinePusher pusher.OfflinePusher
|
||||
if config.Config.Push.Getui.Enable {
|
||||
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
|
||||
offlinePusher = getui.GetuiClient
|
||||
}
|
||||
if config.Config.Push.Jpns.Enable {
|
||||
offlinePusher = jpush.JPushClient
|
||||
}
|
||||
if offlinePusher == nil {
|
||||
offlinePusher = jpush.JPushClient
|
||||
}
|
||||
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
||||
} else {
|
||||
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package push
|
||||
|
||||
type OfflinePusher interface {
|
||||
Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ type adminCMSServer struct {
|
||||
}
|
||||
|
||||
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||
log.NewPrivateLog("AdminCMS")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &adminCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
||||
@@ -66,12 +66,12 @@ func (s *adminCMSServer) Run() {
|
||||
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbAdminCMS.AdminLoginResp{}
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid{
|
||||
for i, adminID := range config.Config.Manager.AppManagerUid {
|
||||
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||
}
|
||||
resp.Token = token
|
||||
@@ -84,4 +84,4 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi
|
||||
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
+23
-19
@@ -20,38 +20,41 @@ import (
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserRegister args ", req.String())
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
var user db.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.Birth != 0 {
|
||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||
}
|
||||
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
||||
err := imdb.UserRegister(user)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err.Error(), user)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
|
||||
log.NewError(req.OperationID, errMsg, user)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserRegister return")
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}})
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
errMsg := req.OperationID + " imdb.GetUserByUserID failed " + err.Error() + req.FromUserID
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, req.Platform)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CreateToken failed ", err.Error(), req.FromUserID, req.Platform)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserToken return ", tokens, expTime)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
|
||||
@@ -63,7 +66,7 @@ type rpcAuth struct {
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
@@ -73,15 +76,16 @@ func NewRpcAuthServer(port int) *rpcAuth {
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log.NewInfo("0", "rpc auth start...")
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, "rpc auth start...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), address)
|
||||
log.NewError(operationID, "listen network failed ", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
log.NewInfo(operationID, "listen network success, ", address, listener)
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
@@ -90,15 +94,15 @@ func (rpc *rpcAuth) Run() {
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(),
|
||||
log.NewError(operationID, "RegisterEtcd failed ", err.Error(),
|
||||
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
log.NewInfo(operationID, "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
log.NewError(operationID, "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc auth ok")
|
||||
log.NewInfo(operationID, "rpc auth ok")
|
||||
}
|
||||
|
||||
Vendored
+330
@@ -0,0 +1,330 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
commonPb "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type cacheServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewCacheServer(port int) *cacheServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &cacheServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImCacheName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *cacheServer) Run() {
|
||||
log.NewInfo("0", "cacheServer 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
|
||||
|
||||
//to cache
|
||||
err = SyncDB2Cache()
|
||||
if err != nil {
|
||||
log.NewError("", err.Error(), "db to cache failed")
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
pbCache.RegisterCacheServer(srv, s)
|
||||
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 SyncDB2Cache() error {
|
||||
var err error
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
userList, err := imdb.GetAllUser()
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
//err = updateAllUserToCache(userList)
|
||||
err = updateAllFriendToCache(userList)
|
||||
err = updateAllBlackListToCache(userList)
|
||||
err = updateAllGroupMemberListToCache()
|
||||
return err
|
||||
}
|
||||
|
||||
func DelRelationCache() {}
|
||||
|
||||
func updateAllUserToCache(userList []db.User) error {
|
||||
for _, userInfo := range userList {
|
||||
userInfoPb := &commonPb.UserInfo{
|
||||
UserID: userInfo.UserID,
|
||||
Nickname: userInfo.Nickname,
|
||||
FaceURL: userInfo.FaceURL,
|
||||
Gender: userInfo.Gender,
|
||||
PhoneNumber: userInfo.PhoneNumber,
|
||||
Birth: uint32(userInfo.Birth.Unix()),
|
||||
Email: userInfo.Email,
|
||||
Ex: userInfo.Ex,
|
||||
CreateTime: uint32(userInfo.CreateTime.Unix()),
|
||||
AppMangerLevel: userInfo.AppMangerLevel,
|
||||
}
|
||||
m, err := utils.Pb2Map(userInfoPb)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllGroupMemberListToCache() error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
groupIDList, err := imdb.GetAllGroupIDList()
|
||||
if err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error())
|
||||
panic(err.Error())
|
||||
}
|
||||
for _, groupID := range groupIDList {
|
||||
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error())
|
||||
continue
|
||||
}
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "groupMemberIDList", groupMemberIDList)
|
||||
if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllFriendToCache(userList []db.User) error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
for _, user := range userList {
|
||||
friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID)
|
||||
if err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||
continue
|
||||
}
|
||||
if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateAllBlackListToCache(userList []db.User) error {
|
||||
log.NewInfo("0", utils.GetSelfFuncName())
|
||||
for _, user := range userList {
|
||||
blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID)
|
||||
if err != nil {
|
||||
log.NewError("", utils.GetSelfFuncName(), err.Error())
|
||||
continue
|
||||
}
|
||||
if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil {
|
||||
log.NewError("0", utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "ok")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetUserInfoFromCache(_ context.Context, req *pbCache.GetUserInfoFromCacheReq) (resp *pbCache.GetUserInfoFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetUserInfoFromCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
for _, userID := range req.UserIDList {
|
||||
userInfo, err := db.DB.GetUserInfoFromCache(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get userInfo from cache failed", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.UserInfoList = append(resp.UserInfoList, userInfo)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) UpdateUserInfoToCache(_ context.Context, req *pbCache.UpdateUserInfoToCacheReq) (resp *pbCache.UpdateUserInfoToCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.UpdateUserInfoToCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
for _, userInfo := range req.UserInfoList {
|
||||
m, err := utils.Pb2Map(userInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), *userInfo)
|
||||
}
|
||||
if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
friendIDList, err := db.DB.GetFriendIDListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), friendIDList)
|
||||
resp.UserIDList = friendIDList
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddFriendToCache(_ context.Context, req *pbCache.AddFriendToCacheReq) (resp *pbCache.AddFriendToCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddFriendToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddFriendToCache(req.UserID, req.FriendID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp.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 *cacheServer) ReduceFriendFromCache(_ context.Context, req *pbCache.ReduceFriendFromCacheReq) (resp *pbCache.ReduceFriendFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceFriendFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.ReduceFriendToCache(req.UserID, req.FriendID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
blackUserIDList, err := db.DB.GetBlackListFromCache(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), blackUserIDList)
|
||||
resp.UserIDList = blackUserIDList
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddBlackUserToCache(_ context.Context, req *pbCache.AddBlackUserToCacheReq) (resp *pbCache.AddBlackUserToCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddBlackUserToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddBlackUserToCache(req.UserID, req.BlackUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
resp.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 *cacheServer) ReduceBlackUserFromCache(_ context.Context, req *pbCache.ReduceBlackUserFromCacheReq) (resp *pbCache.ReduceBlackUserFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceBlackUserFromCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.ReduceBlackUserFromCache(req.UserID, req.BlackUserID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCache.GetGroupMemberIDListFromCacheReq) (resp *pbCache.GetGroupMemberIDListFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.GetGroupMemberIDListFromCacheResp{
|
||||
CommonResp: &pbCache.CommonResp{},
|
||||
}
|
||||
userIDList, err := db.DB.GetGroupMemberIDListFromCache(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListFromCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
resp.UserIDList = userIDList
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *cacheServer) AddGroupMemberToCache(_ context.Context, req *pbCache.AddGroupMemberToCacheReq) (resp *pbCache.AddGroupMemberToCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.AddGroupMemberToCacheResp{CommonResp: &pbCache.CommonResp{}}
|
||||
if err := db.DB.AddGroupMemberToCache(req.GroupID, req.UserIDList...); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddGroupMemberToCache failed", err.Error())
|
||||
resp.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 *cacheServer) ReduceGroupMemberFromCache(_ context.Context, req *pbCache.ReduceGroupMemberFromCacheReq) (resp *pbCache.ReduceGroupMemberFromCacheResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbCache.ReduceGroupMemberFromCacheResp{}
|
||||
if err := db.DB.ReduceGroupMemberFromCache(req.GroupID, req.UserIDList...); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "ReduceGroupMemberFromCache failed", err.Error())
|
||||
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type rpcConversation struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbConversation.ModifyConversationFieldReq) (*pbConversation.ModifyConversationFieldResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbConversation.ModifyConversationFieldResp{}
|
||||
var err error
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.Conversation.GroupID, err.Error())
|
||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup {
|
||||
errMsg := "group status is dismissed"
|
||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
var conversation db.Conversation
|
||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error())
|
||||
}
|
||||
haveUserID, _ := imdb.GetExistConversationUserIDList(req.UserIDList, req.Conversation.ConversationID)
|
||||
switch req.FieldType {
|
||||
case constant.FieldRecvMsgOpt:
|
||||
for _, v := range req.UserIDList {
|
||||
if err = db.DB.SetSingleConversationRecvMsgOpt(v, req.Conversation.ConversationID, req.Conversation.RecvMsgOpt); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error())
|
||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt})
|
||||
case constant.FieldGroupAtType:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"group_at_type": conversation.GroupAtType})
|
||||
case constant.FieldIsNotInGroup:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"is_not_in_group": conversation.IsNotInGroup})
|
||||
case constant.FieldIsPinned:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"is_pinned": conversation.IsPinned})
|
||||
case constant.FieldIsPrivateChat:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"is_private_chat": conversation.IsPrivateChat})
|
||||
case constant.FieldEx:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"ex": conversation.Ex})
|
||||
case constant.FieldAttachedInfo:
|
||||
err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"attached_info": conversation.AttachedInfo})
|
||||
}
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateColumnsConversations error", err.Error())
|
||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
for _, v := range utils.DifferenceString(haveUserID, req.UserIDList) {
|
||||
conversation.OwnerUserID = v
|
||||
err := imdb.SetOneConversation(conversation)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
resp.CommonResp = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
// notification
|
||||
if req.Conversation.ConversationType == constant.SingleChatType && req.FieldType == constant.FieldIsPrivateChat {
|
||||
//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 = &pbConversation.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
} else {
|
||||
for _, v := range req.UserIDList {
|
||||
chat.ConversationChangeNotification(req.OperationID, v)
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbConversation.CommonResp{}
|
||||
return resp, nil
|
||||
}
|
||||
func syncPeerUserConversation(conversation *pbConversation.Conversation, operationID string) error {
|
||||
peerUserConversation := db.Conversation{
|
||||
OwnerUserID: conversation.UserID,
|
||||
ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType),
|
||||
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 NewRpcConversationServer(port int) *rpcConversation {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &rpcConversation{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImConversationName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcConversation) Run() {
|
||||
log.NewInfo("0", "rpc conversation start...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
pbConversation.RegisterConversationServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(),
|
||||
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "RegisterConversationServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc conversation ok")
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -29,7 +30,7 @@ type friendServer struct {
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
@@ -83,6 +84,18 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
reqAddBlackUserToCache := &pbCache.AddBlackUserToCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.AddBlackUserToCache(context.Background(), reqAddBlackUserToCache)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc call failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -234,9 +247,37 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
// cache rpc
|
||||
addFriendToCacheReq := &pbCache.AddFriendToCacheReq{OperationID: req.CommID.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
addFriendToCacheReq.UserID = req.CommID.ToUserID
|
||||
addFriendToCacheReq.FriendID = req.CommID.FromUserID
|
||||
respPb, err := client.AddFriendToCache(context.Background(), addFriendToCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
addFriendToCacheReq.UserID = req.CommID.FromUserID
|
||||
addFriendToCacheReq.FriendID = req.CommID.ToUserID
|
||||
respPb, err = client.AddFriendToCache(context.Background(), addFriendToCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String())
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
}
|
||||
}
|
||||
|
||||
if req.HandleResult == constant.FriendResponseAgree {
|
||||
chat.FriendApplicationApprovedNotification(req)
|
||||
} else if req.HandleResult == constant.FriendResponseRefuse {
|
||||
@@ -244,6 +285,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
} else {
|
||||
log.Error(req.CommID.OperationID, "HandleResult failed ", req.HandleResult)
|
||||
}
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok")
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -261,6 +303,18 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
|
||||
reduceFriendFromCache := &pbCache.ReduceFriendFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID, FriendID: req.CommID.ToUserID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
client := pbCache.NewCacheClient(etcdConn)
|
||||
respPb, err := client.ReduceFriendFromCache(context.Background(), reduceFriendFromCache)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache rpc failed", err.Error())
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
}
|
||||
if respPb.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed")
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
chat.FriendDeletedNotification(req)
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
@@ -330,6 +384,18 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
|
||||
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ")
|
||||
reqReduceBlackUserFromCache := &pbCache.ReduceBlackUserFromCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.ReduceBlackUserFromCache(context.Background(), reqReduceBlackUserFromCache)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc call failed ", err.Error())
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
|
||||
}
|
||||
chat.BlackDeletedNotification(req)
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
@@ -7,3 +7,7 @@ import (
|
||||
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func callbackAfterCreateGroup(req *pbGroup.CreateGroupReq) {
|
||||
|
||||
}
|
||||
|
||||
+343
-23
@@ -13,6 +13,7 @@ import (
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net"
|
||||
@@ -31,7 +32,7 @@ type groupServer struct {
|
||||
}
|
||||
|
||||
func NewGroupServer(port int) *groupServer {
|
||||
log.NewPrivateLog("group")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &groupServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
@@ -41,16 +42,16 @@ func NewGroupServer(port int) *groupServer {
|
||||
}
|
||||
|
||||
func (s *groupServer) Run() {
|
||||
log.NewInfo("0", "group rpc start ")
|
||||
log.NewInfo("", "group rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
log.NewError("", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", registerAddress, listener)
|
||||
log.NewInfo("", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
@@ -59,15 +60,15 @@ func (s *groupServer) Run() {
|
||||
pbGroup.RegisterGroupServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error())
|
||||
log.NewError("", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
log.NewError("", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "group rpc success")
|
||||
log.NewInfo("", "group rpc success")
|
||||
}
|
||||
|
||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||
@@ -160,6 +161,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
resp.GroupInfo.OwnerUserID = req.OwnerUserID
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
|
||||
return resp, nil
|
||||
}
|
||||
@@ -202,15 +204,19 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
|
||||
|
||||
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "no permission InviteUserToGroup ", req.GroupID, req.OpUserID)
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
_, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
errMsg := " group status is dismissed "
|
||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
//
|
||||
//from User: invite: applicant
|
||||
@@ -254,7 +260,53 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
}
|
||||
|
||||
var haveConUserID []string
|
||||
conversations, err := imdb.GetConversationsByConversationIDMultipleOwner(okUserIDList, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType))
|
||||
for _, v := range conversations {
|
||||
haveConUserID = append(haveConUserID, v.OwnerUserID)
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbUser.Conversation
|
||||
for _, v := range conversations {
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = v.OwnerUserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.RecvMsgOpt = v.RecvMsgOpt
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsPinned = v.IsPinned
|
||||
c.AttachedInfo = v.AttachedInfo
|
||||
c.IsPrivateChat = v.IsPrivateChat
|
||||
c.GroupAtType = v.GroupAtType
|
||||
c.IsNotInGroup = false
|
||||
c.Ex = v.Ex
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v.OwnerUserID)
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.OwnerUserID)
|
||||
}
|
||||
}
|
||||
for _, v := range utils.DifferenceString(haveConUserID, okUserIDList) {
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = v
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = false
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v)
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v)
|
||||
}
|
||||
}
|
||||
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
|
||||
resp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp.String())
|
||||
@@ -273,8 +325,11 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
}
|
||||
|
||||
for _, v := range memberList {
|
||||
log.Debug(req.OperationID, v)
|
||||
var node open_im_sdk.GroupMemberFullInfo
|
||||
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
||||
log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix())
|
||||
log.Debug(req.OperationID, "cp value: ", node)
|
||||
resp.MemberList = append(resp.MemberList, &node)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", resp.String())
|
||||
@@ -328,7 +383,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
|
||||
//op is app manager
|
||||
if flag != 1 {
|
||||
if token_verify.IsMangerUserID(req.OpUserID) {
|
||||
if token_verify.IsManagerUserID(req.OpUserID) {
|
||||
flag = 1
|
||||
log.NewDebug(req.OperationID, "is app manager ", req.OpUserID)
|
||||
}
|
||||
@@ -355,7 +410,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
//remove
|
||||
var resp pbGroup.KickGroupMemberResp
|
||||
for _, v := range req.KickedUserIDList {
|
||||
//owner cant kicked
|
||||
//owner can‘t kicked
|
||||
if v == groupOwnerUserID {
|
||||
log.NewError(req.OperationID, "failed, can't kick owner ", v)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
||||
@@ -371,9 +426,28 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
okUserIDList = append(okUserIDList, v)
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, v)
|
||||
//err = db.DB.DelGroupMember(req.GroupID, v)
|
||||
//if err != nil {
|
||||
// log.NewError(req.OperationID, "DelGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
//}
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbUser.Conversation
|
||||
for _, v := range okUserIDList {
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = v
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DelGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v)
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v)
|
||||
}
|
||||
}
|
||||
chat.MemberKickedNotification(req, okUserIDList)
|
||||
@@ -464,8 +538,8 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
groupRequest.UserID = req.FromUserID
|
||||
groupRequest.HandleUserID = req.OpUserID
|
||||
groupRequest.HandledTime = time.Now()
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID)
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
err := imdb.UpdateGroupRequest(groupRequest)
|
||||
@@ -494,6 +568,38 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member)
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
reqPb.OperationID = req.OperationID
|
||||
var c pbUser.Conversation
|
||||
conversation, err := imdb.GetConversation(req.FromUserID, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType))
|
||||
if err != nil {
|
||||
c.OwnerUserID = req.FromUserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = false
|
||||
} else {
|
||||
c.OwnerUserID = conversation.OwnerUserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.RecvMsgOpt = conversation.RecvMsgOpt
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsPinned = conversation.IsPinned
|
||||
c.AttachedInfo = conversation.AttachedInfo
|
||||
c.IsPrivateChat = conversation.IsPrivateChat
|
||||
c.GroupAtType = conversation.GroupAtType
|
||||
c.IsNotInGroup = false
|
||||
c.Ex = conversation.Ex
|
||||
}
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
|
||||
}
|
||||
chat.GroupApplicationAcceptedNotification(req)
|
||||
chat.MemberEnterNotification(req)
|
||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||
@@ -515,6 +621,16 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
errMsg := " group status is dismissed "
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
var groupRequest db.GroupRequest
|
||||
groupRequest.UserID = req.OpUserID
|
||||
groupRequest.ReqMsg = req.ReqMessage
|
||||
@@ -539,7 +655,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.QuitGroupResp, error) {
|
||||
log.NewError(req.OperationID, "QuitGroup args ", req.String())
|
||||
log.NewInfo(req.OperationID, "QuitGroup args ", req.String())
|
||||
_, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMemberInfoByGroupIDAndUserID failed ", err.Error(), req.GroupID, req.OpUserID)
|
||||
@@ -557,7 +673,40 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
log.NewError(req.OperationID, "DelGroupMember failed ", req.GroupID, req.OpUserID)
|
||||
// return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//modify quitter conversation info
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbUser.Conversation
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = req.OpUserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
|
||||
}
|
||||
//reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{
|
||||
// UserIDList: []string{req.OpUserID},
|
||||
// GroupID: req.GroupID,
|
||||
// OperationID: req.OperationID,
|
||||
//}
|
||||
//etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
//cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
//respCachePb, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq)
|
||||
//if err != nil {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), reduceGroupMemberFromCacheReq.String())
|
||||
// return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
|
||||
//}
|
||||
//if respPb.CommonResp.ErrCode != 0 {
|
||||
// log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", reduceGroupMemberFromCacheReq.String())
|
||||
// return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode:respCachePb.CommonResp.ErrCode, ErrMsg: respCachePb.CommonResp.ErrMsg}}, nil
|
||||
//}
|
||||
chat.MemberQuitNotification(req)
|
||||
log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}})
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
@@ -592,6 +741,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
|
||||
if group.Status == constant.GroupStatusDismissed {
|
||||
errMsg := " group status is dismissed "
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner
|
||||
var changedType int32
|
||||
if group.GroupName != req.GroupInfo.GroupName && req.GroupInfo.GroupName != "" {
|
||||
@@ -624,12 +778,22 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||
log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String())
|
||||
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
errMsg := " group status is dismissed "
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
|
||||
if req.OldOwnerUserID == req.NewOwnerUserID {
|
||||
log.NewError(req.OperationID, "same owner ", req.OldOwnerUserID, req.NewOwnerUserID)
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
}
|
||||
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers}
|
||||
err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
@@ -653,7 +817,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
||||
}}
|
||||
group, err := imdb.GetGroupById(req.GroupId)
|
||||
if err != nil {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
|
||||
return resp, http.WrapError(constant.ErrDB)
|
||||
}
|
||||
resp.CMSGroup.GroupInfo = &open_im_sdk.GroupInfo{
|
||||
@@ -665,6 +829,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
||||
Status: group.Status,
|
||||
CreatorUserID: group.CreatorUserID,
|
||||
GroupType: group.GroupType,
|
||||
CreateTime: uint32(group.CreateTime.Unix()),
|
||||
}
|
||||
groupMember, err := imdb.GetGroupMaster(group.GroupID)
|
||||
if err != nil {
|
||||
@@ -674,6 +839,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
|
||||
resp.CMSGroup.GroupMasterName = groupMember.Nickname
|
||||
resp.CMSGroup.GroupMasterId = groupMember.UserID
|
||||
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -701,6 +867,7 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
groupMember, err := imdb.GetGroupMaster(v.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
|
||||
continue
|
||||
}
|
||||
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
|
||||
GroupInfo: &open_im_sdk.GroupInfo{
|
||||
@@ -710,11 +877,13 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
|
||||
OwnerUserID: v.CreatorUserID,
|
||||
Status: v.Status,
|
||||
CreatorUserID: v.CreatorUserID,
|
||||
CreateTime: uint32(v.CreateTime.Unix()),
|
||||
},
|
||||
GroupMasterName: groupMember.Nickname,
|
||||
GroupMasterId: groupMember.UserID,
|
||||
})
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -859,6 +1028,25 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
|
||||
OperationID: req.OperationID,
|
||||
OpUserID: req.OpUserId,
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbUser.Conversation
|
||||
for _, v := range resp.Success {
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = v
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupId, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupId
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v)
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v)
|
||||
}
|
||||
}
|
||||
chat.MemberKickedNotification(reqKick, resp.Success)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "success: ", resp.Success)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "failed: ", resp.Failed)
|
||||
@@ -940,7 +1128,7 @@ func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.
|
||||
|
||||
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) {
|
||||
if !token_verify.IsManagerUserID(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
|
||||
}
|
||||
@@ -950,14 +1138,146 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
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
|
||||
}
|
||||
memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
|
||||
}
|
||||
//modify quitter conversation info
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbUser.Conversation
|
||||
for _, v := range memberList {
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = v.UserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
c.GroupID = req.GroupID
|
||||
c.IsNotInGroup = true
|
||||
reqPb.Conversation = &c
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v.UserID)
|
||||
} else {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.UserID)
|
||||
}
|
||||
}
|
||||
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.IsManagerUserID(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.IsManagerUserID(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.IsManagerUserID(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.IsManagerUserID(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
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " verify failed " + req.OpUserID + req.GroupID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
groupMemberInfo := db.GroupMember{}
|
||||
groupMemberInfo.UserID = req.UserID
|
||||
groupMemberInfo.GroupID = req.GroupID
|
||||
if req.Nickname == "" {
|
||||
userNickname, err := imdb.GetUserNameByUserID(groupMemberInfo.UserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " GetUserNameByUserID failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
groupMemberInfo.Nickname = userNickname
|
||||
} else {
|
||||
groupMemberInfo.Nickname = req.Nickname
|
||||
}
|
||||
err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " UpdateGroupMemberInfo failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
|
||||
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type messageCMSServer struct {
|
||||
}
|
||||
|
||||
func NewMessageCMSServer(port int) *messageCMSServer {
|
||||
log.NewPrivateLog("MessageCMS")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &messageCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
||||
@@ -84,8 +84,8 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||
}
|
||||
chatLog := db.ChatLog{
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
Content: req.Content,
|
||||
SendTime: time,
|
||||
ContentType: req.ContentType,
|
||||
SessionType: req.SessionType,
|
||||
}
|
||||
@@ -101,20 +101,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
||||
}
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||
return resp, errors.WrapError(constant.ErrDB)
|
||||
}
|
||||
for _, chatLog := range chatLogs {
|
||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
||||
SessionType: chatLog.SessionType,
|
||||
ContentType: chatLog.ContentType,
|
||||
SearchContent: req.Content,
|
||||
WholeContent: chatLog.Content,
|
||||
Date: chatLog.CreateTime.String(),
|
||||
SessionType: chatLog.SessionType,
|
||||
ContentType: chatLog.ContentType,
|
||||
SearchContent: req.Content,
|
||||
WholeContent: chatLog.Content,
|
||||
Date: chatLog.CreateTime.String(),
|
||||
SenderNickName: chatLog.SenderNickname,
|
||||
SenderId: chatLog.SendID,
|
||||
SenderId: chatLog.SendID,
|
||||
}
|
||||
if chatLog.SenderNickname == "" {
|
||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func conversationNotification(contentType int32, m proto.Message, operationID, userID string) {
|
||||
func SetConversationNotification(operationID, sendID, recvID string, contentType int, m proto.Message, tips open_im_sdk.TipsComm) {
|
||||
log.NewInfo(operationID, "args: ", sendID, recvID, contentType, m.String(), tips.String())
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, utils.GetSelfFuncName(), "Marshal failed ", err.Error(), m.String())
|
||||
log.NewError(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
@@ -24,15 +24,10 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.ConversationOptChangeNotification:
|
||||
tips.DefaultTips = cn.ConversationOptUpdate.DefaultTips.Tips
|
||||
}
|
||||
var n NotificationMsg
|
||||
n.SendID = userID
|
||||
n.RecvID = userID
|
||||
n.ContentType = contentType
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = int32(contentType)
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
@@ -44,10 +39,38 @@ func conversationNotification(contentType int32, m proto.Message, operationID, u
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func SetConversationNotification(operationID, userID string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "userID: ", userID)
|
||||
conversationUpdateTips := open_im_sdk.ConversationUpdateTips{
|
||||
// SetPrivate调用
|
||||
func ConversationSetPrivateNotification(operationID, sendID, recvID string, isPrivateChat bool) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName())
|
||||
conversationSetPrivateTips := &open_im_sdk.ConversationSetPrivateTips{
|
||||
RecvID: recvID,
|
||||
SendID: sendID,
|
||||
IsPrivate: isPrivateChat,
|
||||
}
|
||||
var tips open_im_sdk.TipsComm
|
||||
var tipsMsg string
|
||||
//var senderName string
|
||||
//senderName, err := im_mysql_model.GetUserNameByUserID(sendID)
|
||||
//if err != nil {
|
||||
// log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
// senderName = sendID
|
||||
//}
|
||||
if isPrivateChat == true {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
|
||||
} else {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
|
||||
}
|
||||
tips.DefaultTips = tipsMsg
|
||||
SetConversationNotification(operationID, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
|
||||
}
|
||||
|
||||
// 会话改变
|
||||
func ConversationChangeNotification(operationID, userID string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName())
|
||||
ConversationChangedTips := &open_im_sdk.ConversationUpdateTips{
|
||||
UserID: userID,
|
||||
}
|
||||
conversationNotification(constant.ConversationOptChangeNotification, &conversationUpdateTips, operationID, userID)
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
||||
SetConversationNotification(operationID, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (rpc *rpcChat) DelMsgList(_ context.Context, req *commonPb.DelMsgListReq) (
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsg failed", err.Error())
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
return resp, err
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
if token_verify.IsMangerUserID(opUserID) {
|
||||
if token_verify.IsManagerUserID(opUserID) {
|
||||
u, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetUserByUserID failed")
|
||||
@@ -160,6 +160,17 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberEnter.DefaultTips.Tips
|
||||
case constant.GroupDismissedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupDismissed.DefaultTips.Tips
|
||||
case constant.GroupMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMuted.DefaultTips.Tips
|
||||
case constant.GroupCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberInfoSet.DefaultTips.Tips
|
||||
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
@@ -227,6 +238,89 @@ func GroupInfoSetNotification(operationID, opUserID, groupID string) {
|
||||
groupNotification(constant.GroupInfoSetNotification, &GroupInfoChangedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := open_im_sdk.GroupMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupCancelMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := open_im_sdk.GroupCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberMutedNotification(operationID, opUserID, groupID, groupMemberUserID string, mutedSeconds uint32) {
|
||||
tips := open_im_sdk.GroupMemberMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
tips.MutedSeconds = mutedSeconds
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberInfoSetNotification(operationID, opUserID, groupID, groupMemberUserID string) {
|
||||
tips := open_im_sdk.GroupMemberInfoSetTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, ChangedUser: &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.ChangedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberInfoSetNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMemberUserID string) {
|
||||
tips := open_im_sdk.GroupMemberCancelMutedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, MutedUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func OrganizationNotificationToAll(opUserID string, operationID string) {
|
||||
err, userIDList := imdb.GetAllOrganizationUserID()
|
||||
if err != nil {
|
||||
log.Error(operationID, "GetAllOrganizationUserID failed ", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
tips := open_im_sdk.OrganizationChangedTips{OpUser: &open_im_sdk.UserInfo{}}
|
||||
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetUserByUserID failed ", err.Error(), opUserID)
|
||||
return
|
||||
}
|
||||
utils2.UserDBCopyOpenIM(tips.OpUser, user)
|
||||
|
||||
for _, v := range userIDList {
|
||||
log.Debug(operationID, "OrganizationNotification", opUserID, v, constant.OrganizationChangedNotification, &tips, operationID)
|
||||
OrganizationNotification(opUserID, v, constant.OrganizationChangedNotification, &tips, operationID)
|
||||
}
|
||||
}
|
||||
|
||||
func OrganizationNotification(opUserID string, recvUserID string, contentType int32, m proto.Message, operationID string) {
|
||||
log.Info(operationID, utils.GetSelfFuncName(), "args: ", contentType, opUserID)
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
|
||||
switch contentType {
|
||||
case constant.OrganizationChangedNotification:
|
||||
tips.DefaultTips = "OrganizationChangedNotification"
|
||||
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.RecvID = recvUserID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
@@ -22,7 +23,7 @@ type rpcChat struct {
|
||||
}
|
||||
|
||||
func NewRpcChatServer(port int) *rpcChat {
|
||||
log.NewPrivateLog("msg")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rc := rpcChat{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
||||
@@ -42,7 +43,7 @@ func (rpc *rpcChat) Run() {
|
||||
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", address)
|
||||
log.Info("", "", "listen network success, address = ", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
|
||||
+223
-38
@@ -6,8 +6,9 @@ import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
cacheRpc "Open_IM/pkg/proto/cache"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
rpc "Open_IM/pkg/proto/friend"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -47,36 +49,38 @@ func userRelationshipVerification(data *pbChat.SendMsgReq) (bool, int32, string)
|
||||
return true, 0, ""
|
||||
}
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
req := &rpc.IsInBlackListReq{CommID: &rpc.CommID{}}
|
||||
req.CommID.OperationID = data.OperationID
|
||||
req.CommID.OpUserID = data.MsgData.RecvID
|
||||
req.CommID.FromUserID = data.MsgData.RecvID
|
||||
req.CommID.ToUserID = data.MsgData.SendID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
reply, err := client.IsInBlackList(context.Background(), req)
|
||||
reqGetBlackIDListFromCache := &cacheRpc.GetBlackIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.GetBlackIDListFromCache(context.Background(), reqGetBlackIDListFromCache)
|
||||
if err != nil {
|
||||
log.NewDebug(data.OperationID, "IsInBlackListReq rpc failed, ", req.String(), err.Error())
|
||||
} else if reply.Response == true {
|
||||
log.NewDebug(data.OperationID, "IsInBlackListReq ", req.String())
|
||||
return false, 600, "in black list"
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc call failed ", err.Error())
|
||||
} else {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
} else {
|
||||
if utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 600, "in black list"
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
|
||||
if config.Config.MessageVerify.FriendVerify {
|
||||
friendReq := &rpc.IsFriendReq{CommID: &rpc.CommID{}}
|
||||
friendReq.CommID.OperationID = data.OperationID
|
||||
friendReq.CommID.OpUserID = data.MsgData.RecvID
|
||||
friendReq.CommID.FromUserID = data.MsgData.RecvID
|
||||
friendReq.CommID.ToUserID = data.MsgData.SendID
|
||||
friendReply, err := client.IsFriend(context.Background(), friendReq)
|
||||
reqGetFriendIDListFromCache := &cacheRpc.GetFriendIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
||||
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.GetFriendIDListFromCache(context.Background(), reqGetFriendIDListFromCache)
|
||||
if err != nil {
|
||||
log.NewDebug(data.OperationID, "IsFriendReq rpc failed, ", req.String(), err.Error())
|
||||
return true, 0, ""
|
||||
} else if friendReply.Response == false {
|
||||
log.NewDebug(data.OperationID, "not friend ", req.String())
|
||||
return friendReply.Response, 601, "not friend"
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc call failed ", err.Error())
|
||||
} else {
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
} else {
|
||||
if !utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
|
||||
return false, 601, "not friend"
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify, friendReply.Response)
|
||||
return true, 0, ""
|
||||
} else {
|
||||
return true, 0, ""
|
||||
@@ -116,6 +120,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
case constant.HasReadReceipt:
|
||||
log.Info("", "this is a test start", msg, msg.Options)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
log.Info("", "this is a test end", msg, msg.Options)
|
||||
@@ -124,6 +129,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
|
||||
@@ -225,6 +231,12 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
log.Error(pb.Token, pb.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrCode, reply.ErrMsg, "", 0)
|
||||
}
|
||||
memberUserIDList := func(all []*sdk_ws.GroupMemberFullInfo) (result []string) {
|
||||
for _, v := range all {
|
||||
result = append(result, v.UserID)
|
||||
}
|
||||
return result
|
||||
}(reply.MemberList)
|
||||
var addUidList []string
|
||||
switch pb.MsgData.ContentType {
|
||||
case constant.MemberKickedNotification:
|
||||
@@ -244,22 +256,55 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
}
|
||||
case constant.MemberQuitNotification:
|
||||
addUidList = append(addUidList, pb.MsgData.SendID)
|
||||
|
||||
default:
|
||||
}
|
||||
groupID := pb.MsgData.GroupID
|
||||
for _, v := range reply.MemberList {
|
||||
pb.MsgData.RecvID = v.UserID
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v.UserID, groupID, constant.GroupChatType, pb)
|
||||
if isSend {
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
err := rpc.sendMsgToKafka(&msgToMQ, v.UserID)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v.UserID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
//split parallel send
|
||||
var wg sync.WaitGroup
|
||||
var sendTag bool
|
||||
var split = 50
|
||||
remain := len(memberUserIDList) % split
|
||||
for i := 0; i < len(memberUserIDList)/split; i++ {
|
||||
wg.Add(1)
|
||||
go func(list []string) {
|
||||
for _, v := range list {
|
||||
pb.MsgData.RecvID = v
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
|
||||
if isSend {
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
||||
} else {
|
||||
sendTag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}(memberUserIDList[i*split : (i+1)*split])
|
||||
}
|
||||
if remain > 0 {
|
||||
wg.Add(1)
|
||||
go func(list []string) {
|
||||
for _, v := range list {
|
||||
pb.MsgData.RecvID = v
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
|
||||
if isSend {
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
||||
} else {
|
||||
sendTag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
}(memberUserIDList[split*(len(memberUserIDList)/split):])
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
log.Info(msgToMQ.OperationID, "addUidList", addUidList)
|
||||
for _, v := range addUidList {
|
||||
pb.MsgData.RecvID = v
|
||||
@@ -270,7 +315,8 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
} else {
|
||||
sendTag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,6 +324,79 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
if err := callbackAfterSendGroupMsg(pb); err != nil {
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error())
|
||||
}
|
||||
if !sendTag {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
} else {
|
||||
if pb.MsgData.ContentType == constant.AtText {
|
||||
go func() {
|
||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||
var tag bool
|
||||
var atUserID []string
|
||||
conversation := pbConversation.Conversation{
|
||||
OwnerUserID: pb.MsgData.SendID,
|
||||
ConversationID: utils.GetConversationIDBySessionType(pb.MsgData.GroupID, constant.GroupChatType),
|
||||
ConversationType: constant.GroupChatType,
|
||||
GroupID: pb.MsgData.GroupID,
|
||||
}
|
||||
conversationReq.Conversation = &conversation
|
||||
conversationReq.OperationID = pb.OperationID
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
tagAll := utils.IsContain(constant.AtAllString, pb.MsgData.AtUserIDList)
|
||||
if tagAll {
|
||||
atUserID = utils.DifferenceString([]string{constant.AtAllString}, pb.MsgData.AtUserIDList)
|
||||
if len(atUserID) == 0 { //just @everyone
|
||||
conversationReq.UserIDList = memberUserIDList
|
||||
conversation.GroupAtType = constant.AtAll
|
||||
} else { //@Everyone and @other people
|
||||
conversationReq.UserIDList = atUserID
|
||||
conversation.GroupAtType = constant.AtAllAtMe
|
||||
tag = true
|
||||
}
|
||||
} else {
|
||||
conversationReq.UserIDList = pb.MsgData.AtUserIDList
|
||||
conversation.GroupAtType = constant.AtMe
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName)
|
||||
client := pbConversation.NewConversationClient(etcdConn)
|
||||
conversationReply, err := client.ModifyConversationField(context.Background(), &conversationReq)
|
||||
if err != nil {
|
||||
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), err.Error())
|
||||
} else if conversationReply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), conversationReply.String())
|
||||
}
|
||||
if tag {
|
||||
conversationReq.UserIDList = utils.DifferenceString(atUserID, memberUserIDList)
|
||||
conversation.GroupAtType = constant.AtAll
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName)
|
||||
client := pbConversation.NewConversationClient(etcdConn)
|
||||
conversationReply, err := client.ModifyConversationField(context.Background(), &conversationReq)
|
||||
if err != nil {
|
||||
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), err.Error())
|
||||
} else if conversationReply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), conversationReply.String())
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
|
||||
}
|
||||
case constant.NotificationChatType:
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
log.NewInfo(msgToMQ.OperationID, msgToMQ)
|
||||
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
||||
if err1 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
|
||||
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
||||
if err2 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
@@ -511,14 +630,80 @@ func Notification(n *NotificationMsg) {
|
||||
ex = config.Config.Notification.GroupDismissed.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupDismissed.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupDismissed.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberInfoSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberInfoSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberInfoSet.Conversation.UnreadCount
|
||||
|
||||
case constant.OrganizationChangedNotification:
|
||||
pushSwitch = config.Config.Notification.OrganizationChanged.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.OrganizationChanged.OfflinePush.Title
|
||||
desc = config.Config.Notification.OrganizationChanged.OfflinePush.Desc
|
||||
ex = config.Config.Notification.OrganizationChanged.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.OrganizationChanged.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.OrganizationChanged.Conversation.UnreadCount
|
||||
|
||||
case constant.WorkMomentNotification:
|
||||
pushSwitch = config.Config.Notification.WorkMomentsNotification.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.WorkMomentsNotification.OfflinePush.Title
|
||||
desc = config.Config.Notification.WorkMomentsNotification.OfflinePush.Desc
|
||||
ex = config.Config.Notification.WorkMomentsNotification.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.WorkMomentsNotification.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.WorkMomentsNotification.Conversation.UnreadCount
|
||||
|
||||
case constant.ConversationPrivateChatNotification:
|
||||
pushSwitch = config.Config.Notification.ConversationSetPrivate.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.ConversationSetPrivate.OfflinePush.Title
|
||||
desc = config.Config.Notification.ConversationSetPrivate.OfflinePush.Desc
|
||||
ex = config.Config.Notification.ConversationSetPrivate.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.ConversationSetPrivate.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.ConversationSetPrivate.Conversation.UnreadCount
|
||||
}
|
||||
switch reliabilityLevel {
|
||||
case constant.UnreliableNotification:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationNoMsg:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationMsg:
|
||||
|
||||
}
|
||||
@@ -535,6 +720,6 @@ func Notification(n *NotificationMsg) {
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||
} else if reply.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String())
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), reply.ErrCode, reply.ErrMsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func TagSendMessage(operationID string, user *db.User, recvID, content string, senderPlatformID int32) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content)
|
||||
var req pbChat.SendMsgReq
|
||||
var msgData pbCommon.MsgData
|
||||
msgData.SendID = user.UserID
|
||||
msgData.RecvID = recvID
|
||||
msgData.ContentType = constant.Custom
|
||||
msgData.SessionType = constant.SingleChatType
|
||||
msgData.MsgFrom = constant.UserMsgType
|
||||
msgData.Content = []byte(content)
|
||||
msgData.SenderFaceURL = user.FaceURL
|
||||
msgData.SenderNickname = user.Nickname
|
||||
msgData.Options = map[string]bool{}
|
||||
msgData.Options[constant.IsSenderConversationUpdate] = false
|
||||
msgData.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
|
||||
msgData.SenderPlatformID = senderPlatformID
|
||||
req.MsgData = &msgData
|
||||
req.OperationID = operationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
respPb, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send msg failed", err.Error())
|
||||
return
|
||||
}
|
||||
if respPb.ErrCode != 0 {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "send tag msg failed ", respPb)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func WorkMomentSendNotification(operationID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), recvID, notificationMsg)
|
||||
WorkMomentNotification(operationID, recvID, recvID, notificationMsg)
|
||||
}
|
||||
|
||||
func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) {
|
||||
var tips sdk.TipsComm
|
||||
var err error
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
n := &NotificationMsg{
|
||||
SendID: sendID,
|
||||
RecvID: recvID,
|
||||
MsgFrom: constant.UserMsgType,
|
||||
ContentType: constant.WorkMomentNotification,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: operationID,
|
||||
}
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "proto.Marshal failed")
|
||||
return
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||
Notification(n)
|
||||
}
|
||||
@@ -0,0 +1,545 @@
|
||||
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.NewDebug(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
|
||||
}
|
||||
|
||||
func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.CreateOneWorkMomentReq) (resp *pbOffice.CreateOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.CreateOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
workMoment := db.WorkMoment{
|
||||
Comments: []*db.Comment{},
|
||||
LikeUserList: []*db.LikeUser{},
|
||||
}
|
||||
createUser, err := imdb.GetUserByUserID(req.WorkMoment.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&workMoment, req.WorkMoment); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
workMoment.UserName = createUser.Nickname
|
||||
workMoment.FaceURL = createUser.FaceURL
|
||||
workMoment.PermissionUserIDList = s.getPermissionUserIDList(req.OperationID, req.WorkMoment.PermissionGroupList, req.WorkMoment.PermissionUserList)
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment to create", workMoment)
|
||||
err = db.DB.CreateOneWorkMoment(&workMoment)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CreateOneWorkMoment", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// send notification to at users
|
||||
for _, atUser := range req.WorkMoment.AtUserList {
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentAtUserNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: workMoment.UserID,
|
||||
FaceURL: createUser.FaceURL,
|
||||
UserName: createUser.Nickname,
|
||||
CreateTime: workMoment.CreateTime,
|
||||
}
|
||||
msg.WorkMomentSendNotification(req.OperationID, atUser.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// count and distinct permission users
|
||||
func (s *officeServer) getPermissionUserIDList(operationID string, groupList []*pbOffice.PermissionGroup, userList []*pbOffice.WorkMomentUser) []string {
|
||||
var permissionUserIDList []string
|
||||
for _, group := range groupList {
|
||||
groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(group.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID failed", group, err.Error())
|
||||
continue
|
||||
}
|
||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "groupMemberIDList: ", groupMemberIDList)
|
||||
permissionUserIDList = append(permissionUserIDList, groupMemberIDList...)
|
||||
}
|
||||
var userIDList []string
|
||||
for _, user := range userList {
|
||||
userIDList = append(userIDList, user.UserID)
|
||||
}
|
||||
permissionUserIDList = append(permissionUserIDList, userIDList...)
|
||||
permissionUserIDList = utils.RemoveRepeatedStringInList(permissionUserIDList)
|
||||
return permissionUserIDList
|
||||
}
|
||||
|
||||
func (s *officeServer) DeleteOneWorkMoment(_ context.Context, req *pbOffice.DeleteOneWorkMomentReq) (resp *pbOffice.DeleteOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.DeleteOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
workMoment, err := db.DB.GetWorkMomentByID(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetWorkMomentByID failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "workMoment", workMoment)
|
||||
if workMoment.UserID != req.UserID {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoment.UserID != req.WorkMomentID, delete failed", workMoment, req.WorkMomentID)
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
err = db.DB.DeleteOneWorkMoment(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DeleteOneWorkMoment", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func isUserCanSeeWorkMoment(userID string, workMoment db.WorkMoment) bool {
|
||||
if userID != workMoment.UserID {
|
||||
switch workMoment.Permission {
|
||||
case constant.WorkMomentPublic:
|
||||
return true
|
||||
case constant.WorkMomentPrivate:
|
||||
return false
|
||||
case constant.WorkMomentPermissionCanSee:
|
||||
return utils.IsContain(userID, workMoment.PermissionUserIDList)
|
||||
case constant.WorkMomentPermissionCantSee:
|
||||
return !utils.IsContain(userID, workMoment.PermissionUserIDList)
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOneWorkMomentReq) (resp *pbOffice.LikeOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.LikeOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
user, err := imdb.GetUserByUserID(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMoment, like, err := db.DB.LikeOneWorkMoment(req.UserID, user.Nickname, req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "LikeOneWorkMoment failed ", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentLikeNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: user.UserID,
|
||||
FaceURL: user.FaceURL,
|
||||
UserName: user.Nickname,
|
||||
CreateTime: int32(time.Now().Unix()),
|
||||
}
|
||||
// send notification
|
||||
if like && workMoment.UserID != req.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.CommentOneWorkMomentReq) (resp *pbOffice.CommentOneWorkMomentResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.CommentOneWorkMomentResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
commentUser, err := imdb.GetUserByUserID(req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID commentUserName failed", req.UserID, err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
var replyUserName string
|
||||
if req.ReplyUserID != "" {
|
||||
replyUserName, err = imdb.GetUserNameByUserID(req.ReplyUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserNameByUserID get replyUserName failed", req.ReplyUserID, err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
comment := &db.Comment{
|
||||
UserID: req.UserID,
|
||||
UserName: commentUser.Nickname,
|
||||
ReplyUserID: req.ReplyUserID,
|
||||
ReplyUserName: replyUserName,
|
||||
Content: req.Content,
|
||||
CreateTime: int32(time.Now().Unix()),
|
||||
}
|
||||
workMoment, err := db.DB.CommentOneWorkMoment(comment, req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CommentOneWorkMoment failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
workMomentNotificationMsg := &pbOffice.WorkMomentNotificationMsg{
|
||||
NotificationMsgType: constant.WorkMomentCommentNotification,
|
||||
WorkMomentID: workMoment.WorkMomentID,
|
||||
WorkMomentContent: workMoment.Content,
|
||||
UserID: commentUser.UserID,
|
||||
FaceURL: commentUser.FaceURL,
|
||||
UserName: commentUser.Nickname,
|
||||
ReplyUserID: comment.ReplyUserID,
|
||||
ReplyUserName: comment.ReplyUserName,
|
||||
ContentID: comment.ContentID,
|
||||
Content: comment.Content,
|
||||
CreateTime: comment.CreateTime,
|
||||
}
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "msg: ", *workMomentNotificationMsg)
|
||||
if req.UserID != workMoment.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg)
|
||||
}
|
||||
if req.ReplyUserID != "" && req.ReplyUserID != workMoment.UserID && req.ReplyUserID != req.UserID {
|
||||
msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetWorkMomentByID(_ context.Context, req *pbOffice.GetWorkMomentByIDReq) (resp *pbOffice.GetWorkMomentByIDResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetWorkMomentByIDResp{
|
||||
WorkMoment: &pbOffice.WorkMoment{},
|
||||
CommonResp: &pbOffice.CommonResp{},
|
||||
}
|
||||
workMoment, err := db.DB.GetWorkMomentByID(req.WorkMomentID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetWorkMomentByID failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
canSee := isUserCanSeeWorkMoment(req.OpUserID, *workMoment)
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), canSee, req.OpUserID, *workMoment)
|
||||
if !canSee {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "workMoments not access to user", canSee, workMoment, req.OpUserID)
|
||||
}
|
||||
if err := utils.CopyStructFields(resp.WorkMoment, workMoment); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserWorkMoments(_ context.Context, req *pbOffice.GetUserWorkMomentsReq) (resp *pbOffice.GetUserWorkMomentsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
||||
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
|
||||
var workMoments []db.WorkMoment
|
||||
if req.UserID == req.OpUserID {
|
||||
workMoments, err = db.DB.GetUserSelfWorkMoments(req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
} else {
|
||||
workMoments, err = db.DB.GetUserWorkMoments(req.OpUserID, req.UserID, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
}
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserWorkMoments failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.WorkMoments, workMoments); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) GetUserFriendWorkMoments(_ context.Context, req *pbOffice.GetUserFriendWorkMomentsReq) (resp *pbOffice.GetUserFriendWorkMomentsResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.GetUserFriendWorkMomentsResp{CommonResp: &pbOffice.CommonResp{}, WorkMoments: []*pbOffice.WorkMoment{}}
|
||||
resp.Pagination = &pbCommon.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber}
|
||||
workMoments, err := db.DB.GetUserFriendWorkMoments(req.Pagination.ShowNumber, req.Pagination.PageNumber, req.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserFriendWorkMoments", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.WorkMoments, workMoments); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) SetUserWorkMomentsLevel(_ context.Context, req *pbOffice.SetUserWorkMomentsLevelReq) (resp *pbOffice.SetUserWorkMomentsLevelResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.SetUserWorkMomentsLevelResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
if err := db.DB.SetUserWorkMomentsLevel(req.UserID, req.Level); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetUserWorkMomentsLevel failed", err.Error())
|
||||
resp.CommonResp = &pbOffice.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *officeServer) ChangeWorkMomentPermission(_ context.Context, req *pbOffice.ChangeWorkMomentPermissionReq) (resp *pbOffice.ChangeWorkMomentPermissionResp, err error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp = &pbOffice.ChangeWorkMomentPermissionResp{CommonResp: &pbOffice.CommonResp{}}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
package organization
|
||||
|
||||
import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/auth"
|
||||
rpc "Open_IM/pkg/proto/organization"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type organizationServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewServer(port int) *organizationServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &organizationServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOrganizationName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *organizationServer) Run() {
|
||||
log.NewInfo("", "organization rpc start ")
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("", "listen network success, ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
rpc.RegisterOrganizationServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("", "RegisterEtcd failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("", "organization rpc RegisterEtcd success", ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("", "organization rpc success")
|
||||
}
|
||||
|
||||
func (s *organizationServer) CreateDepartment(ctx context.Context, req *rpc.CreateDepartmentReq) (*rpc.CreateDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
department := db.Department{}
|
||||
utils.CopyStructFields(&department, req.DepartmentInfo)
|
||||
if department.DepartmentID == "" {
|
||||
department.DepartmentID = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
}
|
||||
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
|
||||
if err := imdb.CreateDepartment(&department); err != nil {
|
||||
errMsg := req.OperationID + " " + "CreateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
err, createdDepartment := imdb.GetDepartment(department.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error() + department.DepartmentID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "GetDepartment ", department.DepartmentID, *createdDepartment)
|
||||
resp := &rpc.CreateDepartmentResp{DepartmentInfo: &open_im_sdk.Department{}}
|
||||
utils.CopyStructFields(resp.DepartmentInfo, createdDepartment)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.UpdateDepartmentReq) (*rpc.UpdateDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
department := db.Department{}
|
||||
utils.CopyStructFields(&department, req.DepartmentInfo)
|
||||
|
||||
log.Debug(req.OperationID, "dst ", department, "src ", req.DepartmentInfo)
|
||||
if err := imdb.UpdateDepartment(&department, nil); err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.UpdateDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
resp := &rpc.UpdateDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
err, departmentList := imdb.GetSubDepartmentList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetSubDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "GetSubDepartmentList ", req.DepartmentID, departmentList)
|
||||
resp := &rpc.GetSubDepartmentResp{}
|
||||
for _, v := range departmentList {
|
||||
v1 := open_im_sdk.Department{}
|
||||
utils.CopyStructFields(&v1, v)
|
||||
log.Debug(req.OperationID, "src ", v, "dst ", v1)
|
||||
err, v1.MemberNum = imdb.GetDepartmentMemberNum(v1.DepartmentID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetDepartmentMemberNum failed ", err.Error(), v1.DepartmentID)
|
||||
continue
|
||||
}
|
||||
err, v1.SubDepartmentNum = imdb.GetSubDepartmentNum(v1.DepartmentID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetSubDepartmentNum failed ", err.Error(), v1.DepartmentID)
|
||||
continue
|
||||
}
|
||||
resp.DepartmentList = append(resp.DepartmentList, &v1)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) DeleteDepartment(ctx context.Context, req *rpc.DeleteDepartmentReq) (*rpc.DeleteDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
err := imdb.DeleteDepartment(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "DeleteDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, req.DepartmentID)
|
||||
return &rpc.DeleteDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "DeleteDepartment ", req.DepartmentID)
|
||||
resp := &rpc.DeleteDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) CreateOrganizationUser(ctx context.Context, req *rpc.CreateOrganizationUserReq) (*rpc.CreateOrganizationUserResp, error) {
|
||||
authReq := &pbAuth.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
||||
utils.CopyStructFields(authReq.UserInfo, req.OrganizationUser)
|
||||
authReq.OperationID = req.OperationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := pbAuth.NewAuthClient(etcdConn)
|
||||
|
||||
reply, err := client.UserRegister(context.Background(), authReq)
|
||||
if err != nil {
|
||||
errMsg := "UserRegister failed " + err.Error()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if reply.CommonResp.ErrCode != 0 {
|
||||
errMsg := "UserRegister failed " + reply.CommonResp.ErrMsg
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
organizationUser := db.OrganizationUser{}
|
||||
utils.CopyStructFields(&organizationUser, req.OrganizationUser)
|
||||
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
|
||||
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
|
||||
err = imdb.CreateOrganizationUser(&organizationUser)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, organizationUser)
|
||||
return &rpc.CreateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CreateOrganizationUser ", organizationUser)
|
||||
resp := &rpc.CreateOrganizationUserResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) UpdateOrganizationUser(ctx context.Context, req *rpc.UpdateOrganizationUserReq) (*rpc.UpdateOrganizationUserResp, error) {
|
||||
authReq := &pbAuth.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
||||
utils.CopyStructFields(authReq.UserInfo, req.OrganizationUser)
|
||||
authReq.OperationID = req.OperationID
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := pbAuth.NewAuthClient(etcdConn)
|
||||
|
||||
reply, err := client.UserRegister(context.Background(), authReq)
|
||||
if err != nil {
|
||||
errMsg := "UserRegister failed " + err.Error()
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if reply.CommonResp.ErrCode != 0 {
|
||||
errMsg := "UserRegister failed " + reply.CommonResp.ErrMsg
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
organizationUser := db.OrganizationUser{}
|
||||
utils.CopyStructFields(&organizationUser, req.OrganizationUser)
|
||||
if req.OrganizationUser.Birth != 0 {
|
||||
organizationUser.Birth = utils.UnixSecondToTime(int64(req.OrganizationUser.Birth))
|
||||
log.Debug(req.OperationID, "time: ", organizationUser.Birth, req.OrganizationUser.Birth)
|
||||
}
|
||||
|
||||
log.Debug(req.OperationID, "src ", *req.OrganizationUser, "dst ", organizationUser)
|
||||
err = imdb.UpdateOrganizationUser(&organizationUser, nil)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "CreateOrganizationUser failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, organizationUser)
|
||||
return &rpc.UpdateOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "UpdateOrganizationUser ", organizationUser)
|
||||
resp := &rpc.UpdateOrganizationUserResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) CreateDepartmentMember(ctx context.Context, req *rpc.CreateDepartmentMemberReq) (*rpc.CreateDepartmentMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
err, _ := imdb.GetOrganizationUser(req.DepartmentMember.UserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + req.DepartmentMember.UserID + " is not exist"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
departmentMember := db.DepartmentMember{}
|
||||
utils.CopyStructFields(&departmentMember, req.DepartmentMember)
|
||||
log.Debug(req.OperationID, "src ", *req.DepartmentMember, "dst ", departmentMember)
|
||||
err = imdb.CreateDepartmentMember(&departmentMember)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "CreateDepartmentMember failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, departmentMember)
|
||||
return &rpc.CreateDepartmentMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "UpdateOrganizationUser ", departmentMember)
|
||||
|
||||
resp := &rpc.CreateDepartmentMemberResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) GetUserInDepartmentByUserID(userID string, operationID string) (*open_im_sdk.UserInDepartment, error) {
|
||||
err, organizationUser := imdb.GetOrganizationUser(userID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetOrganizationUser failed")
|
||||
}
|
||||
err, departmentMemberList := imdb.GetUserInDepartment(userID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "GetUserInDepartment failed")
|
||||
}
|
||||
log.Debug(operationID, "GetUserInDepartment ", departmentMemberList)
|
||||
resp := &open_im_sdk.UserInDepartment{OrganizationUser: &open_im_sdk.OrganizationUser{}}
|
||||
utils.CopyStructFields(resp.OrganizationUser, organizationUser)
|
||||
for _, v := range departmentMemberList {
|
||||
v1 := open_im_sdk.DepartmentMember{}
|
||||
utils.CopyStructFields(&v1, v)
|
||||
log.Debug(operationID, "DepartmentMember src ", v, "dst ", v1)
|
||||
resp.DepartmentMemberList = append(resp.DepartmentMemberList, &v1)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) GetUserInDepartment(ctx context.Context, req *rpc.GetUserInDepartmentReq) (*rpc.GetUserInDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
r, err := s.GetUserInDepartmentByUserID(req.UserID, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "GetUserInDepartmentByUserID failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, req.UserID)
|
||||
return &rpc.GetUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "GetUserInDepartmentByUserID success ", req.UserID, r)
|
||||
resp := rpc.GetUserInDepartmentResp{UserInDepartment: &open_im_sdk.UserInDepartment{OrganizationUser: &open_im_sdk.OrganizationUser{}}}
|
||||
resp.UserInDepartment.DepartmentMemberList = r.DepartmentMemberList
|
||||
resp.UserInDepartment.OrganizationUser = r.OrganizationUser
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) UpdateUserInDepartment(ctx context.Context, req *rpc.UpdateUserInDepartmentReq) (*rpc.UpdateUserInDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
departmentMember := &db.DepartmentMember{}
|
||||
utils.CopyStructFields(departmentMember, req.DepartmentMember)
|
||||
log.Debug(req.OperationID, "dst ", departmentMember, "src ", req.DepartmentMember)
|
||||
err := imdb.UpdateUserInDepartment(departmentMember, nil)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "UpdateUserInDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, *departmentMember)
|
||||
return &rpc.UpdateUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
resp := &rpc.UpdateUserInDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) DeleteUserInDepartment(ctx context.Context, req *rpc.DeleteUserInDepartmentReq) (*rpc.DeleteUserInDepartmentResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.DeleteUserInDepartmentResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
err := imdb.DeleteUserInDepartment(req.DepartmentID, req.UserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "DeleteUserInDepartment failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, req.DepartmentID, req.UserID)
|
||||
return &rpc.DeleteUserInDepartmentResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "DeleteUserInDepartment success ", req.DepartmentID, req.UserID)
|
||||
resp := &rpc.DeleteUserInDepartmentResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rpc.DeleteOrganizationUserReq) (*rpc.DeleteOrganizationUserResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.DeleteOrganizationUserResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
err := imdb.DeleteOrganizationUser(req.UserID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + "DeleteOrganizationUser failed " + err.Error()
|
||||
log.Error(req.OperationID, errMsg, req.UserID)
|
||||
return &rpc.DeleteOrganizationUserResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "DeleteOrganizationUser success ", req.UserID)
|
||||
resp := &rpc.DeleteOrganizationUserResp{}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", *resp)
|
||||
chat.OrganizationNotificationToAll(req.OpUserID, req.OperationID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
err, departmentMemberList := imdb.GetDepartmentMemberList(req.DepartmentID)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " " + req.OpUserID + " is not app manager"
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &rpc.GetDepartmentMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
log.Debug(req.OperationID, "GetDepartmentMemberList ", departmentMemberList)
|
||||
resp := rpc.GetDepartmentMemberResp{}
|
||||
for _, v := range departmentMemberList {
|
||||
err, organizationUser := imdb.GetOrganizationUser(v.UserID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetOrganizationUser failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
respOrganizationUser := &open_im_sdk.OrganizationUser{}
|
||||
respDepartmentMember := &open_im_sdk.DepartmentMember{}
|
||||
|
||||
utils.CopyStructFields(respOrganizationUser, organizationUser)
|
||||
utils.CopyStructFields(respDepartmentMember, &v)
|
||||
userDepartmentMember := open_im_sdk.UserDepartmentMember{OrganizationUser: respOrganizationUser, DepartmentMember: respDepartmentMember}
|
||||
|
||||
log.Debug(req.OperationID, "GetUserInDepartmentByUserID success ", userDepartmentMember)
|
||||
resp.UserDepartmentMemberList = append(resp.UserDepartmentMemberList, &userDepartmentMember)
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp)
|
||||
return &resp, nil
|
||||
}
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
//"context"
|
||||
errors "Open_IM/pkg/common/http"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
errors "Open_IM/pkg/common/http"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@@ -35,7 +35,7 @@ type statisticsServer struct {
|
||||
}
|
||||
|
||||
func NewStatisticsServer(port int) *statisticsServer {
|
||||
log.NewPrivateLog("Statistics")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &statisticsServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
||||
@@ -164,7 +164,7 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
|
||||
}
|
||||
// month
|
||||
case !isInOneMonth(from, to):
|
||||
if to.Sub(from) < time.Hour * 24 * 30 {
|
||||
if to.Sub(from) < time.Hour*24*30 {
|
||||
for i := 0; ; i++ {
|
||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||
@@ -251,7 +251,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||
}
|
||||
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
||||
Date: v[0].String(),
|
||||
Date: v[0].String(),
|
||||
Num: num,
|
||||
}
|
||||
}(wg, i, v)
|
||||
|
||||
+85
-10
@@ -32,7 +32,7 @@ type userServer struct {
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
@@ -72,6 +72,30 @@ func (s *userServer) Run() {
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func syncPeerUserConversation(conversation *pbUser.Conversation, operationID string) error {
|
||||
peerUserConversation := db.Conversation{
|
||||
OwnerUserID: conversation.UserID,
|
||||
ConversationID: utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType),
|
||||
ConversationType: constant.SingleChatType,
|
||||
UserID: conversation.OwnerUserID,
|
||||
GroupID: "",
|
||||
RecvMsgOpt: 0,
|
||||
UnreadCount: 0,
|
||||
DraftTextTime: 0,
|
||||
IsPinned: false,
|
||||
IsPrivateChat: conversation.IsPrivateChat,
|
||||
AttachedInfo: "",
|
||||
Ex: "",
|
||||
}
|
||||
err := imdb.PeerUserSetConversation(peerUserConversation)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
return err
|
||||
}
|
||||
chat.ConversationSetPrivateNotification(operationID, conversation.OwnerUserID, conversation.UserID, conversation.IsPrivateChat)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||
var userInfoList []*sdkws.UserInfo
|
||||
@@ -96,12 +120,16 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
|
||||
|
||||
func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.BatchSetConversationsReq) (*pbUser.BatchSetConversationsResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
if req.NotificationType == 0 {
|
||||
req.NotificationType = constant.ConversationOptChangeNotification
|
||||
}
|
||||
resp := &pbUser.BatchSetConversationsResp{}
|
||||
for _, v := range req.Conversations {
|
||||
conversation := db.Conversation{}
|
||||
if err := utils.CopyStructFields(&conversation, v); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), v.String(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
//redis op
|
||||
if err := db.DB.SetSingleConversationRecvMsgOpt(req.OwnerUserID, v.ConversationID, v.RecvMsgOpt); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "cache failed, rpc return", err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
@@ -113,8 +141,14 @@ func (s *userServer) BatchSetConversations(ctx context.Context, req *pbUser.Batc
|
||||
continue
|
||||
}
|
||||
resp.Success = append(resp.Success, v.ConversationID)
|
||||
// if is set private chat operation,then peer user need to sync and set tips\
|
||||
if v.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
|
||||
if err := syncPeerUserConversation(v, req.OperationID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
||||
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
@@ -174,6 +208,22 @@ func (s *userServer) GetConversations(ctx context.Context, req *pbUser.GetConver
|
||||
func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConversationReq) (*pbUser.SetConversationResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &pbUser.SetConversationResp{}
|
||||
if req.NotificationType == 0 {
|
||||
req.NotificationType = constant.ConversationOptChangeNotification
|
||||
}
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.Conversation.GroupID, err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed && !req.Conversation.IsNotInGroup {
|
||||
errMsg := "group status is dismissed"
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
var conversation db.Conversation
|
||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", *req.Conversation, err.Error())
|
||||
@@ -189,7 +239,17 @@ func (s *userServer) SetConversation(ctx context.Context, req *pbUser.SetConvers
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.Conversation.OwnerUserID)
|
||||
// notification
|
||||
if req.Conversation.ConversationType == constant.SingleChatType && req.NotificationType == constant.ConversationPrivateChatNotification {
|
||||
//sync peer user conversation if conversation is singleChatType
|
||||
if err := syncPeerUserConversation(req.Conversation, req.OperationID); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "syncPeerUserConversation", err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
} else {
|
||||
chat.ConversationChangeNotification(req.OperationID, req.Conversation.OwnerUserID)
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
@@ -207,13 +267,24 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
stringList := strings.Split(req.ConversationID, "_")
|
||||
if len(stringList) > 1 {
|
||||
switch stringList[0] {
|
||||
case "single_":
|
||||
conversation.UserID = stringList[1]
|
||||
conversation.ConversationType = constant.SingleChatType
|
||||
case "group":
|
||||
conversation.GroupID = stringList[1]
|
||||
conversation.ConversationType = constant.GroupChatType
|
||||
}
|
||||
}
|
||||
err := imdb.SetRecvMsgOpt(conversation)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
|
||||
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
|
||||
return resp, nil
|
||||
}
|
||||
chat.SetConversationNotification(req.OperationID, req.OwnerUserID)
|
||||
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
resp.CommonResp = &pbUser.CommonResp{}
|
||||
return resp, nil
|
||||
@@ -221,8 +292,8 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsManagerUserID false ", req.OpUserID)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, FailedUserIDList: req.DeleteUserIDList}, nil
|
||||
}
|
||||
var common pbUser.CommonResp
|
||||
@@ -242,8 +313,8 @@ func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq)
|
||||
|
||||
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsManagerUserID false ", req.OpUserID)
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectAllUserID()
|
||||
@@ -258,8 +329,8 @@ func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq
|
||||
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.NewInfo(req.OperationID, "AccountCheck args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsManagerUserID false ", req.OpUserID)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectSomeUserID(req.CheckUserIDList)
|
||||
@@ -318,6 +389,10 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
}
|
||||
|
||||
//etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
//client := pbFriend.NewFriendClient(etcdConn)
|
||||
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID)
|
||||
log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
|
||||
@@ -76,7 +76,7 @@ func Test_ParseToken(t *testing.T) {
|
||||
uid := "1"
|
||||
platform := int32(1)
|
||||
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
||||
claims, err := token_verify.ParseToken(tokenString)
|
||||
claims, err := token_verify.ParseToken(tokenString, "")
|
||||
if err == nil {
|
||||
assert.Equal(t, claims.UID, uid)
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ type SetReceiveMessageOptResp struct {
|
||||
|
||||
type Conversation struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
ConversationType int32 `json:"conversationType"`
|
||||
ConversationID string `json:"conversationID" binding:"required"`
|
||||
ConversationType int32 `json:"conversationType" binding:"required"`
|
||||
UserID string `json:"userID"`
|
||||
GroupID string `json:"groupID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
@@ -43,23 +43,36 @@ type Conversation struct {
|
||||
DraftTextTime int64 `json:"draftTextTime"`
|
||||
IsPinned bool `json:"isPinned" binding:"omitempty"`
|
||||
IsPrivateChat bool `json:"isPrivateChat"`
|
||||
GroupAtType int32 `json:"groupAtType"`
|
||||
IsNotInGroup bool `json:"isNotInGroup"`
|
||||
AttachedInfo string `json:"attachedInfo"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type SetConversationReq struct {
|
||||
Conversation
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetConversationResp struct {
|
||||
CommResp
|
||||
}
|
||||
type ModifyConversationFieldReq struct {
|
||||
Conversation
|
||||
FieldType int32 `json:"fieldType" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type ModifyConversationFieldResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type BatchSetConversationsReq struct {
|
||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type BatchSetConversationsResp struct {
|
||||
@@ -103,10 +116,11 @@ type GetConversationsResp struct {
|
||||
}
|
||||
|
||||
type SetRecvMsgOptReq struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt" binding:"omitempty,oneof=0 1 2"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
NotificationType int32 `json:"notificationType"`
|
||||
}
|
||||
|
||||
type SetRecvMsgOptResp struct {
|
||||
|
||||
@@ -21,7 +21,7 @@ type ImportFriendReq struct {
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type UserIDResult struct {
|
||||
UserID string `json:"userID""`
|
||||
UserID string `json:"userID"`
|
||||
Result int32 `json:"result"`
|
||||
}
|
||||
type ImportFriendResp struct {
|
||||
|
||||
@@ -185,3 +185,49 @@ type DismissGroupReq struct {
|
||||
type DismissGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type MuteGroupMemberReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
MutedSeconds uint32 `json:"mutedSeconds" binding:"required"`
|
||||
}
|
||||
type MuteGroupMemberResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CancelMuteGroupMemberReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
}
|
||||
type CancelMuteGroupMemberResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type MuteGroupReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
}
|
||||
type MuteGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CancelMuteGroupReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
}
|
||||
type CancelMuteGroupResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetGroupMemberNicknameReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
Nickname string `json:"nickname"`
|
||||
}
|
||||
|
||||
type SetGroupMemberNicknameResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ type MiniostorageCredentialResp struct {
|
||||
}
|
||||
|
||||
type MinioUploadFileReq struct {
|
||||
OperationID string `form:"operationID"`
|
||||
FileType int `form:"fileType"`
|
||||
OperationID string `form:"operationID" binding:"required"`
|
||||
FileType int `form:"fileType" binding:"required"`
|
||||
}
|
||||
|
||||
type MinioUploadFileResp struct {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package base_info
|
||||
|
||||
import (
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
||||
)
|
||||
|
||||
type GetUserTagsReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tags []*pbOffice.Tag `json:"tags"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateTagReq struct {
|
||||
TagName string `json:"tagName" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type CreateTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SetTagReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
NewName string `json:"newName"`
|
||||
IncreaseUserIDList []string `json:"increaseUserIDList"`
|
||||
ReduceUserIDList []string `json:"reduceUserIDList"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetTagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type SendMsg2TagReq struct {
|
||||
TagList []string `json:"tagList"`
|
||||
UserList []string `json:"userList"`
|
||||
GroupList []string `json:"groupList"`
|
||||
|
||||
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SendMsg2TagResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetTagSendLogsReq struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetTagSendLogsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Logs []*pbOffice.TagSendLog `json:"logs"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDReq struct {
|
||||
TagID string `json:"tagID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserTagByIDResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
Tag *pbOffice.Tag `json:"tag"`
|
||||
} `json:"data"`
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package base_info
|
||||
|
||||
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
|
||||
type CreateDepartmentReq struct {
|
||||
*open_im_sdk.Department
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type CreateDepartmentResp struct {
|
||||
CommResp
|
||||
Department *open_im_sdk.Department `json:"-"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type UpdateDepartmentReq struct {
|
||||
*open_im_sdk.Department
|
||||
DepartmentID string `json:"departmentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type UpdateDepartmentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetSubDepartmentReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
DepartmentID string `json:"departmentID" binding:"required"`
|
||||
}
|
||||
type GetSubDepartmentResp struct {
|
||||
CommResp
|
||||
DepartmentList []*open_im_sdk.Department `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteDepartmentReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
DepartmentID string `json:"departmentID" binding:"required"`
|
||||
}
|
||||
type DeleteDepartmentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CreateOrganizationUserReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
*open_im_sdk.OrganizationUser
|
||||
}
|
||||
type CreateOrganizationUserResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type UpdateOrganizationUserReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
*open_im_sdk.OrganizationUser
|
||||
}
|
||||
type UpdateOrganizationUserResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CreateDepartmentMemberReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
*open_im_sdk.DepartmentMember
|
||||
}
|
||||
|
||||
type CreateDepartmentMemberResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetUserInDepartmentReq struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type GetUserInDepartmentResp struct {
|
||||
CommResp
|
||||
UserInDepartment *open_im_sdk.UserInDepartment `json:"-"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type UpdateUserInDepartmentReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
*open_im_sdk.DepartmentMember
|
||||
}
|
||||
type UpdateUserInDepartmentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteOrganizationUserReq struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type DeleteOrganizationUserResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetDepartmentMemberReq struct {
|
||||
DepartmentID string `json:"departmentID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type GetDepartmentMemberResp struct {
|
||||
CommResp
|
||||
UserInDepartmentList []*open_im_sdk.UserDepartmentMember `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteUserInDepartmentReq struct {
|
||||
DepartmentID string `json:"departmentID" binding:"required"`
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type DeleteUserInDepartmentResp struct {
|
||||
CommResp
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
@@ -32,3 +32,21 @@ type GetSelfUserInfoResp struct {
|
||||
UserInfo *open_im_sdk.UserInfo `json:"-"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetFriendIDListFromCacheReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetFriendIDListFromCacheResp struct {
|
||||
CommResp
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
}
|
||||
|
||||
type GetBlackIDListFromCacheReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetBlackIDListFromCacheResp struct {
|
||||
CommResp
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package base_info
|
||||
|
||||
import "Open_IM/pkg/proto/office"
|
||||
|
||||
type CreateOneWorkMomentReq struct {
|
||||
office.CreateOneWorkMomentReq
|
||||
}
|
||||
|
||||
type CreateOneWorkMomentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteOneWorkMomentReq struct {
|
||||
office.DeleteOneWorkMomentReq
|
||||
}
|
||||
|
||||
type DeleteOneWorkMomentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type LikeOneWorkMomentReq struct {
|
||||
office.LikeOneWorkMomentReq
|
||||
}
|
||||
|
||||
type LikeOneWorkMomentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type CommentOneWorkMomentReq struct {
|
||||
office.CommentOneWorkMomentReq
|
||||
}
|
||||
|
||||
type CommentOneWorkMomentResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type WorkMomentsUserCommonReq struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetWorkMomentByIDReq struct {
|
||||
office.GetWorkMomentByIDReq
|
||||
}
|
||||
|
||||
type WorkMoment struct {
|
||||
WorkMomentID string `json:"workMomentID"`
|
||||
UserID string `json:"userID"`
|
||||
Content string `json:"content"`
|
||||
LikeUserList []*WorkMomentUser `json:"likeUsers"`
|
||||
Comments []*Comment `json:"comments"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
UserName string `json:"userName"`
|
||||
AtUserList []*WorkMomentUser `json:"atUsers"`
|
||||
CreateTime int32 `json:"createTime"`
|
||||
}
|
||||
|
||||
type WorkMomentUser struct {
|
||||
UserID string `json:"userID"`
|
||||
UserName string `json:"userName"`
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
UserID string `json:"userID"`
|
||||
UserName string `json:"userName"`
|
||||
ReplyUserID string `json:"replyUserID"`
|
||||
ReplyUserName string `json:"replyUserName"`
|
||||
ContentID string `json:"contentID"`
|
||||
Content string `json:"content"`
|
||||
CreateTime int32 `json:"createTime"`
|
||||
}
|
||||
|
||||
type GetWorkMomentByIDResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoment *WorkMoment `json:"workMoment"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserWorkMomentsReq struct {
|
||||
WorkMomentsUserCommonReq
|
||||
UserID string `json:"userID"`
|
||||
}
|
||||
|
||||
type GetUserWorkMomentsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoments []*WorkMoment `json:"workMoments"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserFriendWorkMomentsReq struct {
|
||||
WorkMomentsUserCommonReq
|
||||
}
|
||||
|
||||
type GetUserFriendWorkMomentsResp struct {
|
||||
CommResp
|
||||
Data struct {
|
||||
WorkMoments []*WorkMoment `json:"workMoments"`
|
||||
CurrentPage int32 `json:"currentPage"`
|
||||
ShowNumber int32 `json:"showNumber"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type SetUserWorkMomentsLevelReq struct {
|
||||
office.SetUserWorkMomentsLevelReq
|
||||
}
|
||||
|
||||
type SetUserWorkMomentsLevelResp struct {
|
||||
CommResp
|
||||
}
|
||||
+13
-15
@@ -8,7 +8,7 @@ type GroupResponse struct {
|
||||
CreateTime string `json:"create_time"`
|
||||
IsBanChat bool `json:"is_ban_chat"`
|
||||
IsBanPrivateChat bool `json:"is_ban_private_chat"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
}
|
||||
|
||||
type GetGroupByIdRequest struct {
|
||||
@@ -63,7 +63,6 @@ type SetGroupMemberRequest struct {
|
||||
}
|
||||
|
||||
type SetGroupMemberRespones struct {
|
||||
|
||||
}
|
||||
|
||||
type BanGroupChatRequest struct {
|
||||
@@ -88,7 +87,7 @@ type DeleteGroupResponse struct {
|
||||
}
|
||||
|
||||
type GetGroupMembersRequest struct {
|
||||
GroupId string `form:"group_id" binding:"required"`
|
||||
GroupId string `form:"group_id" binding:"required"`
|
||||
UserName string `form:"user_name"`
|
||||
RequestPagination
|
||||
}
|
||||
@@ -96,24 +95,24 @@ type GetGroupMembersRequest struct {
|
||||
type GroupMemberResponse struct {
|
||||
MemberPosition int `json:"member_position"`
|
||||
MemberNickName string `json:"member_nick_name"`
|
||||
MemberId string `json:"member_id"`
|
||||
MemberId string `json:"member_id"`
|
||||
JoinTime string `json:"join_time"`
|
||||
}
|
||||
|
||||
type GetGroupMembersResponse struct {
|
||||
GroupMembers []GroupMemberResponse `json:"group_members"`
|
||||
GroupMembers []GroupMemberResponse `json:"group_members"`
|
||||
ResponsePagination
|
||||
MemberNums int `json:"member_nums"`
|
||||
}
|
||||
|
||||
type GroupMemberRequest struct {
|
||||
GroupId string `json:"group_id" binding:"required"`
|
||||
GroupId string `json:"group_id" binding:"required"`
|
||||
Members []string `json:"members" binding:"required"`
|
||||
}
|
||||
|
||||
type GroupMemberOperateResponse struct {
|
||||
Success []string `json:"success"`
|
||||
Failed []string `json:"failed"`
|
||||
Failed []string `json:"failed"`
|
||||
}
|
||||
|
||||
type AddGroupMembersRequest struct {
|
||||
@@ -128,19 +127,18 @@ type RemoveGroupMembersRequest struct {
|
||||
GroupMemberRequest
|
||||
}
|
||||
|
||||
type RemoveGroupMembersResponse struct{
|
||||
type RemoveGroupMembersResponse struct {
|
||||
GroupMemberOperateResponse
|
||||
}
|
||||
|
||||
type AlterGroupInfoRequest struct {
|
||||
GroupID string `json:"group_id"`
|
||||
GroupName string `json:"group_name"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
GroupType int `json:"group_type"`
|
||||
GroupID string `json:"group_id"`
|
||||
GroupName string `json:"group_name"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
ProfilePhoto string `json:"profile_photo"`
|
||||
GroupType int `json:"group_type"`
|
||||
}
|
||||
|
||||
type AlterGroupInfoResponse struct {
|
||||
|
||||
}
|
||||
|
||||
+89
-10
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -45,12 +44,25 @@ type config struct {
|
||||
SecretID string `yaml:"secretID"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
Ali struct {
|
||||
RegionID string `yaml:"regionID"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
StsEndpoint string `yaml:"stsEndpoint"`
|
||||
OssEndpoint string `yaml:"ossEndpoint"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
FinalHost string `yaml:"finalHost"`
|
||||
StsDurationSeconds int64 `yaml:"stsDurationSeconds"`
|
||||
OssRoleArn string `yaml:"OssRoleArn"`
|
||||
}
|
||||
Minio struct {
|
||||
Bucket string `yaml:"bucket"`
|
||||
Location string `yaml:"location"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
SecretAccessKey string `yaml:"secretAccessKey"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
Location string `yaml:"location"`
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
SecretAccessKey string `yaml:"secretAccessKey"`
|
||||
EndpointInner string `yaml:"endpointInner"`
|
||||
EndpointInnerEnable bool `yaml:"endpointInnerEnable"`
|
||||
} `yaml:"minio"`
|
||||
}
|
||||
|
||||
@@ -66,6 +78,7 @@ type config struct {
|
||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||
}
|
||||
Mongo struct {
|
||||
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
|
||||
DBAddress []string `yaml:"dbAddress"`
|
||||
DBDirect bool `yaml:"dbDirect"`
|
||||
DBTimeout int `yaml:"dbTimeout"`
|
||||
@@ -103,6 +116,10 @@ type config struct {
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImMessageCMSName string `yaml:"openImMessageCMSName"`
|
||||
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
|
||||
OpenImOfficeName string `yaml:"openImOfficeName"`
|
||||
OpenImOrganizationName string `yaml:"openImOrganizationName"`
|
||||
OpenImConversationName string `yaml:"openImConversationName"`
|
||||
OpenImCacheName string `yaml:"openImCacheName"`
|
||||
}
|
||||
Etcd struct {
|
||||
EtcdSchema string `yaml:"etcdSchema"`
|
||||
@@ -140,18 +157,28 @@ type config struct {
|
||||
AccessID string `yaml:"accessID"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
Enable bool `yaml:"enable"`
|
||||
}
|
||||
Jpns struct {
|
||||
AppKey string `yaml:"appKey"`
|
||||
MasterSecret string `yaml:"masterSecret"`
|
||||
PushUrl string `yaml:"pushUrl"`
|
||||
PushIntent string `yaml:"pushIntent"`
|
||||
Enable bool `yaml:"enable"`
|
||||
}
|
||||
Getui struct {
|
||||
PushUrl string `yaml:"pushUrl"`
|
||||
AppKey string `yaml:"appKey"`
|
||||
Enable bool `yaml:"enable"`
|
||||
Intent string `yaml:"intent"`
|
||||
MasterSecret string `yaml:"masterSecret"`
|
||||
}
|
||||
}
|
||||
Manager struct {
|
||||
AppManagerUid []string `yaml:"appManagerUid"`
|
||||
Secrets []string `yaml:"secrets"`
|
||||
}
|
||||
|
||||
Kafka struct {
|
||||
Ws2mschat struct {
|
||||
Addr []string `yaml:"addr"`
|
||||
@@ -167,9 +194,11 @@ type config struct {
|
||||
MsgToPush string `yaml:"msgToPush"`
|
||||
}
|
||||
}
|
||||
Secret string `yaml:"secret"`
|
||||
MultiLoginPolicy int `yaml:"multiloginpolicy"`
|
||||
TokenPolicy struct {
|
||||
Secret string `yaml:"secret"`
|
||||
MultiLoginPolicy int `yaml:"multiloginpolicy"`
|
||||
ChatPersistenceMysql bool `yaml:"chatPersistenceMysql"`
|
||||
|
||||
TokenPolicy struct {
|
||||
AccessSecret string `yaml:"accessSecret"`
|
||||
AccessExpire int64 `yaml:"accessExpire"`
|
||||
}
|
||||
@@ -257,6 +286,40 @@ type config struct {
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupDismissed"`
|
||||
|
||||
GroupMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMuted"`
|
||||
|
||||
GroupCancelMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupCancelMuted"`
|
||||
|
||||
GroupMemberMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMemberMuted"`
|
||||
|
||||
GroupMemberCancelMuted struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMemberCancelMuted"`
|
||||
GroupMemberInfoSet struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"groupMemberInfoSet"`
|
||||
OrganizationChanged struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"organizationChanged"`
|
||||
|
||||
////////////////////////user///////////////////////
|
||||
UserInfoUpdated struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
@@ -313,6 +376,19 @@ type config struct {
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"conversationOptUpdate"`
|
||||
ConversationSetPrivate struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips struct {
|
||||
OpenTips string `yaml:"openTips"`
|
||||
CloseTips string `yaml:"closeTips"`
|
||||
} `yaml:"defaultTips"`
|
||||
} `yaml:"conversationSetPrivate"`
|
||||
WorkMomentsNotification struct {
|
||||
Conversation PConversation `yaml:"conversation"`
|
||||
OfflinePush POfflinePush `yaml:"offlinePush"`
|
||||
DefaultTips PDefaultTips `yaml:"defaultTips"`
|
||||
} `yaml:"workMomentsNotification"`
|
||||
}
|
||||
Demo struct {
|
||||
Port []int `yaml:"openImDemoPort"`
|
||||
@@ -332,6 +408,10 @@ type config struct {
|
||||
SmtpPort int `yaml:"smtpPort"`
|
||||
}
|
||||
}
|
||||
Rtc struct {
|
||||
Port int `yaml:"port"`
|
||||
Address string `yaml:"address"`
|
||||
} `yaml:"rtc"`
|
||||
}
|
||||
type PConversation struct {
|
||||
ReliabilityLevel int `yaml:"reliabilityLevel"`
|
||||
@@ -371,5 +451,4 @@ func init() {
|
||||
if err = yaml.Unmarshal(bytes, &Config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
fmt.Println("load config: ", Config)
|
||||
}
|
||||
|
||||
@@ -56,14 +56,13 @@ const (
|
||||
FriendRemarkSetNotification = 1206 //set_friend_remark?
|
||||
BlackAddedNotification = 1207 //add_black
|
||||
BlackDeletedNotification = 1208 //remove_black
|
||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||
|
||||
ConversationOptChangeNotification = 1300 // change conversation opt
|
||||
|
||||
UserNotificationBegin = 1301
|
||||
UserInfoUpdatedNotification = 1303 //SetSelfInfoTip = 204
|
||||
ConversationNotification = 1307
|
||||
ConversationNotNotification = 1308
|
||||
ConversationDefault = 0
|
||||
UserNotificationEnd = 1399
|
||||
OANotification = 1400
|
||||
|
||||
GroupNotificationBegin = 1500
|
||||
|
||||
@@ -78,11 +77,24 @@ const (
|
||||
MemberInvitedNotification = 1509
|
||||
MemberEnterNotification = 1510
|
||||
GroupDismissedNotification = 1511
|
||||
GroupMemberMutedNotification = 1512
|
||||
GroupMemberCancelMutedNotification = 1513
|
||||
GroupMutedNotification = 1514
|
||||
GroupCancelMutedNotification = 1515
|
||||
GroupMemberInfoSetNotification = 1516
|
||||
|
||||
SignalingNotificationBegin = 1600
|
||||
SignalingNotification = 1601
|
||||
SignalingNotificationEnd = 1699
|
||||
NotificationEnd = 2000
|
||||
|
||||
ConversationPrivateChatNotification = 1701
|
||||
|
||||
OrganizationChangedNotification = 1801
|
||||
|
||||
WorkMomentNotificationBegin = 1900
|
||||
WorkMomentNotification = 1901
|
||||
|
||||
NotificationEnd = 2000
|
||||
|
||||
//status
|
||||
MsgNormal = 1
|
||||
@@ -95,6 +107,8 @@ const (
|
||||
//SessionType
|
||||
SingleChatType = 1
|
||||
GroupChatType = 2
|
||||
|
||||
NotificationChatType = 4
|
||||
//token
|
||||
NormalToken = 0
|
||||
InValidToken = 1
|
||||
@@ -122,17 +136,20 @@ const (
|
||||
ReceiveNotNotifyMessage = 2
|
||||
|
||||
//OptionsKey
|
||||
IsHistory = "history"
|
||||
IsPersistent = "persistent"
|
||||
IsOfflinePush = "offlinePush"
|
||||
IsUnreadCount = "unreadCount"
|
||||
IsConversationUpdate = "conversationUpdate"
|
||||
IsSenderSync = "senderSync"
|
||||
IsHistory = "history"
|
||||
IsPersistent = "persistent"
|
||||
IsOfflinePush = "offlinePush"
|
||||
IsUnreadCount = "unreadCount"
|
||||
IsConversationUpdate = "conversationUpdate"
|
||||
IsSenderSync = "senderSync"
|
||||
IsNotPrivate = "notPrivate"
|
||||
IsSenderConversationUpdate = "senderConversationUpdate"
|
||||
|
||||
//GroupStatus
|
||||
GroupOk = 0
|
||||
GroupBanChat = 1
|
||||
GroupStatusDismissed = 2
|
||||
GroupStatusMuted = 3
|
||||
|
||||
GroupBaned = 3
|
||||
GroupBanPrivateChat = 4
|
||||
@@ -166,6 +183,24 @@ const (
|
||||
OtherType = 1
|
||||
VideoType = 2
|
||||
ImageType = 3
|
||||
|
||||
// workMoment permission
|
||||
WorkMomentPublic = 0
|
||||
WorkMomentPrivate = 1
|
||||
WorkMomentPermissionCanSee = 2
|
||||
WorkMomentPermissionCantSee = 3
|
||||
|
||||
// workMoment sdk notification type
|
||||
WorkMomentCommentNotification = 0
|
||||
WorkMomentLikeNotification = 1
|
||||
WorkMomentAtUserNotification = 2
|
||||
)
|
||||
const (
|
||||
AtAllString = "AtAllTag"
|
||||
AtNormal = 0
|
||||
AtMe = 1
|
||||
AtAll = 2
|
||||
AtAllAtMe = 3
|
||||
)
|
||||
|
||||
var ContentType2PushContent = map[int64]string{
|
||||
@@ -179,6 +214,16 @@ var ContentType2PushContent = map[int64]string{
|
||||
Common: "你收到一条新消息",
|
||||
}
|
||||
|
||||
const (
|
||||
FieldRecvMsgOpt = 1
|
||||
FieldIsPinned = 2
|
||||
FieldAttachedInfo = 3
|
||||
FieldIsPrivateChat = 4
|
||||
FieldGroupAtType = 5
|
||||
FieldIsNotInGroup = 6
|
||||
FieldEx = 7
|
||||
)
|
||||
|
||||
const (
|
||||
AppOrdinaryUsers = 1
|
||||
AppAdmin = 2
|
||||
@@ -206,7 +251,7 @@ const (
|
||||
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
||||
|
||||
func GroupIsBanChat(status int32) bool {
|
||||
if status != GroupBanChat {
|
||||
if status != GroupStatusMuted {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -220,3 +265,5 @@ func GroupIsBanPrivateChat(status int32) bool {
|
||||
}
|
||||
|
||||
const BigVersion = "v3"
|
||||
|
||||
const LogFileName = "OpenIM.log"
|
||||
|
||||
@@ -51,7 +51,8 @@ var (
|
||||
|
||||
ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()}
|
||||
ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()}
|
||||
ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()}
|
||||
ErrArgs = ErrInfo{ErrCode: 803, ErrMsg: ArgsMsg.Error()}
|
||||
ErrStatus = ErrInfo{ErrCode: 804, ErrMsg: StatusMsg.Error()}
|
||||
ErrCallback = ErrInfo{ErrCode: 809, ErrMsg: CallBackMsg.Error()}
|
||||
)
|
||||
|
||||
@@ -64,6 +65,7 @@ var (
|
||||
TokenUnknownMsg = errors.New("couldn't handle this token")
|
||||
TokenUserKickedMsg = errors.New("user has been kicked")
|
||||
AccessMsg = errors.New("no permission")
|
||||
StatusMsg = errors.New("status is abnormal")
|
||||
DBMsg = errors.New("db failed")
|
||||
ArgsMsg = errors.New("args failed")
|
||||
CallBackMsg = errors.New("callback failed")
|
||||
|
||||
+69
-39
@@ -2,7 +2,9 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
||||
//"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@@ -33,7 +35,7 @@ func key(dbAddress, dbName string) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
//var mgoSession *mgo.Session
|
||||
//log.NewPrivateLog(constant.LogFileName)
|
||||
var mongoClient *mongo.Client
|
||||
var err1 error
|
||||
//mysql init
|
||||
@@ -41,53 +43,81 @@ func init() {
|
||||
// mongo init
|
||||
// "mongodb://sysop:moon@localhost/records"
|
||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
|
||||
if config.Config.Mongo.DBUri != "" {
|
||||
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
||||
uri = config.Config.Mongo.DBUri
|
||||
} else {
|
||||
if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" {
|
||||
uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0],
|
||||
config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize)
|
||||
} else {
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
}
|
||||
}
|
||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||
fmt.Println(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
if err1 != nil {
|
||||
log.NewError(" mongo.Connect retry failed, panic", err.Error(), uri)
|
||||
fmt.Println(" mongo.Connect retry failed, panic", err.Error(), uri)
|
||||
panic(err1.Error())
|
||||
}
|
||||
}
|
||||
log.NewInfo("0", utils.GetSelfFuncName(), "mongo driver client init success")
|
||||
fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success: ", uri)
|
||||
// mongodb create index
|
||||
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
|
||||
dataBase := mongoClient.Database(config.Config.Mongo.DBDatabase)
|
||||
|
||||
cSendLogModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
},
|
||||
}
|
||||
result, err := dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cChatModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"uid": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cChat).Indexes().CreateMany(context.Background(), cChatModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cChatModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cWorkMomentModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"work_moment_id": -1},
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cTagModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"tag_id": -1},
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModels, opts)
|
||||
if err != nil {
|
||||
//fmt.Println("mongodb create cTagModels failed", result, err.Error())
|
||||
}
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
//mgoDailInfo := &mgo.DialInfo{
|
||||
// Addrs: config.Config.Mongo.DBAddress,
|
||||
// Direct: config.Config.Mongo.DBDirect,
|
||||
// Timeout: time.Second * time.Duration(config.Config.Mongo.DBTimeout),
|
||||
// Database: config.Config.Mongo.DBDatabase,
|
||||
// Source: config.Config.Mongo.DBSource,
|
||||
// Username: config.Config.Mongo.DBUserName,
|
||||
// Password: config.Config.Mongo.DBPassword,
|
||||
// PoolLimit: config.Config.Mongo.DBMaxPoolSize,
|
||||
//}
|
||||
//mgoSession, err = mgo.DialWithInfo(mgoDailInfo)
|
||||
//
|
||||
//if err != nil {
|
||||
//
|
||||
// mgoSession, err1 = mgo.DialWithInfo(mgoDailInfo)
|
||||
// if err1 != nil {
|
||||
// log.NewError(" mongo.Connect failed, panic", err.Error())
|
||||
// panic(err1.Error())
|
||||
// }
|
||||
//}
|
||||
|
||||
//DB.mgoSession = mgoSession
|
||||
//DB.mgoSession.SetMode(mgo.Monotonic, true)
|
||||
//c := DB.mgoSession.DB(config.Config.Mongo.DBDatabase).C(cChat)
|
||||
//err = c.EnsureIndexKey("uid")
|
||||
//if err != nil {
|
||||
// panic(err.Error())
|
||||
//}
|
||||
//
|
||||
|
||||
// redis pool init
|
||||
DB.redisPool = &redis.Pool{
|
||||
MaxIdle: config.Config.Redis.DBMaxIdle,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user