send msg file modify

pull/131/head
Gordon 3 years ago
parent d40e1e47fd
commit ba249d294e

@ -77,10 +77,10 @@ func main() {
//Message
chatGroup := r.Group("/msg")
{
chatGroup.POST("/newest_seq", apiChat.UserGetSeq)
chatGroup.POST("/pull_msg", apiChat.UserPullMsg)
chatGroup.POST("/send_msg", apiChat.UserSendMsg)
chatGroup.POST("/pull_msg_by_seq", apiChat.UserPullMsgBySeqList)
chatGroup.POST("/newest_seq", apiChat.GetSeq)
chatGroup.POST("/pull_msg", apiChat.PullMsg)
chatGroup.POST("/send_msg", apiChat.SendMsg)
chatGroup.POST("/pull_msg_by_seq", apiChat.PullMsgBySeqList)
}
//Manager
managementGroup := r.Group("/manager")

@ -19,7 +19,7 @@ type paramsUserNewestSeq struct {
MsgIncr int `json:"msgIncr" binding:"required"`
}
func UserGetSeq(c *gin.Context) {
func GetSeq(c *gin.Context) {
params := paramsUserNewestSeq{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})

@ -6,6 +6,7 @@ import (
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"Open_IM/pkg/proto/chat"
"Open_IM/pkg/proto/sdk_ws"
"context"
"github.com/gin-gonic/gin"
"net/http"
@ -22,7 +23,7 @@ type paramsUserPullMsg struct {
}
}
func UserPullMsg(c *gin.Context) {
func PullMsg(c *gin.Context) {
params := paramsUserPullMsg{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
@ -34,7 +35,7 @@ func UserPullMsg(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err" + err.Error()})
return
}
pbData := pbChat.PullMessageReq{}
pbData := open_im_sdk.PullMessageReq{}
pbData.UserID = params.SendID
pbData.OperationID = params.OperationID
pbData.SeqBegin = *params.Data.SeqBegin
@ -54,12 +55,12 @@ func UserPullMsg(c *gin.Context) {
if v := reply.GetSingleUserMsg(); v != nil {
msg["single"] = v
} else {
msg["single"] = []pbChat.GatherFormat{}
msg["single"] = []open_im_sdk.GatherFormat{}
}
if v := reply.GetGroupUserMsg(); v != nil {
msg["group"] = v
} else {
msg["group"] = []pbChat.GatherFormat{}
msg["group"] = []open_im_sdk.GatherFormat{}
}
msg["maxSeq"] = reply.GetMaxSeq()
msg["minSeq"] = reply.GetMinSeq()
@ -79,7 +80,7 @@ type paramsUserPullMsgBySeqList struct {
SeqList []int64 `json:"seqList"`
}
func UserPullMsgBySeqList(c *gin.Context) {
func PullMsgBySeqList(c *gin.Context) {
params := paramsUserPullMsgBySeqList{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
@ -91,7 +92,7 @@ func UserPullMsgBySeqList(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err" + err.Error()})
return
}
pbData := pbChat.PullMessageBySeqListReq{}
pbData := open_im_sdk.PullMessageBySeqListReq{}
pbData.UserID = params.SendID
pbData.OperationID = params.OperationID
pbData.SeqList = params.SeqList
@ -110,12 +111,12 @@ func UserPullMsgBySeqList(c *gin.Context) {
if v := reply.GetSingleUserMsg(); v != nil {
msg["single"] = v
} else {
msg["single"] = []pbChat.GatherFormat{}
msg["single"] = []open_im_sdk.GatherFormat{}
}
if v := reply.GetGroupUserMsg(); v != nil {
msg["group"] = v
} else {
msg["group"] = []pbChat.GatherFormat{}
msg["group"] = []open_im_sdk.GatherFormat{}
}
msg["maxSeq"] = reply.GetMaxSeq()
msg["minSeq"] = reply.GetMinSeq()

@ -4,7 +4,7 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
pbChat "Open_IM/pkg/proto/chat"
"Open_IM/pkg/utils"
"Open_IM/pkg/proto/sdk_ws"
"context"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
@ -14,50 +14,51 @@ import (
)
type paramsUserSendMsg struct {
ReqIdentifier int32 `json:"reqIdentifier" binding:"required"`
PlatformID int32 `json:"platformID" binding:"required"`
SendID string `json:"sendID" binding:"required"`
SenderNickName string `json:"senderNickName"`
SenderFaceURL string `json:"senderFaceUrl"`
OperationID string `json:"operationID" binding:"required"`
Data struct {
SessionType int32 `json:"sessionType" binding:"required"`
MsgFrom int32 `json:"msgFrom" binding:"required"`
ContentType int32 `json:"contentType" binding:"required"`
RecvID string `json:"recvID" binding:"required"`
ForceList []string `json:"forceList"`
Content string `json:"content" binding:"required"`
Options map[string]int32 `json:"options" `
ClientMsgID string `json:"clientMsgID" binding:"required"`
OffLineInfo map[string]interface{} `json:"offlineInfo" `
Ex map[string]interface{} `json:"ext"`
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
SendID string `json:"sendID" binding:"required"`
SenderNickName string `json:"senderNickName"`
SenderFaceURL string `json:"senderFaceUrl"`
OperationID string `json:"operationID" binding:"required"`
Data struct {
SessionType int32 `json:"sessionType" binding:"required"`
MsgFrom int32 `json:"msgFrom" binding:"required"`
ContentType int32 `json:"contentType" binding:"required"`
RecvID string `json:"recvID" `
GroupID string `json:"groupID" `
ForceList []string `json:"forceList"`
Content []byte `json:"content" binding:"required"`
Options map[string]bool `json:"options" `
ClientMsgID string `json:"clientMsgID" binding:"required"`
CreateTime int64 `json:"createTime" binding:"required"`
OffLineInfo *open_im_sdk.OfflinePushInfo `json:"offlineInfo" `
}
}
func newUserSendMsgReq(token string, params *paramsUserSendMsg) *pbChat.SendMsgReq {
pbData := pbChat.SendMsgReq{
ReqIdentifier: params.ReqIdentifier,
Token: token,
SendID: params.SendID,
SenderNickName: params.SenderNickName,
SenderFaceURL: params.SenderFaceURL,
OperationID: params.OperationID,
PlatformID: params.PlatformID,
SessionType: params.Data.SessionType,
MsgFrom: params.Data.MsgFrom,
ContentType: params.Data.ContentType,
RecvID: params.Data.RecvID,
ForceList: params.Data.ForceList,
Content: params.Data.Content,
Options: utils.MapIntToJsonString(params.Data.Options),
ClientMsgID: params.Data.ClientMsgID,
OffLineInfo: utils.MapToJsonString(params.Data.OffLineInfo),
Ex: utils.MapToJsonString(params.Data.Ex),
Token: token,
OperationID: params.OperationID,
MsgData: &open_im_sdk.MsgData{
SendID: params.SendID,
RecvID: params.Data.RecvID,
GroupID: params.Data.GroupID,
ClientMsgID: params.Data.ClientMsgID,
SenderPlatformID: params.SenderPlatformID,
SenderNickName: params.SenderNickName,
SenderFaceURL: params.SenderFaceURL,
SessionType: params.Data.SessionType,
MsgFrom: params.Data.MsgFrom,
ContentType: params.Data.ContentType,
Content: params.Data.Content,
CreateTime: params.Data.CreateTime,
Options: params.Data.Options,
OfflinePushInfo: params.Data.OffLineInfo,
},
}
return &pbData
}
func UserSendMsg(c *gin.Context) {
func SendMsg(c *gin.Context) {
params := paramsUserSendMsg{}
if err := c.BindJSON(&params); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
@ -86,9 +87,8 @@ func UserSendMsg(c *gin.Context) {
log.Info("", "", "api SendMsg call end..., [data: %s] [reply: %s]", pbData.String(), reply.String())
c.JSON(http.StatusOK, gin.H{
"errCode": reply.ErrCode,
"errMsg": reply.ErrMsg,
"reqIdentifier": reply.ReqIdentifier,
"errCode": reply.ErrCode,
"errMsg": reply.ErrMsg,
"data": gin.H{
"clientMsgID": reply.ClientMsgID,
"serverMsgID": reply.ServerMsgID,

@ -13,6 +13,7 @@ import (
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbChat "Open_IM/pkg/proto/chat"
"Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"github.com/gin-gonic/gin"
@ -25,20 +26,22 @@ import (
var validate *validator.Validate
type paramsManagementSendMsg struct {
OperationID string `json:"operationID" binding:"required"`
SendID string `json:"sendID" binding:"required"`
RecvID string `json:"recvID" binding:"required"`
SenderNickName string `json:"senderNickName" `
SenderFaceURL string `json:"senderFaceURL" `
SenderPlatformID int32 `json:"senderPlatformID"`
ForceList []string `json:"forceList" `
Content map[string]interface{} `json:"content" binding:"required"`
ContentType int32 `json:"contentType" binding:"required"`
SessionType int32 `json:"sessionType" binding:"required"`
IsOnlineOnly bool `json:"isOnlineOnly"`
OperationID string `json:"operationID" binding:"required"`
SendID string `json:"sendID" binding:"required"`
RecvID string `json:"recvID" `
GroupID string `json:"groupID" `
SenderNickName string `json:"senderNickName" `
SenderFaceURL string `json:"senderFaceURL" `
SenderPlatformID int32 `json:"senderPlatformID"`
ForceList []string `json:"forceList" `
Content map[string]interface{} `json:"content" binding:"required"`
ContentType int32 `json:"contentType" binding:"required"`
SessionType int32 `json:"sessionType" binding:"required"`
IsOnlineOnly bool `json:"isOnlineOnly"`
OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"`
}
func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.UserSendMsgReq {
func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.SendMsgReq {
var newContent string
switch params.ContentType {
case constant.Text:
@ -53,26 +56,31 @@ func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.UserSendMsgReq {
newContent = utils.StructToJsonString(params.Content)
default:
}
options := make(map[string]int32, 2)
options := make(map[string]bool, 2)
if params.IsOnlineOnly {
options["history"] = 0
options["persistent"] = 0
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
}
pbData := pbChat.UserSendMsgReq{
ReqIdentifier: constant.WSSendMsg,
SendID: params.SendID,
SenderNickName: params.SenderNickName,
SenderFaceURL: params.SenderFaceURL,
OperationID: params.OperationID,
PlatformID: params.SenderPlatformID,
SessionType: params.SessionType,
MsgFrom: constant.UserMsgType,
ContentType: params.ContentType,
RecvID: params.RecvID,
ForceList: params.ForceList,
Content: newContent,
ClientMsgID: utils.GetMsgID(params.SendID),
Options: utils.MapIntToJsonString(options),
pbData := pbChat.SendMsgReq{
OperationID: params.OperationID,
MsgData: &open_im_sdk.MsgData{
SendID: params.SendID,
RecvID: params.RecvID,
GroupID: params.GroupID,
ClientMsgID: utils.GetMsgID(params.SendID),
SenderPlatformID: params.SenderPlatformID,
SenderNickName: params.SenderNickName,
SenderFaceURL: params.SenderFaceURL,
SessionType: params.SessionType,
MsgFrom: constant.SysMsgType,
ContentType: params.ContentType,
Content: []byte(newContent),
ForceList: params.ForceList,
CreateTime: utils.GetCurrentTimestampByNano(),
Options: options,
OfflinePushInfo: params.OfflinePushInfo,
},
}
return &pbData
}
@ -135,6 +143,19 @@ func ManagementSendMsg(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
return
}
switch params.SessionType {
case constant.SingleChatType:
if len(params.RecvID) == 0 {
log.NewError(params.OperationID, "recvID is a null string")
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "recvID is a null string", "sendTime": 0, "MsgID": ""})
}
case constant.GroupChatType:
if len(params.GroupID) == 0 {
log.NewError(params.OperationID, "groupID is a null string")
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "groupID is a null string", "sendTime": 0, "MsgID": ""})
}
}
log.InfoByKv("Ws call success to ManagementSendMsgReq", params.OperationID, "Parameters", params)
@ -146,7 +167,7 @@ func ManagementSendMsg(c *gin.Context) {
log.Info("", "", "api ManagementSendMsg call, api call rpc...")
reply, err := client.UserSendMsg(context.Background(), pbData)
reply, err := client.SendMsg(context.Background(), pbData)
if err != nil {
log.NewError(params.OperationID, "call delete UserSendMsg rpc server failed", err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call UserSendMsg rpc server failed"})

@ -155,7 +155,6 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
client := pbGroup.NewGroupClient(etcdConn)
req := &pbGroup.GetGroupAllMemberReq{
GroupID: pb.MsgData.GroupID,
Token: pb.Token,
OperationID: pb.OperationID,
}
reply, err := client.GetGroupAllMember(context.Background(), req)
@ -169,13 +168,13 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
}
groupID := pb.MsgData.GroupID
for _, v := range reply.MemberList {
pb.MsgData.RecvID = v.UserId
isSend := modifyMessageByUserMessageReceiveOpt(v.UserId, groupID, constant.GroupChatType, pb)
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)
err := rpc.sendMsgToKafka(&msgToMQ, v.UserID)
if err != nil {
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v.UserId, msgToMQ.String())
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v.UserID, msgToMQ.String())
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
}
}

Loading…
Cancel
Save