|
|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
|
"OpenIM/pkg/common/config"
|
|
|
|
|
"OpenIM/pkg/common/constant"
|
|
|
|
|
"OpenIM/pkg/common/log"
|
|
|
|
|
"OpenIM/pkg/common/tracelog"
|
|
|
|
|
"OpenIM/pkg/discoveryregistry"
|
|
|
|
|
"OpenIM/pkg/errs"
|
|
|
|
|
"OpenIM/pkg/proto/msg"
|
|
|
|
@ -31,14 +32,14 @@ type Msg struct {
|
|
|
|
|
validate *validator.Validate
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetOptions(options map[string]bool, value bool) {
|
|
|
|
|
func (Msg) 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 newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
|
|
|
|
|
func (m Msg) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
|
|
|
|
|
var newContent string
|
|
|
|
|
var err error
|
|
|
|
|
switch params.ContentType {
|
|
|
|
@ -66,17 +67,16 @@ func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
|
|
|
|
|
}
|
|
|
|
|
options := make(map[string]bool, 5)
|
|
|
|
|
if params.IsOnlineOnly {
|
|
|
|
|
SetOptions(options, false)
|
|
|
|
|
m.SetOptions(options, false)
|
|
|
|
|
}
|
|
|
|
|
if params.NotOfflinePush {
|
|
|
|
|
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
|
|
|
|
}
|
|
|
|
|
if params.ContentType == constant.CustomOnlineOnly {
|
|
|
|
|
SetOptions(options, false)
|
|
|
|
|
m.SetOptions(options, false)
|
|
|
|
|
} else if params.ContentType == constant.CustomNotTriggerConversation {
|
|
|
|
|
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pbData := msg.SendMsgReq{
|
|
|
|
|
MsgData: &sdkws.MsgData{
|
|
|
|
|
SendID: params.SendID,
|
|
|
|
@ -100,91 +100,87 @@ func newUserSendMsgReq(params *apistruct.ManagementSendMsgReq) *msg.SendMsgReq {
|
|
|
|
|
tips.JsonDetail = utils.StructToJsonString(params.Content)
|
|
|
|
|
pbData.MsgData.Content, err = proto.Marshal(&tips)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error(params.OperationID, "Marshal failed ", err.Error(), tips.String())
|
|
|
|
|
log.Error(tracelog.GetOperationID(c), "Marshal failed ", err.Error(), tips.String())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return &pbData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) client() (msg.MsgClient, error) {
|
|
|
|
|
conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
|
|
|
|
func (m *Msg) client() (msg.MsgClient, error) {
|
|
|
|
|
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return msg.NewMsgClient(conn), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) GetSeq(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetMaxAndMinSeq, o.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) SendMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.SendMsg, o.client, c)
|
|
|
|
|
func (m *Msg) GetSeq(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetMaxAndMinSeq, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) PullMsgBySeqs(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.PullMessageBySeqs, o.client, c)
|
|
|
|
|
func (m *Msg) PullMsgBySeqs(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.PullMessageBySeqs, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) DelMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DelMsgs, o.client, c)
|
|
|
|
|
func (m *Msg) DelMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DelMsgs, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) DelSuperGroupMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DelSuperGroupMsg, o.client, c)
|
|
|
|
|
func (m *Msg) DelSuperGroupMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DelSuperGroupMsg, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) ClearMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.ClearMsg, o.client, c)
|
|
|
|
|
func (m *Msg) ClearMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.ClearMsg, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) SetMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, o.client, c)
|
|
|
|
|
func (m *Msg) SetMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) GetMessageListReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, o.client, c)
|
|
|
|
|
func (m *Msg) GetMessageListReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetMessagesReactionExtensions, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) AddMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, o.client, c)
|
|
|
|
|
func (m *Msg) AddMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, o.client, c)
|
|
|
|
|
func (m *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) ManagementSendMsg(c *gin.Context) {
|
|
|
|
|
var data interface{}
|
|
|
|
|
func (m *Msg) SendMsg(c *gin.Context) {
|
|
|
|
|
params := apistruct.ManagementSendMsgReq{}
|
|
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var data interface{}
|
|
|
|
|
switch params.ContentType {
|
|
|
|
|
case constant.Text:
|
|
|
|
|
data = TextElem{}
|
|
|
|
|
data = apistruct.TextElem{}
|
|
|
|
|
case constant.Picture:
|
|
|
|
|
data = PictureElem{}
|
|
|
|
|
data = apistruct.PictureElem{}
|
|
|
|
|
case constant.Voice:
|
|
|
|
|
data = SoundElem{}
|
|
|
|
|
data = apistruct.SoundElem{}
|
|
|
|
|
case constant.Video:
|
|
|
|
|
data = VideoElem{}
|
|
|
|
|
data = apistruct.VideoElem{}
|
|
|
|
|
case constant.File:
|
|
|
|
|
data = FileElem{}
|
|
|
|
|
data = apistruct.FileElem{}
|
|
|
|
|
case constant.Custom:
|
|
|
|
|
data = CustomElem{}
|
|
|
|
|
data = apistruct.CustomElem{}
|
|
|
|
|
case constant.Revoke:
|
|
|
|
|
data = RevokeElem{}
|
|
|
|
|
data = apistruct.RevokeElem{}
|
|
|
|
|
case constant.AdvancedRevoke:
|
|
|
|
|
data = MessageRevoked{}
|
|
|
|
|
data = apistruct.MessageRevoked{}
|
|
|
|
|
case constant.OANotification:
|
|
|
|
|
data = OANotificationElem{}
|
|
|
|
|
data = apistruct.OANotificationElem{}
|
|
|
|
|
params.SessionType = constant.NotificationChatType
|
|
|
|
|
case constant.CustomNotTriggerConversation:
|
|
|
|
|
data = CustomElem{}
|
|
|
|
|
data = apistruct.CustomElem{}
|
|
|
|
|
case constant.CustomOnlineOnly:
|
|
|
|
|
data = CustomElem{}
|
|
|
|
|
data = apistruct.CustomElem{}
|
|
|
|
|
//case constant.HasReadReceipt:
|
|
|
|
|
//case constant.Typing:
|
|
|
|
|
//case constant.Quote:
|
|
|
|
@ -195,11 +191,10 @@ func (o *Msg) ManagementSendMsg(c *gin.Context) {
|
|
|
|
|
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrData)
|
|
|
|
|
return
|
|
|
|
|
} else if err := o.validate.Struct(data); err != nil {
|
|
|
|
|
} else if err := m.validate.Struct(data); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrData)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.NewInfo(params.OperationID, data, params)
|
|
|
|
|
switch params.SessionType {
|
|
|
|
|
case constant.SingleChatType:
|
|
|
|
|
if len(params.RecvID) == 0 {
|
|
|
|
@ -212,132 +207,43 @@ func (o *Msg) ManagementSendMsg(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.NewInfo(params.OperationID, "Ws call success to ManagementSendMsgReq", params)
|
|
|
|
|
pbData := newUserSendMsgReq(¶ms)
|
|
|
|
|
conn, err := o.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
|
|
|
|
pbReq := m.newUserSendMsgReq(c, ¶ms)
|
|
|
|
|
conn, err := m.c.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrInternalServer)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
client := msg.NewMsgClient(conn)
|
|
|
|
|
log.Info(params.OperationID, "", "api ManagementSendMsg call, api call rpc...")
|
|
|
|
|
//var status int32
|
|
|
|
|
RpcResp, err := client.SendMsg(context.Background(), pbData)
|
|
|
|
|
var status int
|
|
|
|
|
respPb, err := client.SendMsg(c, pbReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
//status = constant.MsgSendFailed
|
|
|
|
|
status = constant.MsgSendFailed
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//status = constant.MsgSendSuccessed
|
|
|
|
|
//_, err2 := client.SetSendMsgStatus(context.Background(), &msg.SetSendMsgStatusReq{OperationID: params.OperationID, Status: status})
|
|
|
|
|
//if err2 != nil {
|
|
|
|
|
// log.NewError(params.OperationID, utils.GetSelfFuncName(), err2.Error())
|
|
|
|
|
//}
|
|
|
|
|
log.Info(params.OperationID, "", "api ManagementSendMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String())
|
|
|
|
|
resp := apistruct.ManagementSendMsgResp{ResultList: sdkws.UserSendMsgResp{ServerMsgID: RpcResp.ServerMsgID, ClientMsgID: RpcResp.ClientMsgID, SendTime: RpcResp.SendTime}}
|
|
|
|
|
log.Info(params.OperationID, "ManagementSendMsg return", resp)
|
|
|
|
|
status = constant.MsgSendSuccessed
|
|
|
|
|
_, err = client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
|
|
|
|
|
Status: int32(status),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewError(tracelog.GetOperationID(c), "SetSendMsgStatus failed")
|
|
|
|
|
}
|
|
|
|
|
resp := apistruct.ManagementSendMsgResp{ResultList: sdkws.UserSendMsgResp{ServerMsgID: respPb.ServerMsgID, ClientMsgID: respPb.ClientMsgID, SendTime: respPb.SendTime}}
|
|
|
|
|
apiresp.GinSuccess(c, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) ManagementBatchSendMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.SendMsg, o.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) GetUsersOnlineStatus(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
|
|
|
|
|
func (m *Msg) ManagementBatchSendMsg(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.SendMsg, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *Msg) AccountCheck(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, o.client, c)
|
|
|
|
|
func (m *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PictureBaseInfo struct {
|
|
|
|
|
UUID string `mapstructure:"uuid"`
|
|
|
|
|
Type string `mapstructure:"type" `
|
|
|
|
|
Size int64 `mapstructure:"size" `
|
|
|
|
|
Width int32 `mapstructure:"width" `
|
|
|
|
|
Height int32 `mapstructure:"height"`
|
|
|
|
|
Url string `mapstructure:"url" `
|
|
|
|
|
func (m *Msg) GetUsersOnlineStatus(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PictureElem struct {
|
|
|
|
|
SourcePath string `mapstructure:"sourcePath"`
|
|
|
|
|
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"`
|
|
|
|
|
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
|
|
|
|
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
|
|
|
|
}
|
|
|
|
|
type SoundElem struct {
|
|
|
|
|
UUID string `mapstructure:"uuid"`
|
|
|
|
|
SoundPath string `mapstructure:"soundPath"`
|
|
|
|
|
SourceURL string `mapstructure:"sourceUrl"`
|
|
|
|
|
DataSize int64 `mapstructure:"dataSize"`
|
|
|
|
|
Duration int64 `mapstructure:"duration"`
|
|
|
|
|
}
|
|
|
|
|
type VideoElem struct {
|
|
|
|
|
VideoPath string `mapstructure:"videoPath"`
|
|
|
|
|
VideoUUID string `mapstructure:"videoUUID"`
|
|
|
|
|
VideoURL string `mapstructure:"videoUrl"`
|
|
|
|
|
VideoType string `mapstructure:"videoType"`
|
|
|
|
|
VideoSize int64 `mapstructure:"videoSize"`
|
|
|
|
|
Duration int64 `mapstructure:"duration"`
|
|
|
|
|
SnapshotPath string `mapstructure:"snapshotPath"`
|
|
|
|
|
SnapshotUUID string `mapstructure:"snapshotUUID"`
|
|
|
|
|
SnapshotSize int64 `mapstructure:"snapshotSize"`
|
|
|
|
|
SnapshotURL string `mapstructure:"snapshotUrl"`
|
|
|
|
|
SnapshotWidth int32 `mapstructure:"snapshotWidth"`
|
|
|
|
|
SnapshotHeight int32 `mapstructure:"snapshotHeight"`
|
|
|
|
|
}
|
|
|
|
|
type FileElem struct {
|
|
|
|
|
FilePath string `mapstructure:"filePath"`
|
|
|
|
|
UUID string `mapstructure:"uuid"`
|
|
|
|
|
SourceURL string `mapstructure:"sourceUrl"`
|
|
|
|
|
FileName string `mapstructure:"fileName"`
|
|
|
|
|
FileSize int64 `mapstructure:"fileSize"`
|
|
|
|
|
}
|
|
|
|
|
type AtElem struct {
|
|
|
|
|
Text string `mapstructure:"text"`
|
|
|
|
|
AtUserList []string `mapstructure:"atUserList"`
|
|
|
|
|
IsAtSelf bool `mapstructure:"isAtSelf"`
|
|
|
|
|
}
|
|
|
|
|
type LocationElem struct {
|
|
|
|
|
Description string `mapstructure:"description"`
|
|
|
|
|
Longitude float64 `mapstructure:"longitude"`
|
|
|
|
|
Latitude float64 `mapstructure:"latitude"`
|
|
|
|
|
}
|
|
|
|
|
type CustomElem struct {
|
|
|
|
|
Data string `mapstructure:"data" validate:"required"`
|
|
|
|
|
Description string `mapstructure:"description"`
|
|
|
|
|
Extension string `mapstructure:"extension"`
|
|
|
|
|
}
|
|
|
|
|
type TextElem struct {
|
|
|
|
|
Text string `mapstructure:"text" validate:"required"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RevokeElem struct {
|
|
|
|
|
RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"`
|
|
|
|
|
}
|
|
|
|
|
type OANotificationElem struct {
|
|
|
|
|
NotificationName string `mapstructure:"notificationName" json:"notificationName" validate:"required"`
|
|
|
|
|
NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"`
|
|
|
|
|
NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"`
|
|
|
|
|
Text string `mapstructure:"text" json:"text" validate:"required"`
|
|
|
|
|
Url string `mapstructure:"url" json:"url"`
|
|
|
|
|
MixType int32 `mapstructure:"mixType" json:"mixType"`
|
|
|
|
|
PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"`
|
|
|
|
|
SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"`
|
|
|
|
|
VideoElem VideoElem `mapstructure:"videoElem" json:"videoElem"`
|
|
|
|
|
FileElem FileElem `mapstructure:"fileElem" json:"fileElem"`
|
|
|
|
|
Ex string `mapstructure:"ex" json:"ex"`
|
|
|
|
|
}
|
|
|
|
|
type MessageRevoked struct {
|
|
|
|
|
RevokerID string `mapstructure:"revokerID" json:"revokerID" validate:"required"`
|
|
|
|
|
RevokerRole int32 `mapstructure:"revokerRole" json:"revokerRole" validate:"required"`
|
|
|
|
|
ClientMsgID string `mapstructure:"clientMsgID" json:"clientMsgID" validate:"required"`
|
|
|
|
|
RevokerNickname string `mapstructure:"revokerNickname" json:"revokerNickname"`
|
|
|
|
|
SessionType int32 `mapstructure:"sessionType" json:"sessionType" validate:"required"`
|
|
|
|
|
Seq uint32 `mapstructure:"seq" json:"seq" validate:"required"`
|
|
|
|
|
func (m *Msg) AccountCheck(c *gin.Context) {
|
|
|
|
|
a2r.Call(msg.MsgClient.GetSendMsgStatus, m.client, c)
|
|
|
|
|
}
|
|
|
|
|