You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
4 years ago
|
package apiChat
|
||
|
|
||
|
import (
|
||
3 years ago
|
"Open_IM/pkg/common/config"
|
||
|
"Open_IM/pkg/common/log"
|
||
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||
3 years ago
|
pbMsg "Open_IM/pkg/proto/chat"
|
||
|
"Open_IM/pkg/utils"
|
||
4 years ago
|
"context"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type paramsUserNewestSeq struct {
|
||
|
ReqIdentifier int `json:"reqIdentifier" binding:"required"`
|
||
|
SendID string `json:"sendID" binding:"required"`
|
||
|
OperationID string `json:"operationID" binding:"required"`
|
||
|
MsgIncr int `json:"msgIncr" binding:"required"`
|
||
|
}
|
||
|
|
||
3 years ago
|
func UserGetSeq(c *gin.Context) {
|
||
4 years ago
|
params := paramsUserNewestSeq{}
|
||
|
if err := c.BindJSON(¶ms); err != nil {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
token := c.Request.Header.Get("token")
|
||
|
if !utils.VerifyToken(token, params.SendID) {
|
||
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
|
||
|
return
|
||
|
}
|
||
3 years ago
|
pbData := pbMsg.GetMaxAndMinSeqReq{}
|
||
4 years ago
|
pbData.UserID = params.SendID
|
||
|
pbData.OperationID = params.OperationID
|
||
|
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||
3 years ago
|
|
||
4 years ago
|
if grpcConn == nil {
|
||
|
log.ErrorByKv("get grpcConn err", pbData.OperationID, "args", params)
|
||
|
}
|
||
|
msgClient := pbMsg.NewChatClient(grpcConn)
|
||
3 years ago
|
reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData)
|
||
4 years ago
|
if err != nil {
|
||
|
log.ErrorByKv("rpc call failed to getNewSeq", pbData.OperationID, "err", err, "pbData", pbData.String())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, gin.H{
|
||
|
"errCode": reply.ErrCode,
|
||
|
"errMsg": reply.ErrMsg,
|
||
|
"msgIncr": params.MsgIncr,
|
||
|
"reqIdentifier": params.ReqIdentifier,
|
||
|
"data": gin.H{
|
||
3 years ago
|
"maxSeq": reply.MaxSeq,
|
||
|
"minSeq": reply.MinSeq,
|
||
4 years ago
|
},
|
||
|
})
|
||
|
|
||
|
}
|