mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 00:55:59 +08:00
change send message by ws and optimization
This commit is contained in:
@@ -70,3 +70,58 @@ func UserPullMsg(c *gin.Context) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func UserPullMsgBySeqList(c *gin.Context) {
|
||||
params := paramsUserPullMsgBySeqList{}
|
||||
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
|
||||
}
|
||||
pbData := pbChat.PullMessageBySeqListReq{}
|
||||
pbData.UserID = params.SendID
|
||||
pbData.OperationID = params.OperationID
|
||||
pbData.SeqList = params.SeqList
|
||||
|
||||
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
msgClient := pbChat.NewChatClient(grpcConn)
|
||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
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"] = []pbChat.GatherFormat{}
|
||||
}
|
||||
if v := reply.GetGroupUserMsg(); v != nil {
|
||||
msg["group"] = v
|
||||
} else {
|
||||
msg["group"] = []pbChat.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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func UserSendMsg(c *gin.Context) {
|
||||
"data": gin.H{
|
||||
"clientMsgID": reply.ClientMsgID,
|
||||
"serverMsgID": reply.ServerMsgID,
|
||||
"sendTime": reply.SendTime,
|
||||
"sendTime": 0,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ func ImportFriend(c *gin.Context) {
|
||||
OwnerUid: params.OwnerUid,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.ErrorByKv("ImportFriend Test start", params.OperationID)
|
||||
RpcResp, err := client.ImportFriend(context.Background(), req)
|
||||
//log.ErrorByKv("ImportFriend Test end", params.OperationID, "resp", RpcResp, "err", err.Error())
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,ImportFriend failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed" + err.Error()})
|
||||
|
||||
@@ -125,7 +125,7 @@ func ManagementSendMsg(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"sendTime": reply.SendTime,
|
||||
"sendTime": "",
|
||||
"msgID": reply.ClientMsgID,
|
||||
})
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ func main() {
|
||||
chatGroup.POST("/newest_seq", apiChat.UserNewestSeq)
|
||||
chatGroup.POST("/pull_msg", apiChat.UserPullMsg)
|
||||
chatGroup.POST("/send_msg", apiChat.UserSendMsg)
|
||||
chatGroup.POST("/pull_msg_by_seq", apiChat.UserPullMsgBySeqList)
|
||||
}
|
||||
//Manager
|
||||
managementGroup := r.Group("/manager")
|
||||
|
||||
Reference in New Issue
Block a user