mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 19:22:46 +08:00
user update
This commit is contained in:
parent
99c486295b
commit
78d5fa30ba
@ -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(¶ms); 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, ¶ms)
|
||||
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)
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal
|
||||
m := NewMsg(zk)
|
||||
msgGroup.Use(mw.GinParseToken(rdb))
|
||||
msgGroup.POST("/newest_seq", m.GetSeq)
|
||||
msgGroup.POST("/send_msg", m.SendMsg)
|
||||
msgGroup.POST("/send_msg", m.SendMessage)
|
||||
msgGroup.POST("/pull_msg_by_seq", m.PullMsgBySeqs)
|
||||
msgGroup.POST("/del_msg", m.DelMsg)
|
||||
msgGroup.POST("/del_super_group_msg", m.DelSuperGroupMsg)
|
||||
|
@ -3,8 +3,8 @@ package msg
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
promePkg "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
@ -259,6 +259,9 @@ func (m *msgServer) SendMsg(ctx context.Context, req *msg.SendMsgReq) (resp *msg
|
||||
}
|
||||
|
||||
func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
|
||||
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := new(sdkws.GetMaxAndMinSeqResp)
|
||||
m2 := make(map[string]*sdkws.MaxAndMinSeq)
|
||||
maxSeq, err := m.MsgDatabase.GetUserMaxSeq(ctx, req.UserID)
|
||||
@ -275,7 +278,6 @@ func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMin
|
||||
for _, groupID := range req.GroupIDs {
|
||||
maxSeq, err := m.MsgDatabase.GetGroupMaxSeq(ctx, groupID)
|
||||
if err != nil && errs.Unwrap(err) != redis.Nil {
|
||||
log.ZDebug(ctx, "redis err", "err", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
minSeq, err := m.MsgDatabase.GetGroupMinSeq(ctx, groupID)
|
||||
|
@ -34,7 +34,7 @@ type AccountCheckResp struct {
|
||||
|
||||
type ManagementSendMsg struct {
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
GroupID string `json:"groupID" `
|
||||
GroupID string `json:"groupID" binding:"required_if=SessionType 2|required_if=SessionType 3"`
|
||||
SenderNickname string `json:"senderNickname" `
|
||||
SenderFaceURL string `json:"senderFaceURL" `
|
||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||
@ -47,8 +47,18 @@ type ManagementSendMsg struct {
|
||||
}
|
||||
|
||||
type ManagementSendMsgReq struct {
|
||||
ManagementSendMsg
|
||||
RecvID string `json:"recvID" `
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
RecvID string `json:"recvID" binding:"required_if=SessionType 1|required_if=SessionType 4"`
|
||||
GroupID string `json:"groupID" binding:"required_if=SessionType 2|required_if=SessionType 3"`
|
||||
SenderNickname string `json:"senderNickname" `
|
||||
SenderFaceURL string `json:"senderFaceURL" `
|
||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||
Content map[string]interface{} `json:"content" binding:"required" swaggerignore:"true"`
|
||||
ContentType int32 `json:"contentType" binding:"required"`
|
||||
SessionType int32 `json:"sessionType" binding:"required"`
|
||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||
NotOfflinePush bool `json:"notOfflinePush"`
|
||||
OfflinePushInfo *sdkws.OfflinePushInfo `json:"offlinePushInfo"`
|
||||
}
|
||||
|
||||
type ManagementSendMsgResp struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user