Merge branch 'tuoyun'

pull/215/head v2.0.7
wangchuxiao 3 years ago
commit 0c7cb274b4

@ -1 +1 @@
Subproject commit 2257ac8ee528fb1e0038f85e34c8770fbe4758e3
Subproject commit 9d67999cec3e4a9792c33a95e5514a945df54052

@ -14,6 +14,7 @@ import (
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"flag"
"fmt"
"io"
"os"
"strconv"
@ -138,5 +139,9 @@ func main() {
go apiThird.MinioInit()
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
flag.Parse()
r.Run(":" + strconv.Itoa(*ginPort))
fmt.Println("start api server, port: ", *ginPort)
err := r.Run(":" + strconv.Itoa(*ginPort))
if err != nil {
log.Error("", "run failed ", *ginPort, err.Error())
}
}

@ -3,6 +3,7 @@ package main
import (
"Open_IM/internal/cms_api"
"Open_IM/pkg/utils"
"fmt"
"github.com/gin-gonic/gin"
)
@ -11,5 +12,6 @@ func main() {
gin.SetMode(gin.ReleaseMode)
router := cms_api.NewGinRouter()
router.Use(utils.CorsHandler())
fmt.Println("start cms api server, port: ", 8000)
router.Run(":" + "8000")
}

@ -4,6 +4,7 @@ import (
"Open_IM/internal/demo/register"
"Open_IM/pkg/utils"
"flag"
"fmt"
"io"
"os"
"strconv"
@ -33,5 +34,9 @@ func main() {
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())
}
}

@ -5,6 +5,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"flag"
"fmt"
"sync"
)
@ -15,6 +16,7 @@ func main() {
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()

@ -4,6 +4,7 @@ import (
"Open_IM/internal/msg_transfer/logic"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"fmt"
"sync"
)
@ -12,6 +13,7 @@ func main() {
wg.Add(1)
log.NewPrivateLog(constant.LogFileName)
logic.Init()
fmt.Println("start msg_transfer server")
logic.Run()
wg.Wait()
}

@ -5,6 +5,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"flag"
"fmt"
"sync"
)
@ -14,6 +15,7 @@ func main() {
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()

@ -3,12 +3,13 @@ package main
import (
rpcMessageCMS "Open_IM/internal/rpc/admin_cms"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 11000, "rpc listening port")
flag.Parse()
fmt.Println("start cms rpc server, port: ", *rpcPort)
rpcServer := rpcMessageCMS.NewAdminCMSServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
rpcAuth "Open_IM/internal/rpc/auth"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800")
flag.Parse()
fmt.Println("start auth rpc server, port: ", *rpcPort)
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
rpcServer.Run()

@ -3,12 +3,14 @@ package main
import (
"Open_IM/internal/rpc/friend"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10200, "get RpcFriendPort from cmd,default 12000 as port")
flag.Parse()
fmt.Println("start friend rpc server, port: ", *rpcPort)
rpcServer := friend.NewFriendServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
"Open_IM/internal/rpc/group"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10500, "get RpcGroupPort from cmd,default 16000 as port")
flag.Parse()
fmt.Println("start group rpc server, port: ", *rpcPort)
rpcServer := group.NewGroupServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
rpcMessageCMS "Open_IM/internal/rpc/message_cms"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10900, "rpc listening port")
flag.Parse()
fmt.Println("start msg cms rpc server, port: ", *rpcPort)
rpcServer := rpcMessageCMS.NewMessageCMSServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
rpcChat "Open_IM/internal/rpc/msg"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10300, "rpc listening port")
flag.Parse()
fmt.Println("start msg rpc server, port: ", *rpcPort)
rpcServer := rpcChat.NewRpcChatServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
rpc "Open_IM/internal/rpc/office"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 11100, "rpc listening port")
flag.Parse()
fmt.Println("start office rpc server, port: ", *rpcPort)
rpcServer := rpc.NewOfficeServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
"Open_IM/internal/rpc/statistics"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10800, "rpc listening port")
flag.Parse()
fmt.Println("start statistics rpc server, port: ", *rpcPort)
rpcServer := statistics.NewStatisticsServer(*rpcPort)
rpcServer.Run()
}

@ -3,11 +3,13 @@ package main
import (
"Open_IM/internal/rpc/user"
"flag"
"fmt"
)
func main() {
rpcPort := flag.Int("port", 10100, "rpc listening port")
flag.Parse()
fmt.Println("start user rpc server, port: ", *rpcPort)
rpcServer := user.NewUserServer(*rpcPort)
rpcServer.Run()
}

@ -165,6 +165,7 @@ longconnsvr:
websocketMaxMsgLen: 4096
websocketTimeOut: 10
## 推送只能开启一个
push:
tpns: #腾讯推送,暂未测试 暂不要使用
ios:
@ -173,11 +174,22 @@ push:
android:
accessID: 111
secretKey: 111
enable: false
jpns: #极光推送 在极光后台申请后,修改以下四项,必须修改
appKey: cf47465a368f24c659608e7e
masterSecret: 02204efe3f3832947a236ee5
pushUrl: "https://api.jpush.cn/v3/push"
pushIntent: "intent:#Intent;component=io.openim.app.enterprisechat/io.openim.app.enterprisechat.MainActivity;end"
enable: true
getui: #个推推送,暂未测试 暂不要使用
pushUrl: "https://restapi.getui.com/v2/$appId"
masterSecret: ""
appKey: ""
intent: ""
enable: false
manager:
#app管理员userID和对应的secret 建议修改。 用于管理后台登录也可以用户管理后台对应的api
appManagerUid: [ "openIM123456","openIM654321", "openIM333", "openIMAdmin"]

@ -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,
})

@ -1,12 +1,167 @@
package getui
type Getui struct {
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"bytes"
"crypto/sha256"
//"crypto/sha512"
"encoding/hex"
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
"time"
)
var (
GetuiClient *Getui
)
const (
PushURL = "/push/single/cid"
AuthURL = "/auth"
)
func init() {
GetuiClient = newGetuiClient()
}
type Getui struct{}
type GetuiCommonResp struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
type AuthReq struct {
Sign string `json:"sign"`
Timestamp string `json:"timestamp"`
Appkey string `json:"appkey"`
}
type AuthResp struct {
ExpireTime string `json:"expire_time"`
Token string `json:"token"`
}
type PushReq struct {
RequestID string `json:"request_id"`
Audience struct {
Cid []string `json:"cid"`
} `json:"audience"`
PushMssage struct {
Notification Notification `json:"notification"`
} `json:"push_message"`
}
type Notification struct {
Title string `json:"title"`
Body string `json:"body"`
ClickType string `json:"click_type"`
Intent string `json:"intent"`
Url string `json:"url"`
}
type PushResp struct {
}
func newGetuiClient() *Getui {
return &Getui{}
}
func (g *Getui) Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error) {
token, err := db.DB.GetGetuiToken()
if err != nil {
log.NewError(operationID, utils.OperationIDGenerator(), "GetGetuiToken failed", err.Error())
}
if token == "" || err != nil {
token, expireTime, err := g.Auth(operationID, time.Now().UnixNano()/1e6)
if err != nil {
return "", utils.Wrap(err, "Auth failed")
}
log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), token, expireTime, err)
err = db.DB.SetGetuiToken(token, 60*60*23)
if err != nil {
return "", utils.Wrap(err, "Auth failed")
}
}
pushReq := PushReq{
RequestID: utils.OperationIDGenerator(),
Audience: struct {
Cid []string `json:"cid"`
}{Cid: []string{userIDList[0]}},
}
pushReq.PushMssage.Notification = Notification{
Title: alert,
Body: alert,
ClickType: "none",
}
if config.Config.Push.Getui.Intent != "" {
pushReq.PushMssage.Notification.Intent = config.Config.Push.Getui.Intent
pushReq.PushMssage.Notification.ClickType = "intent"
}
pushResp := PushResp{}
err = g.request(PushURL, pushReq, token, &pushResp, operationID)
if err != nil {
return "", utils.Wrap(err, "push failed")
}
respBytes, err := json.Marshal(pushResp)
return string(respBytes), err
}
func (g *Getui) Push(userIDList []string, alert, detailContent, platform string) (resp string, err error) {
return "", nil
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) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
return "", nil
func (g *Getui) request(url string, content interface{}, token string, returnStruct interface{}, operationID string) error {
con, err := json.Marshal(content)
if err != nil {
return err
}
client := &http.Client{}
log.Debug(operationID, utils.GetSelfFuncName(), "json:", string(con))
req, err := http.NewRequest("POST", config.Config.Push.Getui.PushUrl+url, bytes.NewBuffer(con))
if err != nil {
return err
}
if token != "" {
req.Header.Set(token, token)
}
req.Header.Set("content-type", "application/json")
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
log.NewInfo(operationID, "getui", utils.GetSelfFuncName(), "resp, ", string(result))
if err := json.Unmarshal(result, returnStruct); err != nil {
return err
}
return nil
}

@ -10,14 +10,29 @@ import (
"net/http"
)
type JPushResp struct {
var (
JPushClient *JPush
)
func init() {
JPushClient = newGetuiClient()
}
type JPush struct{}
func newGetuiClient() *JPush {
return &JPush{}
}
type JPush struct {
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
return token, nil
}
func JGAccountListPush(accounts []string, alert, detailContent, platform string) ([]byte, error) {
func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
return resp, nil
}
func (j *JPush) Push(accounts []string, alert, detailContent, platform, operationID string) (string, error) {
var pf requestBody.Platform
_ = pf.SetPlatform(platform)
var au requestBody.Audience
@ -37,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
}

@ -7,7 +7,9 @@
package logic
import (
push "Open_IM/internal/push/jpush"
pusher "Open_IM/internal/push"
"Open_IM/internal/push/getui"
jpush "Open_IM/internal/push/jpush"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
@ -99,12 +101,22 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
content = constant.ContentType2PushContent[constant.Common]
}
}
pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
var offlinePusher pusher.OfflinePusher
if config.Config.Push.Getui.Enable {
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), config.Config.Push.Getui)
offlinePusher = getui.GetuiClient
}
if config.Config.Push.Jpns.Enable {
offlinePusher = jpush.JPushClient
}
if offlinePusher == nil {
offlinePusher = jpush.JPushClient
}
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t), pushMsg.OperationID)
if err != nil {
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
} else {
log.NewDebug(pushMsg.OperationID, "offline push return result is ", string(pushResult), pushMsg.MsgData, constant.PlatformIDToName(t))
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData, constant.PlatformIDToName(t))
}
}

@ -1,6 +1,5 @@
package push
type offlinePusher interface {
auth(apiKey, secretKey string, timeStamp int64) (token string, err error)
push(userIDList []string, alert, detailContent, platform string) (resp string, err error)
type OfflinePusher interface {
Push(userIDList []string, alert, detailContent, platform, operationID string) (resp string, err error)
}

@ -7,3 +7,7 @@ import (
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
return true, nil
}
func callbackAfterCreateGroup(req *pbGroup.CreateGroupReq) {
}

@ -668,6 +668,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
Status: group.Status,
CreatorUserID: group.CreatorUserID,
GroupType: group.GroupType,
CreateTime: uint32(group.CreateTime.Unix()),
}
groupMember, err := imdb.GetGroupMaster(group.GroupID)
if err != nil {
@ -677,6 +678,7 @@ func (s *groupServer) GetGroupById(_ context.Context, req *pbGroup.GetGroupByIdR
resp.CMSGroup.GroupMasterName = groupMember.Nickname
resp.CMSGroup.GroupMasterId = groupMember.UserID
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
@ -704,6 +706,7 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
groupMember, err := imdb.GetGroupMaster(v.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
continue
}
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{
@ -713,11 +716,13 @@ func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pb
OwnerUserID: v.CreatorUserID,
Status: v.Status,
CreatorUserID: v.CreatorUserID,
CreateTime: uint32(v.CreateTime.Unix()),
},
GroupMasterName: groupMember.Nickname,
GroupMasterId: groupMember.UserID,
})
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}

@ -3,6 +3,7 @@ package msg
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/chat"
@ -10,23 +11,24 @@ import (
"Open_IM/pkg/utils"
"context"
"strings"
"time"
)
func TagSendMessage(operationID, sendID, recvID, content string, senderPlatformID int32) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", sendID, recvID, content)
func TagSendMessage(operationID string, user *db.User, recvID, content string, senderPlatformID int32) {
log.NewInfo(operationID, utils.GetSelfFuncName(), "args: ", user.UserID, recvID, content)
var req pbChat.SendMsgReq
var msgData pbCommon.MsgData
msgData.SendID = sendID
msgData.SendID = user.UserID
msgData.RecvID = recvID
msgData.ContentType = constant.Custom
msgData.SessionType = constant.SingleChatType
msgData.MsgFrom = constant.UserMsgType
msgData.Content = []byte(content)
msgData.SenderFaceURL = user.FaceURL
msgData.SenderNickname = user.Nickname
msgData.Options = map[string]bool{}
msgData.Options[constant.IsSenderConversationUpdate] = false
msgData.SendTime = time.Now().Unix()
msgData.CreateTime = time.Now().Unix()
msgData.CreateTime = utils.GetCurrentTimestampByMill()
msgData.ClientMsgID = utils.GetMsgID(user.UserID)
msgData.SenderPlatformID = senderPlatformID
req.MsgData = &msgData
req.OperationID = operationID

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbOffice "Open_IM/pkg/proto/office"
@ -179,8 +180,12 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
}
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "total userIDList result: ", userIDList)
us, err := imdb.GetUserByUserID(req.SendID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.SendID)
}
for _, userID := range userIDList {
msg.TagSendMessage(req.OperationID, req.SendID, userID, req.Content, req.SenderPlatformID)
msg.TagSendMessage(req.OperationID, us, userID, req.Content, req.SenderPlatformID)
}
var tagSendLogs db.TagSendLog
for _, userID := range userIDList {

@ -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 {
}

@ -152,12 +152,21 @@ type config struct {
AccessID string `yaml:"accessID"`
SecretKey string `yaml:"secretKey"`
}
Enable bool `yaml:"enable"`
}
Jpns struct {
AppKey string `yaml:"appKey"`
MasterSecret string `yaml:"masterSecret"`
PushUrl string `yaml:"pushUrl"`
PushIntent string `yaml:"pushIntent"`
Enable bool `yaml:"enable"`
}
Getui struct {
PushUrl string `yaml:"pushUrl"`
AppKey string `yaml:"appKey"`
Enable bool `yaml:"enable"`
Intent string `yaml:"intent"`
MasterSecret string `yaml:"masterSecret"`
}
}
Manager struct {

@ -217,7 +217,7 @@ const (
const FriendAcceptTip = "You have successfully become friends, so start chatting"
func GroupIsBanChat(status int32) bool {
if status != GroupBanChat {
if status != GroupStatusMuted {
return false
}
return true

@ -2,7 +2,7 @@ package db
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"fmt"
"sync"
"time"
@ -24,13 +24,13 @@ func initMysqlDB() {
var err1 error
db, err := gorm.Open("mysql", dsn)
if err != nil {
log.NewError("0", "Open failed ", err.Error(), dsn)
fmt.Println("0", "Open failed ", err.Error(), dsn)
}
if err != nil {
time.Sleep(time.Duration(30) * time.Second)
db, err1 = gorm.Open("mysql", dsn)
if err1 != nil {
log.NewError("0", "Open failed ", err1.Error(), dsn)
fmt.Println("0", "Open failed ", err1.Error(), dsn)
panic(err1.Error())
}
}
@ -39,7 +39,7 @@ func initMysqlDB() {
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
err = db.Exec(sql).Error
if err != nil {
log.NewError("0", "Exec failed ", err.Error(), sql)
fmt.Println("0", "Exec failed ", err.Error(), sql)
panic(err.Error())
}
db.Close()
@ -48,11 +48,11 @@ func initMysqlDB() {
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
db, err = gorm.Open("mysql", dsn)
if err != nil {
log.NewError("0", "Open failed ", err.Error(), dsn)
fmt.Println("0", "Open failed ", err.Error(), dsn)
panic(err.Error())
}
log.NewInfo("open db ok ", dsn)
fmt.Println("open db ok ", dsn)
db.AutoMigrate(&Friend{},
&FriendRequest{},
&Group{},
@ -64,49 +64,49 @@ func initMysqlDB() {
db.Set("gorm:table_options", "collation=utf8_unicode_ci")
if !db.HasTable(&Friend{}) {
log.NewInfo("CreateTable Friend")
fmt.Println("CreateTable Friend")
db.CreateTable(&Friend{})
}
if !db.HasTable(&FriendRequest{}) {
log.NewInfo("CreateTable FriendRequest")
fmt.Println("CreateTable FriendRequest")
db.CreateTable(&FriendRequest{})
}
if !db.HasTable(&Group{}) {
log.NewInfo("CreateTable Group")
fmt.Println("CreateTable Group")
db.CreateTable(&Group{})
}
if !db.HasTable(&GroupMember{}) {
log.NewInfo("CreateTable GroupMember")
fmt.Println("CreateTable GroupMember")
db.CreateTable(&GroupMember{})
}
if !db.HasTable(&GroupRequest{}) {
log.NewInfo("CreateTable GroupRequest")
fmt.Println("CreateTable GroupRequest")
db.CreateTable(&GroupRequest{})
}
if !db.HasTable(&User{}) {
log.NewInfo("CreateTable User")
fmt.Println("CreateTable User")
db.CreateTable(&User{})
}
if !db.HasTable(&Black{}) {
log.NewInfo("CreateTable Black")
fmt.Println("CreateTable Black")
db.CreateTable(&Black{})
}
if !db.HasTable(&ChatLog{}) {
log.NewInfo("CreateTable Black")
fmt.Println("CreateTable Black")
db.CreateTable(&ChatLog{})
}
if !db.HasTable(&Register{}) {
log.NewInfo("CreateTable Black")
fmt.Println("CreateTable Black")
db.CreateTable(&Register{})
}
if !db.HasTable(&Conversation{}) {
log.NewInfo("CreateTable Black")
fmt.Println("CreateTable Black")
db.CreateTable(&Conversation{})
}

@ -33,7 +33,7 @@ func ResetPassword(account, password string) error {
Password: password,
}
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(true)
dbConn.LogMode(false)
if err != nil {
return err
}

@ -71,7 +71,7 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) {
if err != nil {
return nil, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var groupMembers []db.GroupMember
err = dbConn.Table("group_members").Select("user_id").Where("group_id=?", groupID).Find(&groupMembers).Error
if err != nil {
@ -279,7 +279,7 @@ func GetGroupMembersCount(groupId, userName string) (int32, error) {
if err != nil {
return count, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
if err := dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil {
return count, err
}

@ -123,7 +123,7 @@ func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
if err != nil {
return nil, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
return groupRequestList, err
}

@ -13,7 +13,7 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
if err != nil {
return chatLogs, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
Limit(showNumber).Offset(showNumber * (pageNumber - 1))
@ -43,7 +43,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
if err != nil {
return count, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
db := dbConn.Table("chat_logs").
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
if chatLog.SessionType != 0 {
@ -65,4 +65,4 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
err = db.Find(&chatLogs).Count(&count).Error
return count, err
}
}

@ -10,7 +10,7 @@ func GetActiveUserNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -21,7 +21,7 @@ func GetIncreaseUserNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -32,7 +32,7 @@ func GetTotalUserNum() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Count(&num).Error
return num, err
@ -43,7 +43,7 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error
return num, err
@ -54,7 +54,7 @@ func GetPrivateMessageNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
return num, err
@ -65,7 +65,7 @@ func GetGroupMessageNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
return num, err
@ -76,7 +76,7 @@ func GetIncreaseGroupNum(from, to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
return num, err
@ -87,7 +87,7 @@ func GetTotalGroupNum() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Count(&num).Error
return num, err
@ -98,7 +98,7 @@ func GetGroupNum(to time.Time) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var num int32
err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error
return num, err
@ -116,7 +116,7 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
if err != nil {
return activeGroups, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
for _, activeGroup := range activeGroups {
group := db.Group{
@ -140,7 +140,7 @@ func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
if err != nil {
return activeUsers, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
for _, activeUser := range activeUsers {
user := db.User{

@ -92,7 +92,7 @@ func UpdateUserInfo(user db.User) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
return err
}
@ -112,7 +112,7 @@ func SelectAllUserID() ([]string, error) {
func SelectSomeUserID(userIDList []string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(true)
dbConn.LogMode(false)
if err != nil {
return nil, err
}
@ -131,7 +131,7 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
if err != nil {
return users, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
if err != nil {
return users, err
@ -204,7 +204,7 @@ func UnBlockUser(userId string) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{})
return result.Error
}
@ -248,7 +248,7 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) {
if err != nil {
return blockUserInfos, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil {
return blockUserInfos, err
}
@ -275,7 +275,7 @@ func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, er
if err != nil {
return users, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error
return users, err
}
@ -285,7 +285,7 @@ func GetUsersCount(user db.User) (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var count int32
if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil {
return 0, err
@ -298,7 +298,7 @@ func GetBlockUsersNumCount() (int32, error) {
if err != nil {
return 0, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
var count int32
if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil {
return 0, err
@ -311,7 +311,7 @@ func SetConversation(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -330,7 +330,7 @@ func PeerUserSetConversation(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -349,7 +349,7 @@ func SetRecvMsgOpt(conversation db.Conversation) error {
if err != nil {
return err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
newConversation := conversation
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
@ -369,7 +369,7 @@ func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
if err != nil {
return conversations, err
}
dbConn.LogMode(true)
dbConn.LogMode(false)
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
return conversations, err
}

@ -14,6 +14,7 @@ const (
userMinSeq = "REDIS_USER_MIN_SEQ:"
uidPidToken = "UID_PID_TOKEN_STATUS:"
conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:"
GetuiToken = "GETUI"
)
func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) {
@ -144,3 +145,13 @@ func (d *DataBases) GetMultiConversationMsgOpt(userID string, conversationIDs []
return m, nil
}
func (d *DataBases) SetGetuiToken(token string, expireTime int64) error {
_, err := d.Exec("SET", GetuiToken, token, "ex", expireTime)
return err
}
func (d *DataBases) GetGetuiToken() (string, error) {
result, err := redis.String(d.Exec("GET", GetuiToken))
return result, err
}

@ -38,6 +38,6 @@ func RespHttp200(ctx *gin.Context, err error, data interface{}) {
}
// warp error
func WrapError(err constant.ErrInfo) error {
return status.Error(codes.Code(err.ErrCode), err.ErrMsg)
func WrapError(err constant.ErrInfo, msg ...string) error {
return status.Error(codes.Code(err.ErrCode), err.ErrMsg+msg[0])
}

@ -39,6 +39,8 @@ func cleanUpFuncName(funcName string) string {
}
return funcName[end+1:]
}
//Get the intersection of two slices
func Intersect(slice1, slice2 []uint32) []uint32 {
m := make(map[uint32]bool)
n := make([]uint32, 0)
@ -53,6 +55,8 @@ func Intersect(slice1, slice2 []uint32) []uint32 {
}
return n
}
//Get the diff of two slices
func Difference(slice1, slice2 []uint32) []uint32 {
m := make(map[uint32]bool)
n := make([]uint32, 0)

@ -32,7 +32,5 @@ for ((i = 0; i < ${#service_source_root[*]}; i++)); do
else
echo -e "${GREEN_PREFIX}${service_names[$i]} successfully be built ${COLOR_SUFFIX}\n"
fi
done
echo -e ${YELLOW_PREFIX}"all services build success"${COLOR_SUFFIX}

Loading…
Cancel
Save