diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 5ae47b938..7d0fbceb3 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -130,6 +130,7 @@ func main() { conversationGroup.POST("/set_conversation", conversation.SetConversation) conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations) conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt) + conversationGroup.POST("/modify_conversation_field", conversation.ModifyConversationField) } // office officeGroup := r.Group("/office") diff --git a/internal/api/conversation/conversation.go b/internal/api/conversation/conversation.go index 3d580864f..dcaa2b62e 100644 --- a/internal/api/conversation/conversation.go +++ b/internal/api/conversation/conversation.go @@ -5,6 +5,7 @@ import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" + pbConversation "Open_IM/pkg/proto/conversation" pbUser "Open_IM/pkg/proto/user" "Open_IM/pkg/utils" "context" @@ -44,6 +45,37 @@ func SetConversation(c *gin.Context) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) c.JSON(http.StatusOK, resp) } +func ModifyConversationField(c *gin.Context) { + var ( + req api.ModifyConversationFieldReq + resp api.ModifyConversationFieldResp + reqPb pbConversation.ModifyConversationFieldReq + ) + if err := c.BindJSON(&req); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()}) + return + } + reqPb.Conversation = &pbConversation.Conversation{} + err := utils.CopyStructFields(&reqPb, req) + err = utils.CopyStructFields(reqPb.Conversation, req.Conversation) + if err != nil { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error()) + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", reqPb.String()) + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName) + client := pbConversation.NewConversationClient(etcdConn) + respPb, err := client.ModifyConversationField(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()}) + return + } + resp.ErrMsg = respPb.CommonResp.ErrMsg + resp.ErrCode = respPb.CommonResp.ErrCode + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) + c.JSON(http.StatusOK, resp) +} func BatchSetConversations(c *gin.Context) { var ( diff --git a/pkg/base_info/conversation_api_struct.go b/pkg/base_info/conversation_api_struct.go index 5e9d021f6..30890f7eb 100644 --- a/pkg/base_info/conversation_api_struct.go +++ b/pkg/base_info/conversation_api_struct.go @@ -58,6 +58,15 @@ type SetConversationReq struct { type SetConversationResp struct { CommResp } +type ModifyConversationFieldReq struct { + Conversation + FieldType int32 `json:"fieldType" binding:"required"` + UserIDList []string `json:"userIDList" binding:"required"` + OperationID string `json:"operationID" binding:"required"` +} +type ModifyConversationFieldResp struct { + CommResp +} type BatchSetConversationsReq struct { Conversations []Conversation `json:"conversations" binding:"required"`