mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
manger send msg modify
This commit is contained in:
parent
36885b4f9e
commit
787cef54f5
@ -29,10 +29,10 @@ import (
|
|||||||
var validate *validator.Validate
|
var validate *validator.Validate
|
||||||
|
|
||||||
func SetOptions(options map[string]bool, value bool) {
|
func SetOptions(options map[string]bool, value bool) {
|
||||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, value)
|
|
||||||
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
|
utils.SetSwitchFromOptions(options, constant.IsHistory, value)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
|
utils.SetSwitchFromOptions(options, constant.IsPersistent, value)
|
||||||
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
|
utils.SetSwitchFromOptions(options, constant.IsSenderSync, value)
|
||||||
|
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUserSendMsgReq(params *api.ManagementSendMsgReq) *pbChat.SendMsgReq {
|
func newUserSendMsgReq(params *api.ManagementSendMsgReq) *pbChat.SendMsgReq {
|
||||||
@ -59,10 +59,12 @@ func newUserSendMsgReq(params *api.ManagementSendMsgReq) *pbChat.SendMsgReq {
|
|||||||
if params.IsOnlineOnly {
|
if params.IsOnlineOnly {
|
||||||
SetOptions(options, false)
|
SetOptions(options, false)
|
||||||
}
|
}
|
||||||
if params.ContentType == constant.CustomMsgOnlineOnly {
|
if params.NotOfflinePush {
|
||||||
SetOptions(options, false)
|
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||||
} else if params.ContentType == constant.CustomMsgNotTriggerConversation {
|
}
|
||||||
|
if params.ContentType == constant.CustomOnlineOnly {
|
||||||
SetOptions(options, false)
|
SetOptions(options, false)
|
||||||
|
} else if params.ContentType == constant.CustomNotTriggerConversation {
|
||||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,9 +148,9 @@ func ManagementSendMsg(c *gin.Context) {
|
|||||||
case constant.OANotification:
|
case constant.OANotification:
|
||||||
data = OANotificationElem{}
|
data = OANotificationElem{}
|
||||||
params.SessionType = constant.NotificationChatType
|
params.SessionType = constant.NotificationChatType
|
||||||
case constant.CustomMsgNotTriggerConversation:
|
case constant.CustomNotTriggerConversation:
|
||||||
data = CustomElem{}
|
data = CustomElem{}
|
||||||
case constant.CustomMsgOnlineOnly:
|
case constant.CustomOnlineOnly:
|
||||||
data = CustomElem{}
|
data = CustomElem{}
|
||||||
//case constant.HasReadReceipt:
|
//case constant.HasReadReceipt:
|
||||||
//case constant.Typing:
|
//case constant.Typing:
|
||||||
@ -277,9 +279,9 @@ func ManagementBatchSendMsg(c *gin.Context) {
|
|||||||
case constant.OANotification:
|
case constant.OANotification:
|
||||||
data = OANotificationElem{}
|
data = OANotificationElem{}
|
||||||
params.SessionType = constant.NotificationChatType
|
params.SessionType = constant.NotificationChatType
|
||||||
case constant.CustomMsgNotTriggerConversation:
|
case constant.CustomNotTriggerConversation:
|
||||||
data = CustomElem{}
|
data = CustomElem{}
|
||||||
case constant.CustomMsgOnlineOnly:
|
case constant.CustomOnlineOnly:
|
||||||
data = CustomElem{}
|
data = CustomElem{}
|
||||||
//case constant.HasReadReceipt:
|
//case constant.HasReadReceipt:
|
||||||
//case constant.Typing:
|
//case constant.Typing:
|
||||||
@ -322,12 +324,11 @@ func ManagementBatchSendMsg(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
client := pbChat.NewMsgClient(etcdConn)
|
client := pbChat.NewMsgClient(etcdConn)
|
||||||
|
req := &api.ManagementSendMsgReq{
|
||||||
|
ManagementSendMsg: params.ManagementSendMsg,
|
||||||
|
}
|
||||||
|
pbData := newUserSendMsgReq(req)
|
||||||
for _, recvID := range params.RecvIDList {
|
for _, recvID := range params.RecvIDList {
|
||||||
req := &api.ManagementSendMsgReq{
|
|
||||||
ManagementSendMsg: params.ManagementSendMsg,
|
|
||||||
RecvID: recvID,
|
|
||||||
}
|
|
||||||
pbData := newUserSendMsgReq(req)
|
|
||||||
pbData.MsgData.RecvID = recvID
|
pbData.MsgData.RecvID = recvID
|
||||||
log.Info(params.OperationID, "", "api ManagementSendMsg call start..., ", pbData.String())
|
log.Info(params.OperationID, "", "api ManagementSendMsg call start..., ", pbData.String())
|
||||||
|
|
||||||
@ -344,10 +345,11 @@ func ManagementBatchSendMsg(c *gin.Context) {
|
|||||||
msgSendFailedFlag = true
|
msgSendFailedFlag = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Data.ResultList = append(resp.Data.ResultList, server_api_params.UserSendMsgResp{
|
resp.Data.ResultList = append(resp.Data.ResultList, &api.SingleReturnResult{
|
||||||
ServerMsgID: rpcResp.ServerMsgID,
|
ServerMsgID: rpcResp.ServerMsgID,
|
||||||
ClientMsgID: rpcResp.ClientMsgID,
|
ClientMsgID: rpcResp.ClientMsgID,
|
||||||
SendTime: rpcResp.SendTime,
|
SendTime: rpcResp.SendTime,
|
||||||
|
RecvID: recvID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if msgSendFailedFlag {
|
if msgSendFailedFlag {
|
||||||
|
@ -4,23 +4,20 @@ import (
|
|||||||
"Open_IM/internal/push"
|
"Open_IM/internal/push"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
"context"
|
"context"
|
||||||
"log"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
firebase "firebase.google.com/go"
|
firebase "firebase.google.com/go"
|
||||||
"firebase.google.com/go/messaging"
|
"firebase.google.com/go/messaging"
|
||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Fcm struct {
|
type Fcm struct {
|
||||||
|
FcmMsgCli *messaging.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var FcmClient *Fcm
|
||||||
FcmClient *Fcm
|
|
||||||
FcmMsgCli *messaging.Client
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
FcmClient = newFcmClient()
|
FcmClient = newFcmClient()
|
||||||
@ -30,7 +27,7 @@ func newFcmClient() *Fcm {
|
|||||||
opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount))
|
opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount))
|
||||||
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("error initializing app: %v\n", err)
|
log.Debug("", "error initializing app: ", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
//授权
|
//授权
|
||||||
@ -41,13 +38,12 @@ func newFcmClient() *Fcm {
|
|||||||
// }
|
// }
|
||||||
// log.Printf("%#v\r\n", fcmClient)
|
// log.Printf("%#v\r\n", fcmClient)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
FcmMsgCli, err = fcmApp.Messaging(ctx)
|
fcmMsgClient, err := fcmApp.Messaging(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error getting Messaging client: %v\n", err)
|
panic(err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Println(FcmMsgCli)
|
return &Fcm{FcmMsgCli: fcmMsgClient}
|
||||||
return &Fcm{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
|
func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
|
||||||
@ -87,9 +83,9 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
|
|||||||
//An error from SendMulticast indicates a total failure -- i.e.
|
//An error from SendMulticast indicates a total failure -- i.e.
|
||||||
//the message could not be sent to any of the recipients.
|
//the message could not be sent to any of the recipients.
|
||||||
//Partial failures are indicated by a `BatchResponse` return value.
|
//Partial failures are indicated by a `BatchResponse` return value.
|
||||||
response, err := FcmMsgCli.SendMulticast(ctx, Msg)
|
response, err := f.FcmMsgCli.SendMulticast(ctx, Msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
return "", err
|
||||||
}
|
}
|
||||||
Success = Success + response.SuccessCount
|
Success = Success + response.SuccessCount
|
||||||
Fail = Fail + response.FailureCount
|
Fail = Fail + response.FailureCount
|
||||||
|
@ -274,7 +274,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|||||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
||||||
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
errMsg := " group status is dismissed "
|
errMsg := " group status is dismissed "
|
||||||
|
@ -52,6 +52,7 @@ type ManagementSendMsg struct {
|
|||||||
ContentType int32 `json:"contentType" binding:"required"`
|
ContentType int32 `json:"contentType" binding:"required"`
|
||||||
SessionType int32 `json:"sessionType" binding:"required"`
|
SessionType int32 `json:"sessionType" binding:"required"`
|
||||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||||
|
NotOfflinePush bool `json:"notOfflinePush"`
|
||||||
OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"`
|
OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +74,16 @@ type ManagementBatchSendMsgReq struct {
|
|||||||
type ManagementBatchSendMsgResp struct {
|
type ManagementBatchSendMsgResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
Data struct {
|
Data struct {
|
||||||
ResultList []server_api_params.UserSendMsgResp `json:"resultList"`
|
ResultList []*SingleReturnResult `json:"resultList"`
|
||||||
FailedIDList []string
|
FailedIDList []string
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
type SingleReturnResult struct {
|
||||||
|
ServerMsgID string `json:"serverMsgID"`
|
||||||
|
ClientMsgID string `json:"clientMsgID"`
|
||||||
|
SendTime int64 `json:"sendTime"`
|
||||||
|
RecvID string `json:"recvID" `
|
||||||
|
}
|
||||||
|
|
||||||
type CheckMsgIsSendSuccessReq struct {
|
type CheckMsgIsSendSuccessReq struct {
|
||||||
OperationID string `json:"operationID"`
|
OperationID string `json:"operationID"`
|
||||||
|
@ -28,25 +28,25 @@ const (
|
|||||||
|
|
||||||
///ContentType
|
///ContentType
|
||||||
//UserRelated
|
//UserRelated
|
||||||
Text = 101
|
Text = 101
|
||||||
Picture = 102
|
Picture = 102
|
||||||
Voice = 103
|
Voice = 103
|
||||||
Video = 104
|
Video = 104
|
||||||
File = 105
|
File = 105
|
||||||
AtText = 106
|
AtText = 106
|
||||||
Merger = 107
|
Merger = 107
|
||||||
Card = 108
|
Card = 108
|
||||||
Location = 109
|
Location = 109
|
||||||
Custom = 110
|
Custom = 110
|
||||||
Revoke = 111
|
Revoke = 111
|
||||||
HasReadReceipt = 112
|
HasReadReceipt = 112
|
||||||
Typing = 113
|
Typing = 113
|
||||||
Quote = 114
|
Quote = 114
|
||||||
GroupHasReadReceipt = 116
|
GroupHasReadReceipt = 116
|
||||||
AdvancedText = 117
|
AdvancedText = 117
|
||||||
AdvancedRevoke = 118 //影响前者消息
|
AdvancedRevoke = 118 //影响前者消息
|
||||||
CustomMsgNotTriggerConversation = 119
|
CustomNotTriggerConversation = 119
|
||||||
CustomMsgOnlineOnly = 120
|
CustomOnlineOnly = 120
|
||||||
|
|
||||||
Common = 200
|
Common = 200
|
||||||
GroupMsg = 201
|
GroupMsg = 201
|
||||||
|
Loading…
x
Reference in New Issue
Block a user