Files
open-im-server/internal/api/msg/pull_msg.go
T

74 lines
2.4 KiB
Go
Raw Normal View History

2022-07-20 21:26:52 +08:00
package msg
2021-05-26 19:15:25 +08:00
import (
2023-02-23 19:15:30 +08:00
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/log"
"OpenIM/pkg/common/tokenverify"
"OpenIM/pkg/proto/msg"
sdkws "OpenIM/pkg/proto/sdkws"
"OpenIM/pkg/utils"
2021-05-26 19:15:25 +08:00
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
type paramsUserPullMsg struct {
2021-06-28 15:26:31 +08:00
ReqIdentifier *int `json:"reqIdentifier" binding:"required"`
2021-05-26 19:15:25 +08:00
SendID string `json:"sendID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
Data struct {
2021-06-28 15:26:31 +08:00
SeqBegin *int64 `json:"seqBegin" binding:"required"`
SeqEnd *int64 `json:"seqEnd" binding:"required"`
2021-05-26 19:15:25 +08:00
}
}
type paramsUserPullMsgBySeqList struct {
2022-01-20 11:53:57 +08:00
ReqIdentifier int `json:"reqIdentifier" binding:"required"`
SendID string `json:"sendID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
SeqList []uint32 `json:"seqList"`
}
2021-12-23 19:37:41 +08:00
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()})
return
}
token := c.Request.Header.Get("token")
2023-02-09 14:40:49 +08:00
if ok, err := tokenverify.VerifyToken(token, params.SendID); !ok {
2022-03-16 20:37:37 +08:00
if err != nil {
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error(), token, params.SendID)
}
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
return
}
2023-02-10 18:13:58 +08:00
pbData := sdkws.PullMessageBySeqListReq{}
pbData.UserID = params.SendID
pbData.OperationID = params.OperationID
pbData.SeqList = params.SeqList
2023-02-07 20:24:20 +08:00
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, pbData.OperationID)
2022-06-16 14:31:41 +08:00
if grpcConn == nil {
2022-08-17 12:12:54 +08:00
errMsg := pbData.OperationID + "getcdv3.GetDefaultConn == nil"
2022-06-16 14:31:41 +08:00
log.NewError(pbData.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
2022-07-20 21:20:46 +08:00
msgClient := msg.NewMsgClient(grpcConn)
reply, err := msgClient.PullMessageBySeqList(context.Background(), &pbData)
if err != nil {
2022-05-10 09:09:37 +08:00
log.Error(pbData.OperationID, "PullMessageBySeqList error", err.Error())
return
}
2022-05-10 09:09:37 +08:00
log.NewInfo(pbData.OperationID, "rpc call success to PullMessageBySeqList", reply.String(), len(reply.List))
c.JSON(http.StatusOK, gin.H{
"errCode": reply.ErrCode,
"errMsg": reply.ErrMsg,
"reqIdentifier": params.ReqIdentifier,
2022-01-20 11:53:57 +08:00
"data": reply.List,
})
}