From 504e4cc6a3c5604c578af3e1038bf77e16d6d934 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Tue, 12 Jul 2022 16:16:04 +0800 Subject: [PATCH] add super delete --- cmd/open_im_api/main.go | 1 + internal/api/chat/del_msg.go | 78 +++++++++++++++++++++++++++++++++ pkg/base_info/msg.go | 16 +++++++ pkg/common/constant/constant.go | 1 + 4 files changed, 96 insertions(+) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 37ceefff2..8411df63a 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -139,6 +139,7 @@ func main() { chatGroup.POST("/send_msg", apiChat.SendMsg) chatGroup.POST("/pull_msg_by_seq", apiChat.PullMsgBySeqList) chatGroup.POST("/del_msg", apiChat.DelMsg) + chatGroup.POST("/del_super_group_msg", apiChat.DelSuperGroupMsg) chatGroup.POST("/clear_msg", apiChat.ClearMsg) chatGroup.POST("/manage_send_msg", manage.ManagementSendMsg) chatGroup.POST("/batch_send_msg", manage.ManagementBatchSendMsg) diff --git a/internal/api/chat/del_msg.go b/internal/api/chat/del_msg.go index c6a6da385..a5131897f 100644 --- a/internal/api/chat/del_msg.go +++ b/internal/api/chat/del_msg.go @@ -12,6 +12,7 @@ import ( "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" + "github.com/golang/protobuf/proto" "net/http" "strings" ) @@ -72,6 +73,83 @@ func DelMsg(c *gin.Context) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) c.JSON(http.StatusOK, resp) } +func DelSuperGroupMsg(c *gin.Context) { + var ( + req api.DelSuperGroupMsgReq + resp api.DelSuperGroupMsgResp + ) + if err := c.BindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) + + ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + errMsg := req.OperationID + " " + opUserID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + options := make(map[string]bool, 5) + utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false) + utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false) + utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false) + utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false) + pbData := rpc.SendMsgReq{ + OperationID: req.OperationID, + MsgData: &pbCommon.MsgData{ + SendID: req.UserID, + RecvID: req.UserID, + ClientMsgID: utils.GetMsgID(req.UserID), + SessionType: constant.SingleChatType, + MsgFrom: constant.SysMsgType, + ContentType: constant.MsgDeleteNotification, + // ForceList: params.ForceList, + CreateTime: utils.GetCurrentTimestampByMill(), + Options: options, + }, + } + var tips pbCommon.TipsComm + deleteMsg := api.MsgDeleteNotificationElem{ + GroupID: req.GroupID, + IsAllDelete: req.IsAllDelete, + SeqList: req.SeqList, + } + tips.JsonDetail = utils.StructToJsonString(deleteMsg) + var err error + pbData.MsgData.Content, err = proto.Marshal(&tips) + if err != nil { + log.Error(req.OperationID, "Marshal failed ", err.Error(), tips.String()) + resp.ErrCode = 400 + resp.ErrMsg = err.Error() + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) + } + log.Info(req.OperationID, "", "api DelSuperGroupMsg call start..., [data: %s]", pbData.String()) + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName, req.OperationID) + if etcdConn == nil { + errMsg := req.OperationID + "getcdv3.GetConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + client := rpc.NewChatClient(etcdConn) + + log.Info(req.OperationID, "", "api DelSuperGroupMsg call, api call rpc...") + + RpcResp, err := client.SendMsg(context.Background(), &pbData) + if err != nil { + log.NewError(req.OperationID, "call delete UserSendMsg rpc server failed", err.Error()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call UserSendMsg rpc server failed"}) + return + } + log.Info(req.OperationID, "", "api DelSuperGroupMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String()) + resp.ErrCode = RpcResp.ErrCode + resp.ErrMsg = RpcResp.ErrMsg + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) +} // @Summary 清空用户消息 // @Description 清空用户消息 diff --git a/pkg/base_info/msg.go b/pkg/base_info/msg.go index 153313f65..f6b134ef3 100644 --- a/pkg/base_info/msg.go +++ b/pkg/base_info/msg.go @@ -18,3 +18,19 @@ type CleanUpMsgReq struct { type CleanUpMsgResp struct { CommResp } +type DelSuperGroupMsgReq struct { + UserID string `json:"userID,omitempty" binding:"required"` + GroupID string `json:"groupID,omitempty" binding:"required"` + SeqList []uint32 `json:"seqList,omitempty"` + IsAllDelete bool `json:"isAllDelete"` + OperationID string `json:"operationID,omitempty" binding:"required"` +} + +type DelSuperGroupMsgResp struct { + CommResp +} +type MsgDeleteNotificationElem struct { + GroupID string `json:"groupID"` + IsAllDelete bool `json:"isAllDelete"` + SeqList []uint32 `json:"seqList"` +} diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index ff857ef5c..39fccb88e 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -58,6 +58,7 @@ const ( FriendRemarkSetNotification = 1206 //set_friend_remark? BlackAddedNotification = 1207 //add_black BlackDeletedNotification = 1208 //remove_black + MsgDeleteNotification = 1209 ConversationOptChangeNotification = 1300 // change conversation opt