diff --git a/internal/api/manage/management_chat.go b/internal/api/manage/management_chat.go index 7a1876c83..98d4ac98b 100644 --- a/internal/api/manage/management_chat.go +++ b/internal/api/manage/management_chat.go @@ -29,10 +29,10 @@ import ( var validate *validator.Validate func SetOptions(options map[string]bool, value bool) { - utils.SetSwitchFromOptions(options, constant.IsOfflinePush, value) 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 *api.ManagementSendMsgReq) *pbChat.SendMsgReq { @@ -59,10 +59,12 @@ func newUserSendMsgReq(params *api.ManagementSendMsgReq) *pbChat.SendMsgReq { if params.IsOnlineOnly { SetOptions(options, false) } - if params.ContentType == constant.CustomMsgOnlineOnly { - SetOptions(options, false) - } else if params.ContentType == constant.CustomMsgNotTriggerConversation { + if params.NotOfflinePush { + utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false) + } + if params.ContentType == constant.CustomOnlineOnly { SetOptions(options, false) + } else if params.ContentType == constant.CustomNotTriggerConversation { utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false) } @@ -146,9 +148,9 @@ func ManagementSendMsg(c *gin.Context) { case constant.OANotification: data = OANotificationElem{} params.SessionType = constant.NotificationChatType - case constant.CustomMsgNotTriggerConversation: + case constant.CustomNotTriggerConversation: data = CustomElem{} - case constant.CustomMsgOnlineOnly: + case constant.CustomOnlineOnly: data = CustomElem{} //case constant.HasReadReceipt: //case constant.Typing: @@ -277,9 +279,9 @@ func ManagementBatchSendMsg(c *gin.Context) { case constant.OANotification: data = OANotificationElem{} params.SessionType = constant.NotificationChatType - case constant.CustomMsgNotTriggerConversation: + case constant.CustomNotTriggerConversation: data = CustomElem{} - case constant.CustomMsgOnlineOnly: + case constant.CustomOnlineOnly: data = CustomElem{} //case constant.HasReadReceipt: //case constant.Typing: @@ -322,12 +324,11 @@ func ManagementBatchSendMsg(c *gin.Context) { return } client := pbChat.NewMsgClient(etcdConn) + req := &api.ManagementSendMsgReq{ + ManagementSendMsg: params.ManagementSendMsg, + } + pbData := newUserSendMsgReq(req) for _, recvID := range params.RecvIDList { - req := &api.ManagementSendMsgReq{ - ManagementSendMsg: params.ManagementSendMsg, - RecvID: recvID, - } - pbData := newUserSendMsgReq(req) pbData.MsgData.RecvID = recvID log.Info(params.OperationID, "", "api ManagementSendMsg call start..., ", pbData.String()) @@ -344,10 +345,11 @@ func ManagementBatchSendMsg(c *gin.Context) { msgSendFailedFlag = true continue } - resp.Data.ResultList = append(resp.Data.ResultList, server_api_params.UserSendMsgResp{ + resp.Data.ResultList = append(resp.Data.ResultList, &api.SingleReturnResult{ ServerMsgID: rpcResp.ServerMsgID, ClientMsgID: rpcResp.ClientMsgID, SendTime: rpcResp.SendTime, + RecvID: recvID, }) } if msgSendFailedFlag { diff --git a/internal/push/fcm/push.go b/internal/push/fcm/push.go index 767ca7ec6..7878f11f3 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/fcm/push.go @@ -4,23 +4,20 @@ import ( "Open_IM/internal/push" "Open_IM/pkg/common/config" "Open_IM/pkg/common/db" + "Open_IM/pkg/common/log" "context" - "log" - "path/filepath" - "strconv" - firebase "firebase.google.com/go" "firebase.google.com/go/messaging" "google.golang.org/api/option" + "path/filepath" + "strconv" ) type Fcm struct { + FcmMsgCli *messaging.Client } -var ( - FcmClient *Fcm - FcmMsgCli *messaging.Client -) +var FcmClient *Fcm func init() { FcmClient = newFcmClient() @@ -30,7 +27,7 @@ func newFcmClient() *Fcm { opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount)) fcmApp, err := firebase.NewApp(context.Background(), nil, opt) if err != nil { - log.Println("error initializing app: %v\n", err) + log.Debug("", "error initializing app: ", err.Error()) return nil } //授权 @@ -41,13 +38,12 @@ func newFcmClient() *Fcm { // } // log.Printf("%#v\r\n", fcmClient) ctx := context.Background() - FcmMsgCli, err = fcmApp.Messaging(ctx) + fcmMsgClient, err := fcmApp.Messaging(ctx) if err != nil { - log.Fatalf("error getting Messaging client: %v\n", err) + panic(err.Error()) return nil } - log.Println(FcmMsgCli) - return &Fcm{} + return &Fcm{FcmMsgCli: fcmMsgClient} } 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. //the message could not be sent to any of the recipients. //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 { - log.Fatalln(err) + return "", err } Success = Success + response.SuccessCount Fail = Fail + response.FailureCount diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 0101ef077..cfe7f4825 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -274,7 +274,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) if err != nil { 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 { errMsg := " group status is dismissed " diff --git a/pkg/base_info/manage_api_struct.go b/pkg/base_info/manage_api_struct.go index e7db30f77..7d9f43653 100644 --- a/pkg/base_info/manage_api_struct.go +++ b/pkg/base_info/manage_api_struct.go @@ -52,6 +52,7 @@ type ManagementSendMsg struct { ContentType int32 `json:"contentType" binding:"required"` SessionType int32 `json:"sessionType" binding:"required"` IsOnlineOnly bool `json:"isOnlineOnly"` + NotOfflinePush bool `json:"notOfflinePush"` OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"` } @@ -73,10 +74,16 @@ type ManagementBatchSendMsgReq struct { type ManagementBatchSendMsgResp struct { CommResp Data struct { - ResultList []server_api_params.UserSendMsgResp `json:"resultList"` + ResultList []*SingleReturnResult `json:"resultList"` FailedIDList []string } `json:"data"` } +type SingleReturnResult struct { + ServerMsgID string `json:"serverMsgID"` + ClientMsgID string `json:"clientMsgID"` + SendTime int64 `json:"sendTime"` + RecvID string `json:"recvID" ` +} type CheckMsgIsSendSuccessReq struct { OperationID string `json:"operationID"` diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 3edcd0f21..58b53d7b7 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -28,25 +28,25 @@ const ( ///ContentType //UserRelated - Text = 101 - Picture = 102 - Voice = 103 - Video = 104 - File = 105 - AtText = 106 - Merger = 107 - Card = 108 - Location = 109 - Custom = 110 - Revoke = 111 - HasReadReceipt = 112 - Typing = 113 - Quote = 114 - GroupHasReadReceipt = 116 - AdvancedText = 117 - AdvancedRevoke = 118 //影响前者消息 - CustomMsgNotTriggerConversation = 119 - CustomMsgOnlineOnly = 120 + Text = 101 + Picture = 102 + Voice = 103 + Video = 104 + File = 105 + AtText = 106 + Merger = 107 + Card = 108 + Location = 109 + Custom = 110 + Revoke = 111 + HasReadReceipt = 112 + Typing = 113 + Quote = 114 + GroupHasReadReceipt = 116 + AdvancedText = 117 + AdvancedRevoke = 118 //影响前者消息 + CustomNotTriggerConversation = 119 + CustomOnlineOnly = 120 Common = 200 GroupMsg = 201