user update

This commit is contained in:
Gordon
2023-03-20 19:34:50 +08:00
parent 99c486295b
commit 78d5fa30ba
4 changed files with 54 additions and 46 deletions
+36 -40
View File
@@ -2,7 +2,6 @@ package api
import (
"context"
"errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
@@ -23,23 +22,23 @@ import (
var _ context.Context // 解决goland编辑器bug
func NewMsg(c discoveryregistry.SvcDiscoveryRegistry) *Msg {
return &Msg{c: c, validate: validator.New()}
func NewMsg(c discoveryregistry.SvcDiscoveryRegistry) *Message {
return &Message{c: c, validate: validator.New()}
}
type Msg struct {
type Message struct {
c discoveryregistry.SvcDiscoveryRegistry
validate *validator.Validate
}
func (Msg) SetOptions(options map[string]bool, value bool) {
func (Message) SetOptions(options map[string]bool, value bool) {
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, value)
}
func (m Msg) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
var newContent string
var err error
switch params.ContentType {
@@ -106,7 +105,7 @@ func (m Msg) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendM
return &pbData
}
func (m *Msg) client() (msg.MsgClient, error) {
func (m *Message) client() (msg.MsgClient, error) {
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
return nil, err
@@ -114,46 +113,46 @@ func (m *Msg) client() (msg.MsgClient, error) {
return msg.NewMsgClient(conn), nil
}
func (m *Msg) GetSeq(c *gin.Context) {
func (m *Message) GetSeq(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMaxAndMinSeq, m.client, c)
}
func (m *Msg) PullMsgBySeqs(c *gin.Context) {
func (m *Message) PullMsgBySeqs(c *gin.Context) {
a2r.Call(msg.MsgClient.PullMessageBySeqs, m.client, c)
}
func (m *Msg) DelMsg(c *gin.Context) {
func (m *Message) DelMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelMsgs, m.client, c)
}
func (m *Msg) DelSuperGroupMsg(c *gin.Context) {
func (m *Message) DelSuperGroupMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.DelSuperGroupMsg, m.client, c)
}
func (m *Msg) ClearMsg(c *gin.Context) {
func (m *Message) ClearMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.ClearMsg, m.client, c)
}
func (m *Msg) SetMessageReactionExtensions(c *gin.Context) {
func (m *Message) SetMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.client, c)
}
func (m *Msg) GetMessageListReactionExtensions(c *gin.Context) {
func (m *Message) GetMessageListReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.client, c)
}
func (m *Msg) AddMessageReactionExtensions(c *gin.Context) {
func (m *Message) AddMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.client, c)
}
func (m *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
func (m *Message) DeleteMessageReactionExtensions(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.client, c)
}
func (m *Msg) SendMsg(c *gin.Context) {
func (m *Message) SendMessage(c *gin.Context) {
params := apistruct.ManagementSendMsgReq{}
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, err)
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return
}
var data interface{}
@@ -181,32 +180,29 @@ func (m *Msg) SendMsg(c *gin.Context) {
data = apistruct.CustomElem{}
case constant.CustomOnlineOnly:
data = apistruct.CustomElem{}
//case constant.HasReadReceipt:
//case constant.Typing:
//case constant.Quote:
default:
apiresp.GinError(c, errors.New("wrong contentType"))
apiresp.GinError(c, errs.ErrArgs.WithDetail("not support err contentType").Wrap())
return
}
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
apiresp.GinError(c, errs.ErrData)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
} else if err := m.validate.Struct(data); err != nil {
apiresp.GinError(c, errs.ErrData)
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
}
switch params.SessionType {
case constant.SingleChatType:
if len(params.RecvID) == 0 {
apiresp.GinError(c, errs.ErrData)
return
}
case constant.GroupChatType, constant.SuperGroupChatType:
if len(params.GroupID) == 0 {
apiresp.GinError(c, errs.ErrData)
return
}
}
//switch params.SessionType {
//case constant.SingleChatType:
// if len(params.RecvID) == 0 {
// apiresp.GinError(c, errs.ErrData)
// return
// }
//case constant.GroupChatType, constant.SuperGroupChatType:
// if len(params.GroupID) == 0 {
// apiresp.GinError(c, errs.ErrData)
// return
// }
//}
pbReq := m.newUserSendMsgReq(c, &params)
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
@@ -232,18 +228,18 @@ func (m *Msg) SendMsg(c *gin.Context) {
apiresp.GinSuccess(c, resp)
}
func (m *Msg) ManagementBatchSendMsg(c *gin.Context) {
func (m *Message) ManagementBatchSendMsg(c *gin.Context) {
a2r.Call(msg.MsgClient.SendMsg, m.client, c)
}
func (m *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
func (m *Message) CheckMsgIsSendSuccess(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}
func (m *Msg) GetUsersOnlineStatus(c *gin.Context) {
func (m *Message) GetUsersOnlineStatus(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}
func (m *Msg) AccountCheck(c *gin.Context) {
func (m *Message) AccountCheck(c *gin.Context) {
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
}