|
|
@ -48,6 +48,7 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Pusher struct {
|
|
|
|
type Pusher struct {
|
|
|
|
|
|
|
|
config *config.GlobalConfig
|
|
|
|
database controller.PushDatabase
|
|
|
|
database controller.PushDatabase
|
|
|
|
discov discoveryregistry.SvcDiscoveryRegistry
|
|
|
|
discov discoveryregistry.SvcDiscoveryRegistry
|
|
|
|
offlinePusher offlinepush.OfflinePusher
|
|
|
|
offlinePusher offlinepush.OfflinePusher
|
|
|
@ -60,11 +61,12 @@ type Pusher struct {
|
|
|
|
|
|
|
|
|
|
|
|
var errNoOfflinePusher = errors.New("no offlinePusher is configured")
|
|
|
|
var errNoOfflinePusher = errors.New("no offlinePusher is configured")
|
|
|
|
|
|
|
|
|
|
|
|
func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
|
|
|
|
func NewPusher(config *config.GlobalConfig, discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
|
|
|
|
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache,
|
|
|
|
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache,
|
|
|
|
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient, msgRpcClient *rpcclient.MessageRpcClient,
|
|
|
|
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient, msgRpcClient *rpcclient.MessageRpcClient,
|
|
|
|
) *Pusher {
|
|
|
|
) *Pusher {
|
|
|
|
return &Pusher{
|
|
|
|
return &Pusher{
|
|
|
|
|
|
|
|
config: config,
|
|
|
|
discov: discov,
|
|
|
|
discov: discov,
|
|
|
|
database: database,
|
|
|
|
database: database,
|
|
|
|
offlinePusher: offlinePusher,
|
|
|
|
offlinePusher: offlinePusher,
|
|
|
@ -76,15 +78,15 @@ func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewOfflinePusher(cache cache.MsgModel) offlinepush.OfflinePusher {
|
|
|
|
func NewOfflinePusher(config *config.GlobalConfig, cache cache.MsgModel) offlinepush.OfflinePusher {
|
|
|
|
var offlinePusher offlinepush.OfflinePusher
|
|
|
|
var offlinePusher offlinepush.OfflinePusher
|
|
|
|
switch config.Config.Push.Enable {
|
|
|
|
switch config.Push.Enable {
|
|
|
|
case "getui":
|
|
|
|
case "getui":
|
|
|
|
offlinePusher = getui.NewClient(cache)
|
|
|
|
offlinePusher = getui.NewClient(config, cache)
|
|
|
|
case "fcm":
|
|
|
|
case "fcm":
|
|
|
|
offlinePusher = fcm.NewClient(cache)
|
|
|
|
offlinePusher = fcm.NewClient(config, cache)
|
|
|
|
case "jpush":
|
|
|
|
case "jpush":
|
|
|
|
offlinePusher = jpush.NewClient()
|
|
|
|
offlinePusher = jpush.NewClient(config)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
offlinePusher = dummy.NewClient()
|
|
|
|
offlinePusher = dummy.NewClient()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -102,7 +104,7 @@ func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID
|
|
|
|
|
|
|
|
|
|
|
|
func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error {
|
|
|
|
func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error {
|
|
|
|
log.ZDebug(ctx, "Get msg from msg_transfer And push msg", "userIDs", userIDs, "msg", msg.String())
|
|
|
|
log.ZDebug(ctx, "Get msg from msg_transfer And push msg", "userIDs", userIDs, "msg", msg.String())
|
|
|
|
if err := callbackOnlinePush(ctx, userIDs, msg); err != nil {
|
|
|
|
if err := callbackOnlinePush(ctx, p.config, userIDs, msg); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// push
|
|
|
|
// push
|
|
|
@ -130,7 +132,7 @@ func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.Msg
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if len(offlinePushUserIDList) > 0 {
|
|
|
|
if len(offlinePushUserIDList) > 0 {
|
|
|
|
if err = callbackOfflinePush(ctx, offlinePushUserIDList, msg, &[]string{}); err != nil {
|
|
|
|
if err = callbackOfflinePush(ctx, p.config, offlinePushUserIDList, msg, &[]string{}); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = p.offlinePushMsg(ctx, msg.SendID, msg, offlinePushUserIDList)
|
|
|
|
err = p.offlinePushMsg(ctx, msg.SendID, msg, offlinePushUserIDList)
|
|
|
@ -163,7 +165,7 @@ func (p *Pusher) k8sOfflinePush2SuperGroup(ctx context.Context, groupID string,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(needOfflinePushUserIDs) > 0 {
|
|
|
|
if len(needOfflinePushUserIDs) > 0 {
|
|
|
|
var offlinePushUserIDs []string
|
|
|
|
var offlinePushUserIDs []string
|
|
|
|
err := callbackOfflinePush(ctx, needOfflinePushUserIDs, msg, &offlinePushUserIDs)
|
|
|
|
err := callbackOfflinePush(ctx, p.config, needOfflinePushUserIDs, msg, &offlinePushUserIDs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,7 +196,7 @@ func (p *Pusher) k8sOfflinePush2SuperGroup(ctx context.Context, groupID string,
|
|
|
|
func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws.MsgData) (err error) {
|
|
|
|
func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws.MsgData) (err error) {
|
|
|
|
log.ZDebug(ctx, "Get super group msg from msg_transfer and push msg", "msg", msg.String(), "groupID", groupID)
|
|
|
|
log.ZDebug(ctx, "Get super group msg from msg_transfer and push msg", "msg", msg.String(), "groupID", groupID)
|
|
|
|
var pushToUserIDs []string
|
|
|
|
var pushToUserIDs []string
|
|
|
|
if err = callbackBeforeSuperGroupOnlinePush(ctx, groupID, msg, &pushToUserIDs); err != nil {
|
|
|
|
if err = callbackBeforeSuperGroupOnlinePush(ctx, p.config, groupID, msg, &pushToUserIDs); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -235,11 +237,11 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.ZInfo(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(pushToUserIDs), "list", pushToUserIDs)
|
|
|
|
log.ZInfo(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(pushToUserIDs), "list", pushToUserIDs)
|
|
|
|
if len(config.Config.Manager.UserID) > 0 {
|
|
|
|
if len(p.config.Manager.UserID) > 0 {
|
|
|
|
ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.UserID[0])
|
|
|
|
ctx = mcontext.WithOpUserIDContext(ctx, p.config.Manager.UserID[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(config.Config.Manager.UserID) == 0 && len(config.Config.IMAdmin.UserID) > 0 {
|
|
|
|
if len(p.config.Manager.UserID) == 0 && len(p.config.IMAdmin.UserID) > 0 {
|
|
|
|
ctx = mcontext.WithOpUserIDContext(ctx, config.Config.IMAdmin.UserID[0])
|
|
|
|
ctx = mcontext.WithOpUserIDContext(ctx, p.config.IMAdmin.UserID[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer func(groupID string) {
|
|
|
|
defer func(groupID string) {
|
|
|
|
if err = p.groupRpcClient.DismissGroup(ctx, groupID); err != nil {
|
|
|
|
if err = p.groupRpcClient.DismissGroup(ctx, groupID); err != nil {
|
|
|
@ -257,10 +259,10 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
|
|
|
|
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "get conn and online push success", "result", wsResults, "msg", msg)
|
|
|
|
log.ZDebug(ctx, "get conn and online push success", "result", wsResults, "msg", msg)
|
|
|
|
isOfflinePush := utils.GetSwitchFromOptions(msg.Options, constant.IsOfflinePush)
|
|
|
|
isOfflinePush := utils.GetSwitchFromOptions(msg.Options, constant.IsOfflinePush)
|
|
|
|
if isOfflinePush && config.Config.Envs.Discovery == "k8s" {
|
|
|
|
if isOfflinePush && p.config.Envs.Discovery == "k8s" {
|
|
|
|
return p.k8sOfflinePush2SuperGroup(ctx, groupID, msg, wsResults)
|
|
|
|
return p.k8sOfflinePush2SuperGroup(ctx, groupID, msg, wsResults)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isOfflinePush && config.Config.Envs.Discovery == "zookeeper" {
|
|
|
|
if isOfflinePush && p.config.Envs.Discovery == "zookeeper" {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
onlineSuccessUserIDs = []string{msg.SendID}
|
|
|
|
onlineSuccessUserIDs = []string{msg.SendID}
|
|
|
|
webAndPcBackgroundUserIDs []string
|
|
|
|
webAndPcBackgroundUserIDs []string
|
|
|
@ -298,7 +300,7 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
|
|
|
|
// Use offline push messaging
|
|
|
|
// Use offline push messaging
|
|
|
|
if len(needOfflinePushUserIDs) > 0 {
|
|
|
|
if len(needOfflinePushUserIDs) > 0 {
|
|
|
|
var offlinePushUserIDs []string
|
|
|
|
var offlinePushUserIDs []string
|
|
|
|
err = callbackOfflinePush(ctx, needOfflinePushUserIDs, msg, &offlinePushUserIDs)
|
|
|
|
err = callbackOfflinePush(ctx, p.config, needOfflinePushUserIDs, msg, &offlinePushUserIDs)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -357,7 +359,7 @@ func (p *Pusher) k8sOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUs
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
mu sync.Mutex
|
|
|
|
mu sync.Mutex
|
|
|
|
wg = errgroup.Group{}
|
|
|
|
wg = errgroup.Group{}
|
|
|
|
maxWorkers = config.Config.Push.MaxConcurrentWorkers
|
|
|
|
maxWorkers = p.config.Push.MaxConcurrentWorkers
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if maxWorkers < 3 {
|
|
|
|
if maxWorkers < 3 {
|
|
|
|
maxWorkers = 3
|
|
|
|
maxWorkers = 3
|
|
|
@ -386,10 +388,10 @@ func (p *Pusher) k8sOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUs
|
|
|
|
return wsResults, nil
|
|
|
|
return wsResults, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
|
|
|
|
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
|
|
|
|
if config.Config.Envs.Discovery == "k8s" {
|
|
|
|
if p.config.Envs.Discovery == "k8s" {
|
|
|
|
return p.k8sOnlinePush(ctx, msg, pushToUserIDs)
|
|
|
|
return p.k8sOnlinePush(ctx, msg, pushToUserIDs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conns, err := p.discov.GetConns(ctx, config.Config.RpcRegisterName.OpenImMessageGatewayName)
|
|
|
|
conns, err := p.discov.GetConns(ctx, p.config.RpcRegisterName.OpenImMessageGatewayName)
|
|
|
|
log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
|
|
|
|
log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -399,7 +401,7 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
|
|
|
|
mu sync.Mutex
|
|
|
|
mu sync.Mutex
|
|
|
|
wg = errgroup.Group{}
|
|
|
|
wg = errgroup.Group{}
|
|
|
|
input = &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}
|
|
|
|
input = &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}
|
|
|
|
maxWorkers = config.Config.Push.MaxConcurrentWorkers
|
|
|
|
maxWorkers = p.config.Push.MaxConcurrentWorkers
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if maxWorkers < 3 {
|
|
|
|
if maxWorkers < 3 {
|
|
|
|