Merge branch 'tuoyun' into superGroup

# Conflicts:
#	internal/msg_gateway/gate/callback.go
#	internal/msg_transfer/logic/online_history_msg_handler.go
#	internal/push/logic/callback.go
#	internal/push/logic/push_to_client.go
#	pkg/common/db/model.go
#	pkg/common/db/newRedisModel.go
#	pkg/proto/group/group.pb.go
#	pkg/proto/group/group.proto
This commit is contained in:
wangchuxiao
2022-06-07 17:42:24 +08:00
78 changed files with 1214 additions and 418 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
package getui
import (
"Open_IM/internal/push"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
@@ -98,7 +99,7 @@ func newGetuiClient() *Getui {
return &Getui{}
}
func (g *Getui) Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error) {
func (g *Getui) Push(userIDList []string, alert, detailContent, operationID string, opts push.PushOpts) (resp string, err error) {
token, err := db.DB.GetGetuiToken()
log.NewDebug(operationID, utils.GetSelfFuncName(), "token", token)
if err != nil {
+10 -1
View File
@@ -1,6 +1,7 @@
package push
import (
"Open_IM/internal/push"
"Open_IM/internal/push/jpush/common"
"Open_IM/internal/push/jpush/requestBody"
"Open_IM/pkg/common/config"
@@ -32,12 +33,20 @@ func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
return resp, nil
}
func (j *JPush) Push(accounts []string, alert, detailContent, operationID string) (string, error) {
func (j *JPush) Push(accounts []string, alert, detailContent, operationID string, opts push.PushOpts) (string, error) {
var pf requestBody.Platform
pf.SetAll()
var au requestBody.Audience
au.SetAlias(accounts)
var no requestBody.Notification
var extras requestBody.Extras
if opts.Signal.ClientMsgID != "" {
extras.ClientMsgID = opts.Signal.ClientMsgID
}
no.IOSEnableMutableContent()
no.SetExtras(extras)
no.SetAlert(alert)
var me requestBody.Message
me.SetMsgContent(detailContent)
@@ -15,11 +15,18 @@ type Android struct {
Intent struct {
URL string `json:"url,omitempty"`
} `json:"intent,omitempty"`
Extras Extras `json:"extras"`
}
type Ios struct {
Alert string `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Alert string `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Extras Extras `json:"extras"`
MutableContent bool `json:"mutable-content"`
}
type Extras struct {
ClientMsgID string `json:"clientMsgID"`
}
func (n *Notification) SetAlert(alert string) {
@@ -29,8 +36,17 @@ func (n *Notification) SetAlert(alert string) {
n.IOS.Alert = alert
n.IOS.Sound = "default"
n.IOS.Badge = "+1"
}
func (n *Notification) SetExtras(extras Extras) {
n.IOS.Extras = extras
n.Android.Extras = extras
}
func (n *Notification) SetAndroidIntent() {
n.Android.Intent.URL = config.Config.Push.Jpns.PushIntent
}
func (n *Notification) IOSEnableMutableContent() {
n.IOS.MutableContent = true
}
+10 -4
View File
@@ -9,7 +9,7 @@ import (
http2 "net/http"
)
func callbackOfflinePush(operationID, userID string, info *commonPb.OfflinePushInfo, platformID int32) cbApi.CommonCallbackResp {
func callbackOfflinePush(operationID, userID string, msg *commonPb.MsgData) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackOfflinePush.Enable {
return callbackResp
@@ -19,10 +19,16 @@ func callbackOfflinePush(operationID, userID string, info *commonPb.OfflinePushI
CallbackCommand: constant.CallbackOfflinePushCommand,
OperationID: operationID,
UserID: userID,
PlatformID: platformID,
Platform: constant.PlatformIDToName(int(platformID)),
PlatformID: msg.SenderPlatformID,
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
OfflinePushInfo: info,
OfflinePushInfo: msg.OfflinePushInfo,
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
Content: string(msg.Content),
}
callbackOfflinePushResp := &cbApi.CallbackOfflinePushResp{CommonCallbackResp: &callbackResp}
if err := http.PostReturn(config.Config.Callback.CallbackUrl, callbackOfflinePushReq, callbackOfflinePushResp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
+32 -4
View File
@@ -7,16 +7,18 @@
package logic
import (
jpush "Open_IM/internal/push/jpush"
"Open_IM/internal/push"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbPush "Open_IM/pkg/proto/push"
pbRelay "Open_IM/pkg/proto/relay"
pbRtc "Open_IM/pkg/proto/rtc"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"strings"
)
@@ -99,11 +101,15 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
} else {
content = constant.ContentType2PushContent[constant.GroupMsg]
}
case constant.SignalingNotification:
content = constant.ContentType2PushContent[constant.SignalMsg]
default:
content = constant.ContentType2PushContent[constant.Common]
}
}
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList[0], pushMsg.MsgData.OfflinePushInfo, constant.AndroidPlatformID)
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList[0], pushMsg.MsgData)
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
if callbackResp.ErrCode != 0 {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
@@ -113,9 +119,14 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
return
}
if offlinePusher == nil {
offlinePusher = jpush.JPushClient
return
}
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID)
opts, err := GetOfflinePushOpts(pushMsg)
if err != nil {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetOfflinePushOpts failed", pushMsg, err.Error())
}
log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), UIDList, content, jsonCustomContent, "opts:", opts)
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID, opts)
if err != nil {
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
} else {
@@ -225,6 +236,23 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
//}
}
func GetOfflinePushOpts(pushMsg *pbPush.PushMsgReq) (opts push.PushOpts, err error) {
if pushMsg.MsgData.ContentType < constant.SignalingNotificationEnd && pushMsg.MsgData.ContentType > constant.SignalingNotificationBegin {
req := &pbRtc.SignalReq{}
if err := proto.Unmarshal(pushMsg.MsgData.Content, req); err != nil {
return opts, utils.Wrap(err, "")
}
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "SignalReq: ", req.String())
switch req.Payload.(type) {
case *pbRtc.SignalReq_Invite, *pbRtc.SignalReq_InviteInGroup:
opts.Signal.ClientMsgID = pushMsg.MsgData.ClientMsgID
log.NewDebug(pushMsg.OperationID, opts)
}
}
return opts, nil
}
//func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) {
// m.MsgID = rpcChat.GetMsgID(m.SendID)
// m.ClientMsgID = m.MsgID
+9 -1
View File
@@ -1,5 +1,13 @@
package push
type OfflinePusher interface {
Push(userIDList []string, alert, detailContent, operationID string) (resp string, err error)
Push(userIDList []string, alert, detailContent, operationID string, opts PushOpts) (resp string, err error)
}
type PushOpts struct {
Signal Signal
}
type Signal struct {
ClientMsgID string
}