mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge branch 'tuoyun' of github.com:OpenIMSDK/Open-IM-Server into tuoyun
This commit is contained in:
commit
929c5e7a5b
@ -1 +1 @@
|
|||||||
Subproject commit 119b4a428510aabc71f52b30867b8d5f64ddeaa2
|
Subproject commit 7b66c0ab78be494ce2cfe23de37543dd11c2d354
|
@ -10,6 +10,7 @@ import (
|
|||||||
"Open_IM/internal/api/office"
|
"Open_IM/internal/api/office"
|
||||||
apiThird "Open_IM/internal/api/third"
|
apiThird "Open_IM/internal/api/third"
|
||||||
"Open_IM/internal/api/user"
|
"Open_IM/internal/api/user"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"flag"
|
"flag"
|
||||||
@ -126,7 +127,7 @@ func main() {
|
|||||||
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs)
|
||||||
}
|
}
|
||||||
apiThird.MinioInit()
|
apiThird.MinioInit()
|
||||||
log.NewPrivateLog("api")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
r.Run(":" + strconv.Itoa(*ginPort))
|
r.Run(":" + strconv.Itoa(*ginPort))
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/internal/demo/register"
|
"Open_IM/internal/demo/register"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"flag"
|
"flag"
|
||||||
@ -23,7 +24,7 @@ func main() {
|
|||||||
authRouterGroup.POST("/login", register.Login)
|
authRouterGroup.POST("/login", register.Login)
|
||||||
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
authRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||||
}
|
}
|
||||||
log.NewPrivateLog("demo")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
r.Run(":" + strconv.Itoa(*ginPort))
|
r.Run(":" + strconv.Itoa(*ginPort))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
commonDB "Open_IM/pkg/common/db"
|
commonDB "Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
@ -8,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.NewPrivateLog("timer")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
//for {
|
//for {
|
||||||
// fmt.Println("start delete mongodb expired record")
|
// fmt.Println("start delete mongodb expired record")
|
||||||
// timeUnixBegin := time.Now().Unix()
|
// timeUnixBegin := time.Now().Unix()
|
||||||
|
@ -140,7 +140,7 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
log.NewInfo("", data, params)
|
log.NewInfo("", data, params)
|
||||||
token := c.Request.Header.Get("token")
|
token := c.Request.Header.Get("token")
|
||||||
claims, err := token_verify.ParseToken(token)
|
claims, err := token_verify.ParseToken(token, params.OperationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(params.OperationID, "parse token failed", err.Error())
|
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||||
@ -289,16 +289,16 @@ type OANotificationElem struct {
|
|||||||
Url string `mapstructure:"url"`
|
Url string `mapstructure:"url"`
|
||||||
MixType int32 `mapstructure:"mixType"`
|
MixType int32 `mapstructure:"mixType"`
|
||||||
Image struct {
|
Image struct {
|
||||||
SourceUrl string `mapstructure:"sourceUrl"`
|
SourceUrl string `mapstructure:"sourceURL"`
|
||||||
SnapshotUrl string `mapstructure:"snapshotUrl"`
|
SnapshotUrl string `mapstructure:"snapshotURL"`
|
||||||
} `mapstructure:"image"`
|
} `mapstructure:"image"`
|
||||||
Video struct {
|
Video struct {
|
||||||
SourceUrl string `mapstructure:"sourceUrl"`
|
SourceUrl string `mapstructure:"sourceURL"`
|
||||||
SnapshotUrl string `mapstructure:"snapshotUrl"`
|
SnapshotUrl string `mapstructure:"snapshotURL"`
|
||||||
Duration int64 `mapstructure:"duration"`
|
Duration int64 `mapstructure:"duration"`
|
||||||
} `mapstructure:"video"`
|
} `mapstructure:"video"`
|
||||||
File struct {
|
File struct {
|
||||||
SourceUrl string `mapstructure:"sourceUrl"`
|
SourceUrl string `mapstructure:"sourceURL"`
|
||||||
FileName string `mapstructure:"fileName"`
|
FileName string `mapstructure:"fileName"`
|
||||||
FileSize int64 `mapstructure:"fileSize"`
|
FileSize int64 `mapstructure:"fileSize"`
|
||||||
} `mapstructure:"file"`
|
} `mapstructure:"file"`
|
||||||
|
@ -2,6 +2,7 @@ package gate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/statistics"
|
"Open_IM/pkg/statistics"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -20,7 +21,7 @@ var (
|
|||||||
|
|
||||||
func Init(rpcPort, wsPort int) {
|
func Init(rpcPort, wsPort int) {
|
||||||
//log initialization
|
//log initialization
|
||||||
log.NewPrivateLog(config.Config.ModuleName.LongConnSvrName)
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
rwLock = new(sync.RWMutex)
|
rwLock = new(sync.RWMutex)
|
||||||
validate = validator.New()
|
validate = validator.New()
|
||||||
statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300)
|
statistics.NewStatistics(&sendMsgCount, config.Config.ModuleName.LongConnSvrName, fmt.Sprintf("%d second recv to msg_gateway sendMsgCount", sendMsgCount), 300)
|
||||||
|
@ -80,6 +80,22 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
|
|||||||
mc.groupMsgCount++
|
mc.groupMsgCount++
|
||||||
}
|
}
|
||||||
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
|
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
|
||||||
|
case constant.NotificationChatType:
|
||||||
|
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = NotificationChatType", isHistory, isPersist)
|
||||||
|
if isHistory {
|
||||||
|
err := saveUserChat(msgKey, &msgFromMQ)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mc.singleMsgCount++
|
||||||
|
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||||
|
}
|
||||||
|
if !isSenderSync && msgKey == msgFromMQ.MsgData.SendID {
|
||||||
|
} else {
|
||||||
|
go sendMessageToPush(&msgFromMQ, msgKey)
|
||||||
|
}
|
||||||
|
log.NewDebug(operationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time)
|
||||||
default:
|
default:
|
||||||
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
|
||||||
return
|
return
|
||||||
|
@ -2,6 +2,7 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
)
|
)
|
||||||
@ -13,7 +14,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
log.NewPrivateLog(config.Config.ModuleName.MsgTransferName)
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
persistentCH.Init()
|
persistentCH.Init()
|
||||||
historyCH.Init()
|
historyCH.Init()
|
||||||
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
producer = kafka.NewKafkaProducer(config.Config.Kafka.Ms2pschat.Addr, config.Config.Kafka.Ms2pschat.Topic)
|
||||||
|
@ -34,26 +34,31 @@ func (pc *PersistentConsumerHandler) Init() {
|
|||||||
|
|
||||||
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
|
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
|
||||||
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
|
||||||
|
var tag bool
|
||||||
msgFromMQ := pbMsg.MsgDataToMQ{}
|
msgFromMQ := pbMsg.MsgDataToMQ{}
|
||||||
err := proto.Unmarshal(msg, &msgFromMQ)
|
err := proto.Unmarshal(msg, &msgFromMQ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorByKv("msg_transfer Unmarshal msg err", "", "msg", string(msg), "err", err.Error())
|
log.NewError(msgFromMQ.OperationID, "msg_transfer Unmarshal msg err", "msg", string(msg), "err", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//Control whether to store history messages (mysql)
|
//Control whether to store history messages (mysql)
|
||||||
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
|
||||||
//Only process receiver data
|
//Only process receiver data
|
||||||
if isPersist {
|
if isPersist {
|
||||||
if msgKey == msgFromMQ.MsgData.RecvID && msgFromMQ.MsgData.SessionType == constant.SingleChatType {
|
switch msgFromMQ.MsgData.SessionType {
|
||||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
case constant.SingleChatType, constant.NotificationChatType:
|
||||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
if msgKey == msgFromMQ.MsgData.RecvID {
|
||||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
tag = true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else if msgFromMQ.MsgData.SessionType == constant.GroupChatType && msgKey == msgFromMQ.MsgData.SendID {
|
case constant.GroupChatType:
|
||||||
log.InfoByKv("msg_transfer msg persisting", msgFromMQ.OperationID)
|
if msgKey == msgFromMQ.MsgData.SendID || utils.IsContain(msgFromMQ.MsgData.SendID, config.Config.Manager.AppManagerUid) {
|
||||||
|
tag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tag {
|
||||||
|
log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg))
|
||||||
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
|
||||||
log.ErrorByKv("Message insert failed", msgFromMQ.OperationID, "err", err.Error(), "msg", msgFromMQ.String())
|
log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Init(rpcPort int) {
|
func Init(rpcPort int) {
|
||||||
log.NewPrivateLog(config.Config.ModuleName.PushName)
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
rpcServer.Init(rpcPort)
|
rpcServer.Init(rpcPort)
|
||||||
pushCh.Init()
|
pushCh.Init()
|
||||||
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
pushTerminal = []int32{constant.IOSPlatformID, constant.AndroidPlatformID}
|
||||||
|
@ -24,7 +24,7 @@ type adminCMSServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAdminCMSServer(port int) *adminCMSServer {
|
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||||
log.NewPrivateLog("AdminCMS")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &adminCMSServer{
|
return &adminCMSServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
||||||
@ -66,12 +66,12 @@ func (s *adminCMSServer) Run() {
|
|||||||
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLoginReq) (*pbAdminCMS.AdminLoginResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp := &pbAdminCMS.AdminLoginResp{}
|
resp := &pbAdminCMS.AdminLoginResp{}
|
||||||
for i, adminID := range config.Config.Manager.AppManagerUid{
|
for i, adminID := range config.Config.Manager.AppManagerUid {
|
||||||
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
if adminID == req.AdminID && config.Config.Manager.Secrets[i] == req.Secret {
|
||||||
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
token, expTime, err := token_verify.CreateToken(adminID, constant.SingleChatType)
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "generate token success", "token: ", token, "expTime:", expTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "generate token failed", "adminID: ", adminID, err.Error())
|
||||||
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
return resp, openIMHttp.WrapError(constant.ErrTokenUnknown)
|
||||||
}
|
}
|
||||||
resp.Token = token
|
resp.Token = token
|
||||||
@ -84,4 +84,4 @@ func (s *adminCMSServer) AdminLogin(_ context.Context, req *pbAdminCMS.AdminLogi
|
|||||||
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
return resp, openIMHttp.WrapError(constant.ErrTokenMalformed)
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ type rpcAuth struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcAuthServer(port int) *rpcAuth {
|
func NewRpcAuthServer(port int) *rpcAuth {
|
||||||
log.NewPrivateLog("auth")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &rpcAuth{
|
return &rpcAuth{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||||
|
@ -29,7 +29,7 @@ type friendServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewFriendServer(port int) *friendServer {
|
func NewFriendServer(port int) *friendServer {
|
||||||
log.NewPrivateLog("friend")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &friendServer{
|
return &friendServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||||
|
@ -31,7 +31,7 @@ type groupServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGroupServer(port int) *groupServer {
|
func NewGroupServer(port int) *groupServer {
|
||||||
log.NewPrivateLog("group")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &groupServer{
|
return &groupServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||||
@ -276,7 +276,7 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
|||||||
log.Debug(req.OperationID, v)
|
log.Debug(req.OperationID, v)
|
||||||
var node open_im_sdk.GroupMemberFullInfo
|
var node open_im_sdk.GroupMemberFullInfo
|
||||||
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
cp.GroupMemberDBCopyOpenIM(&node, &v)
|
||||||
log.Debug(req.OperationID, "db value:", v)
|
log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix())
|
||||||
log.Debug(req.OperationID, "cp value: ", node)
|
log.Debug(req.OperationID, "cp value: ", node)
|
||||||
resp.MemberList = append(resp.MemberList, &node)
|
resp.MemberList = append(resp.MemberList, &node)
|
||||||
}
|
}
|
||||||
@ -1029,11 +1029,10 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
|||||||
log.Error(req.OperationID, "verify failed ", req.OpUserID, req.GroupID)
|
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
|
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||||
}
|
}
|
||||||
groupInfo := db.Group{GroupID: req.GroupID}
|
|
||||||
|
|
||||||
err := imdb.UpdateGroupInfoDefaultZero(groupInfo, map[string]interface{}{"status": constant.GroupOk})
|
err := imdb.UpdateGroupInfoDefaultZero(req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), groupInfo)
|
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
|
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||||
}
|
}
|
||||||
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||||
|
@ -31,7 +31,7 @@ type messageCMSServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMessageCMSServer(port int) *messageCMSServer {
|
func NewMessageCMSServer(port int) *messageCMSServer {
|
||||||
log.NewPrivateLog("MessageCMS")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &messageCMSServer{
|
return &messageCMSServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImMessageCMSName,
|
||||||
@ -84,8 +84,8 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
|||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "time string parse error", err.Error())
|
||||||
}
|
}
|
||||||
chatLog := db.ChatLog{
|
chatLog := db.ChatLog{
|
||||||
Content: req.Content,
|
Content: req.Content,
|
||||||
SendTime: time,
|
SendTime: time,
|
||||||
ContentType: req.ContentType,
|
ContentType: req.ContentType,
|
||||||
SessionType: req.SessionType,
|
SessionType: req.SessionType,
|
||||||
}
|
}
|
||||||
@ -101,20 +101,20 @@ func (s *messageCMSServer) GetChatLogs(_ context.Context, req *pbMessageCMS.GetC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLogCount", err.Error())
|
||||||
}
|
}
|
||||||
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
chatLogs, err := imdb.GetChatLog(chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetChatLog", err.Error())
|
||||||
return resp, errors.WrapError(constant.ErrDB)
|
return resp, errors.WrapError(constant.ErrDB)
|
||||||
}
|
}
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbChatLog := &pbMessageCMS.ChatLogs{
|
pbChatLog := &pbMessageCMS.ChatLogs{
|
||||||
SessionType: chatLog.SessionType,
|
SessionType: chatLog.SessionType,
|
||||||
ContentType: chatLog.ContentType,
|
ContentType: chatLog.ContentType,
|
||||||
SearchContent: req.Content,
|
SearchContent: req.Content,
|
||||||
WholeContent: chatLog.Content,
|
WholeContent: chatLog.Content,
|
||||||
Date: chatLog.CreateTime.String(),
|
Date: chatLog.CreateTime.String(),
|
||||||
SenderNickName: chatLog.SenderNickname,
|
SenderNickName: chatLog.SenderNickname,
|
||||||
SenderId: chatLog.SendID,
|
SenderId: chatLog.SendID,
|
||||||
}
|
}
|
||||||
if chatLog.SenderNickname == "" {
|
if chatLog.SenderNickname == "" {
|
||||||
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
sendUser, err := imdb.GetUserByUserID(chatLog.SendID)
|
||||||
|
@ -2,6 +2,7 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/kafka"
|
"Open_IM/pkg/common/kafka"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||||
@ -22,7 +23,7 @@ type rpcChat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcChatServer(port int) *rpcChat {
|
func NewRpcChatServer(port int) *rpcChat {
|
||||||
log.NewPrivateLog("msg")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
rc := rpcChat{
|
rc := rpcChat{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfflineMessageName,
|
||||||
|
@ -281,6 +281,23 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|||||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error())
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendGroupMsg failed", err.Error())
|
||||||
}
|
}
|
||||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||||
|
case constant.NotificationChatType:
|
||||||
|
msgToMQ.MsgData = pb.MsgData
|
||||||
|
log.NewInfo(msgToMQ.OperationID, msgToMQ)
|
||||||
|
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
||||||
|
if err1 != nil {
|
||||||
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
||||||
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
||||||
|
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
||||||
|
if err2 != nil {
|
||||||
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
||||||
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||||
default:
|
default:
|
||||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||||
}
|
}
|
||||||
@ -571,6 +588,6 @@ func Notification(n *NotificationMsg) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||||
} else if reply.ErrCode != 0 {
|
} else if reply.ErrCode != 0 {
|
||||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String())
|
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), reply.ErrCode, reply.ErrMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ type officeServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewOfficeServer(port int) *officeServer {
|
func NewOfficeServer(port int) *officeServer {
|
||||||
log.NewPrivateLog("office")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &officeServer{
|
return &officeServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName,
|
||||||
@ -103,7 +103,7 @@ func (s *officeServer) GetUserTags(_ context.Context, req *pbOffice.GetUserTagsR
|
|||||||
|
|
||||||
func (s *officeServer) CreateTag(_ context.Context, req *pbOffice.CreateTagReq) (resp *pbOffice.CreateTagResp, err error) {
|
func (s *officeServer) CreateTag(_ context.Context, req *pbOffice.CreateTagReq) (resp *pbOffice.CreateTagResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "CreateTag req", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "CreateTag req", req.String())
|
||||||
userIDList := utils.RemoveUserIDRepByMap(req.UserIDList)
|
userIDList := utils.RemoveRepeatedStringInList(req.UserIDList)
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
||||||
resp = &pbOffice.CreateTagResp{CommonResp: &pbOffice.CommonResp{}}
|
resp = &pbOffice.CreateTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||||
if err := db.DB.CreateTag(req.UserID, req.TagName, userIDList); err != nil {
|
if err := db.DB.CreateTag(req.UserID, req.TagName, userIDList); err != nil {
|
||||||
@ -132,8 +132,8 @@ func (s *officeServer) DeleteTag(_ context.Context, req *pbOffice.DeleteTagReq)
|
|||||||
func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp *pbOffice.SetTagResp, err error) {
|
func (s *officeServer) SetTag(_ context.Context, req *pbOffice.SetTagReq) (resp *pbOffice.SetTagResp, err error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||||
resp = &pbOffice.SetTagResp{CommonResp: &pbOffice.CommonResp{}}
|
resp = &pbOffice.SetTagResp{CommonResp: &pbOffice.CommonResp{}}
|
||||||
IncreaseUserIDList := utils.RemoveUserIDRepByMap(req.IncreaseUserIDList)
|
IncreaseUserIDList := utils.RemoveRepeatedStringInList(req.IncreaseUserIDList)
|
||||||
reduceUserIDList := utils.RemoveUserIDRepByMap(req.ReduceUserIDList)
|
reduceUserIDList := utils.RemoveRepeatedStringInList(req.ReduceUserIDList)
|
||||||
if err := db.DB.SetTag(req.UserID, req.TagID, req.NewName, IncreaseUserIDList, reduceUserIDList); err != nil {
|
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())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetTag failed", err.Error())
|
||||||
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg
|
||||||
@ -171,7 +171,7 @@ func (s *officeServer) SendMsg2Tag(_ context.Context, req *pbOffice.SendMsg2TagR
|
|||||||
userIDList = append(userIDList, tagUserIDList...)
|
userIDList = append(userIDList, tagUserIDList...)
|
||||||
userIDList = append(userIDList, groupUserIDList...)
|
userIDList = append(userIDList, groupUserIDList...)
|
||||||
userIDList = append(userIDList, req.UserList...)
|
userIDList = append(userIDList, req.UserList...)
|
||||||
userIDList = utils.RemoveUserIDRepByMap(userIDList)
|
userIDList = utils.RemoveRepeatedStringInList(userIDList)
|
||||||
for i, userID := range userIDList {
|
for i, userID := range userIDList {
|
||||||
if userID == req.SendID || userID == "" {
|
if userID == req.SendID || userID == "" {
|
||||||
userIDList = append(userIDList[:i], userIDList[i+1:]...)
|
userIDList = append(userIDList[:i], userIDList[i+1:]...)
|
||||||
|
@ -19,10 +19,10 @@ import (
|
|||||||
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
//open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
//"context"
|
//"context"
|
||||||
|
errors "Open_IM/pkg/common/http"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
errors "Open_IM/pkg/common/http"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
@ -35,7 +35,7 @@ type statisticsServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewStatisticsServer(port int) *statisticsServer {
|
func NewStatisticsServer(port int) *statisticsServer {
|
||||||
log.NewPrivateLog("Statistics")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &statisticsServer{
|
return &statisticsServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImStatisticsName,
|
||||||
@ -164,7 +164,7 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
|
|||||||
}
|
}
|
||||||
// month
|
// month
|
||||||
case !isInOneMonth(from, to):
|
case !isInOneMonth(from, to):
|
||||||
if to.Sub(from) < time.Hour * 24 * 30 {
|
if to.Sub(from) < time.Hour*24*30 {
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||||
@ -251,7 +251,7 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
|
|||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum", v, err.Error())
|
||||||
}
|
}
|
||||||
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
resp.TotalGroupNumList[index] = &pbStatistics.DateNumList{
|
||||||
Date: v[0].String(),
|
Date: v[0].String(),
|
||||||
Num: num,
|
Num: num,
|
||||||
}
|
}
|
||||||
}(wg, i, v)
|
}(wg, i, v)
|
||||||
|
@ -32,7 +32,7 @@ type userServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewUserServer(port int) *userServer {
|
func NewUserServer(port int) *userServer {
|
||||||
log.NewPrivateLog("user")
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
return &userServer{
|
return &userServer{
|
||||||
rpcPort: port,
|
rpcPort: port,
|
||||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||||
|
@ -76,7 +76,7 @@ func Test_ParseToken(t *testing.T) {
|
|||||||
uid := "1"
|
uid := "1"
|
||||||
platform := int32(1)
|
platform := int32(1)
|
||||||
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
tokenString, _, _ := token_verify.CreateToken(uid, platform)
|
||||||
claims, err := token_verify.ParseToken(tokenString)
|
claims, err := token_verify.ParseToken(tokenString, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
assert.Equal(t, claims.UID, uid)
|
assert.Equal(t, claims.UID, uid)
|
||||||
}
|
}
|
||||||
|
@ -231,3 +231,5 @@ func GroupIsBanPrivateChat(status int32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BigVersion = "v3"
|
const BigVersion = "v3"
|
||||||
|
|
||||||
|
const LogFileName = "OpenIM.log"
|
||||||
|
@ -2,6 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -33,6 +34,7 @@ func key(dbAddress, dbName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
log.NewPrivateLog(constant.LogFileName)
|
||||||
//var mgoSession *mgo.Session
|
//var mgoSession *mgo.Session
|
||||||
var mongoClient *mongo.Client
|
var mongoClient *mongo.Client
|
||||||
var err1 error
|
var err1 error
|
||||||
@ -51,7 +53,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
if err != nil{
|
if err != nil {
|
||||||
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||||
time.Sleep(time.Duration(30) * time.Second)
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||||
|
@ -499,7 +499,7 @@ func (d *DataBases) SetTag(userID, tagID, newName string, increaseUserIDList []s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
tag.UserList = append(tag.UserList, increaseUserIDList...)
|
||||||
tag.UserList = utils.RemoveUserIDRepByMap(tag.UserList)
|
tag.UserList = utils.RemoveRepeatedStringInList(tag.UserList)
|
||||||
for _, v := range reduceUserIDList {
|
for _, v := range reduceUserIDList {
|
||||||
for i2, v2 := range tag.UserList {
|
for i2, v2 := range tag.UserList {
|
||||||
if v == v2 {
|
if v == v2 {
|
||||||
|
@ -216,10 +216,10 @@ func GetGroupMaster(groupId string) (db.GroupMember, error) {
|
|||||||
return groupMember, nil
|
return groupMember, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateGroupInfoDefaultZero(groupInfo db.Group, args map[string]interface{}) error {
|
func UpdateGroupInfoDefaultZero(groupID string, args map[string]interface{}) error {
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return dbConn.Model(groupInfo).Updates(args).Error
|
return dbConn.Table("groups").Where("group_id = ? ", groupID).Update(args).Error
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@ func loggerInit(moduleName string) *Logger {
|
|||||||
}
|
}
|
||||||
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||||
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
||||||
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "debug", moduleName),
|
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "info", moduleName),
|
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "warn", moduleName),
|
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "error", moduleName),
|
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||||
}, &nested.Formatter{
|
}, &nested.Formatter{
|
||||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||||
HideKeys: false,
|
HideKeys: false,
|
||||||
|
@ -101,7 +101,7 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsAppManagerAccess(token string, OpUserID string) bool {
|
func IsAppManagerAccess(token string, OpUserID string) bool {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ func CheckAccess(OpUserID string, OwnerUserID string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(operationID, "ParseToken failed, ", err.Error(), token)
|
log.Error(operationID, "ParseToken failed, ", err.Error(), token)
|
||||||
return false, ""
|
return false, ""
|
||||||
@ -138,31 +138,31 @@ func GetUserIDFromToken(token string, operationID string) (bool, string) {
|
|||||||
return true, claims.UID
|
return true, claims.UID
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseToken(tokensString string) (claims *Claims, err error) {
|
func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
|
||||||
|
|
||||||
claims, err = GetClaimFromToken(tokensString)
|
claims, err = GetClaimFromToken(tokensString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", "token validate err", err.Error())
|
log.NewError(operationID, "token validate err", err.Error(), tokensString)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
m, err := commonDB.DB.GetTokenMapByUidPid(claims.UID, claims.Platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError("", "get token from redis err", err.Error())
|
log.NewError(operationID, "get token from redis err", err.Error(), tokensString)
|
||||||
return nil, &constant.ErrTokenInvalid
|
return nil, &constant.ErrTokenInvalid
|
||||||
}
|
}
|
||||||
if m == nil {
|
if m == nil {
|
||||||
log.NewError("", "get token from redis err", "m is nil")
|
log.NewError(operationID, "get token from redis err", "m is nil", tokensString)
|
||||||
return nil, &constant.ErrTokenInvalid
|
return nil, &constant.ErrTokenInvalid
|
||||||
}
|
}
|
||||||
if v, ok := m[tokensString]; ok {
|
if v, ok := m[tokensString]; ok {
|
||||||
switch v {
|
switch v {
|
||||||
case constant.NormalToken:
|
case constant.NormalToken:
|
||||||
log.NewDebug("", "this is normal return", claims)
|
log.NewDebug(operationID, "this is normal return", claims)
|
||||||
return claims, nil
|
return claims, nil
|
||||||
case constant.InValidToken:
|
case constant.InValidToken:
|
||||||
return nil, &constant.ErrTokenInvalid
|
return nil, &constant.ErrTokenInvalid
|
||||||
case constant.KickedToken:
|
case constant.KickedToken:
|
||||||
|
log.Error(operationID, "this token has been kicked by other same terminal ", constant.ErrTokenKicked)
|
||||||
return nil, &constant.ErrTokenKicked
|
return nil, &constant.ErrTokenKicked
|
||||||
case constant.ExpiredToken:
|
case constant.ExpiredToken:
|
||||||
return nil, &constant.ErrTokenExpired
|
return nil, &constant.ErrTokenExpired
|
||||||
@ -170,6 +170,7 @@ func ParseToken(tokensString string) (claims *Claims, err error) {
|
|||||||
return nil, &constant.ErrTokenUnknown
|
return nil, &constant.ErrTokenUnknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.NewError(operationID, "redis token map not find", constant.ErrTokenUnknown)
|
||||||
return nil, &constant.ErrTokenUnknown
|
return nil, &constant.ErrTokenUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +196,7 @@ func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {
|
|||||||
|
|
||||||
//Validation token, false means failure, true means successful verification
|
//Validation token, false means failure, true means successful verification
|
||||||
func VerifyToken(token, uid string) (bool, error) {
|
func VerifyToken(token, uid string) (bool, error) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -207,7 +208,7 @@ func VerifyToken(token, uid string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
|
func WsVerifyToken(token, uid string, platformID string) (bool, error, string) {
|
||||||
claims, err := ParseToken(token)
|
claims, err := ParseToken(token, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err, "parse token err"
|
return false, err, "parse token err"
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,10 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group
|
|||||||
dst.AppMangerLevel = 1
|
dst.AppMangerLevel = 1
|
||||||
}
|
}
|
||||||
dst.JoinTime = int32(src.JoinTime.Unix())
|
dst.JoinTime = int32(src.JoinTime.Unix())
|
||||||
|
if src.MuteEndTime.Unix() < 0 {
|
||||||
|
dst.JoinTime = 0
|
||||||
|
return nil
|
||||||
|
}
|
||||||
dst.MuteEndTime = uint32(src.MuteEndTime.Unix())
|
dst.MuteEndTime = uint32(src.MuteEndTime.Unix())
|
||||||
if dst.MuteEndTime < uint32(time.Now().Unix()) {
|
if dst.MuteEndTime < uint32(time.Now().Unix()) {
|
||||||
dst.MuteEndTime = 0
|
dst.MuteEndTime = 0
|
||||||
|
@ -77,7 +77,7 @@ func OperationIDGenerator() string {
|
|||||||
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
|
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveUserIDRepByMap(slc []string) []string {
|
func RemoveRepeatedStringInList(slc []string) []string {
|
||||||
var result []string
|
var result []string
|
||||||
tempMap := map[string]byte{}
|
tempMap := map[string]byte{}
|
||||||
for _, e := range slc {
|
for _, e := range slc {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user