From e4f87b53b485237d56eb1d7cf82e4c10962291d3 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 20 Jan 2022 11:53:57 +0800 Subject: [PATCH] protocol modify --- cmd/open_im_api/main.go | 1 - internal/api/chat/pull_msg.go | 77 +++-------------------------------- 2 files changed, 6 insertions(+), 72 deletions(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 7f8fd7db2..817042f5c 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -81,7 +81,6 @@ func main() { chatGroup := r.Group("/msg") { 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) } diff --git a/internal/api/chat/pull_msg.go b/internal/api/chat/pull_msg.go index 56903f5cc..0872319c6 100644 --- a/internal/api/chat/pull_msg.go +++ b/internal/api/chat/pull_msg.go @@ -23,61 +23,11 @@ type paramsUserPullMsg struct { } } -func PullMsg(c *gin.Context) { - params := paramsUserPullMsg{} - 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 ok, err := token_verify.VerifyToken(token, params.SendID); !ok { - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err" + err.Error()}) - return - } - pbData := open_im_sdk.PullMessageReq{} - pbData.UserID = params.SendID - pbData.OperationID = params.OperationID - pbData.SeqBegin = *params.Data.SeqBegin - pbData.SeqEnd = *params.Data.SeqEnd - grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName) - msgClient := pbChat.NewChatClient(grpcConn) - reply, err := msgClient.PullMessage(context.Background(), &pbData) - if err != nil { - log.NewError(params.OperationID, "UserPullMsg rpc failed, ", params, err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "UserPullMsg rpc failed, " + err.Error()}) - return - } - log.InfoByKv("rpc call success to pullMsgRep", pbData.OperationID, "ReplyArgs", reply.String(), "maxSeq", reply.GetMaxSeq(), - "MinSeq", reply.GetMinSeq(), "singLen", len(reply.GetSingleUserMsg()), "groupLen", len(reply.GetGroupUserMsg())) - - msg := make(map[string]interface{}) - if v := reply.GetSingleUserMsg(); v != nil { - msg["single"] = v - } else { - msg["single"] = []open_im_sdk.GatherFormat{} - } - if v := reply.GetGroupUserMsg(); v != nil { - msg["group"] = v - } else { - msg["group"] = []open_im_sdk.GatherFormat{} - } - msg["maxSeq"] = reply.GetMaxSeq() - msg["minSeq"] = reply.GetMinSeq() - c.JSON(http.StatusOK, gin.H{ - "errCode": reply.ErrCode, - "errMsg": reply.ErrMsg, - "reqIdentifier": *params.ReqIdentifier, - "data": msg, - }) - -} - type paramsUserPullMsgBySeqList struct { - ReqIdentifier int `json:"reqIdentifier" binding:"required"` - SendID string `json:"sendID" binding:"required"` - OperationID string `json:"operationID" binding:"required"` - SeqList []int64 `json:"seqList"` + ReqIdentifier int `json:"reqIdentifier" binding:"required"` + SendID string `json:"sendID" binding:"required"` + OperationID string `json:"operationID" binding:"required"` + SeqList []uint32 `json:"seqList"` } func PullMsgBySeqList(c *gin.Context) { @@ -104,26 +54,11 @@ func PullMsgBySeqList(c *gin.Context) { log.ErrorByKv("PullMessageBySeqList error", pbData.OperationID, "err", err.Error()) return } - log.InfoByKv("rpc call success to PullMessageBySeqList", pbData.OperationID, "ReplyArgs", reply.String(), "maxSeq", reply.GetMaxSeq(), - "MinSeq", reply.GetMinSeq(), "singLen", len(reply.GetSingleUserMsg()), "groupLen", len(reply.GetGroupUserMsg())) - - msg := make(map[string]interface{}) - if v := reply.GetSingleUserMsg(); v != nil { - msg["single"] = v - } else { - msg["single"] = []open_im_sdk.GatherFormat{} - } - if v := reply.GetGroupUserMsg(); v != nil { - msg["group"] = v - } else { - msg["group"] = []open_im_sdk.GatherFormat{} - } - msg["maxSeq"] = reply.GetMaxSeq() - msg["minSeq"] = reply.GetMinSeq() + log.InfoByKv("rpc call success to PullMessageBySeqList", pbData.OperationID, "ReplyArgs", reply.String(), len(reply.List)) c.JSON(http.StatusOK, gin.H{ "errCode": reply.ErrCode, "errMsg": reply.ErrMsg, "reqIdentifier": params.ReqIdentifier, - "data": msg, + "data": reply.List, }) }