Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(push): push content with jpush #2844

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/openim-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ prometheus:
ports: [ 12170, 12171, 12172, 12173, 12174, 12175, 12176, 12177, 12178, 12179, 12180, 12182, 12183, 12184, 12185, 12186 ]

maxConcurrentWorkers: 3
#Use geTui for offline push notifications, or choose fcm or jpns; corresponding configuration settings must be specified.
#Use geTui for offline push notifications, or choose fcm or jpush; corresponding configuration settings must be specified.
enable: geTui
geTui:
pushUrl: https://restapi.getui.com/v2/$appId
Expand Down
33 changes: 20 additions & 13 deletions internal/push/offlinepush/jpush/body/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package body

import (
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
)

Expand All @@ -26,32 +27,38 @@ type Notification struct {

type Android struct {
Alert string `json:"alert,omitempty"`
Title string `json:"title,omitempty"`
Intent struct {
URL string `json:"url,omitempty"`
} `json:"intent,omitempty"`
Extras Extras `json:"extras"`
Extras map[string]string `json:"extras,omitempty"`
}
type Ios struct {
Alert string `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Extras Extras `json:"extras"`
MutableContent bool `json:"mutable-content"`
Alert IosAlert `json:"alert,omitempty"`
Sound string `json:"sound,omitempty"`
Badge string `json:"badge,omitempty"`
Extras map[string]string `json:"extras,omitempty"`
MutableContent bool `json:"mutable-content"`
}

type Extras struct {
ClientMsgID string `json:"clientMsgID"`
type IosAlert struct {
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
}

func (n *Notification) SetAlert(alert string) {
func (n *Notification) SetAlert(alert string, title string, opts *options.Opts) {
n.Alert = alert
n.Android.Alert = alert
n.IOS.Alert = alert
n.IOS.Sound = "default"
n.IOS.Badge = "+1"
n.Android.Title = title
n.IOS.Alert.Body = alert
n.IOS.Alert.Title = title
n.IOS.Sound = opts.IOSPushSound
if opts.IOSBadgeCount {
n.IOS.Badge = "+1"
}
}

func (n *Notification) SetExtras(extras Extras) {
func (n *Notification) SetExtras(extras map[string]string) {
n.IOS.Extras = extras
n.Android.Extras = extras
}
Expand Down
29 changes: 21 additions & 8 deletions internal/push/offlinepush/jpush/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"

"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/jpush/body"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/tools/utils/httputil"
)
Expand Down Expand Up @@ -57,17 +57,23 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
var au body.Audience
au.SetAlias(userIDs)
var no body.Notification
var extras body.Extras
extras := make(map[string]string)
extras["ex"] = opts.Ex
if opts.Signal.ClientMsgID != "" {
extras.ClientMsgID = opts.Signal.ClientMsgID
extras["ClientMsgID"] = opts.Signal.ClientMsgID
}
no.IOSEnableMutableContent()
no.SetExtras(extras)
no.SetAlert(title)
no.SetAlert(content, title, opts)
no.SetAndroidIntent(j.pushConf)

var msg body.Message
msg.SetMsgContent(content)
msg.SetTitle(title)
if opts.Signal.ClientMsgID != "" {
msg.SetExtras("ClientMsgID", opts.Signal.ClientMsgID)
}
msg.SetExtras("ex", opts.Ex)
var opt body.Options
opt.SetApnsProduction(j.pushConf.IOSPush.Production)
var pushObj body.PushObj
Expand All @@ -76,12 +82,12 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
pushObj.SetNotification(&no)
pushObj.SetMessage(&msg)
pushObj.SetOptions(&opt)
var resp any
return j.request(ctx, pushObj, resp, 5)
var resp map[string]string
return j.request(ctx, pushObj, &resp, 5)
}

func (j *JPush) request(ctx context.Context, po body.PushObj, resp any, timeout int) error {
return j.httpClient.PostReturn(
func (j *JPush) request(ctx context.Context, po body.PushObj, resp *map[string]string, timeout int) error {
err := j.httpClient.PostReturn(
ctx,
j.pushConf.JPNS.PushURL,
map[string]string{
Expand All @@ -91,4 +97,11 @@ func (j *JPush) request(ctx context.Context, po body.PushObj, resp any, timeout
resp,
timeout,
)
if err != nil {
return err
}
if (*resp)["sendno"] != "0" {
return fmt.Errorf("jpush push failed %v", resp)
}
return nil
}
2 changes: 1 addition & 1 deletion internal/push/offlinepush_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (o *OfflinePushConsumerHandler) getOfflinePushInfos(msg *sdkws.MsgData) (ti
IsAtSelf bool `json:"isAtSelf"`
}

opts = &options.Opts{Signal: &options.Signal{}}
opts = &options.Opts{Signal: &options.Signal{ClientMsgID: msg.ClientMsgID}}
if msg.OfflinePushInfo != nil {
opts.IOSBadgeCount = msg.OfflinePushInfo.IOSBadgeCount
opts.IOSPushSound = msg.OfflinePushInfo.IOSPushSound
Expand Down
10 changes: 6 additions & 4 deletions internal/push/push_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"context"
"encoding/json"

"math/rand"
"strconv"
"time"

"github.com/IBM/sarama"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options"
Expand All @@ -27,9 +31,6 @@ import (
"github.com/openimsdk/tools/utils/timeutil"
"github.com/redis/go-redis/v9"
"google.golang.org/protobuf/proto"
"math/rand"
"strconv"
"time"
)

type ConsumerHandler struct {
Expand Down Expand Up @@ -332,6 +333,7 @@ func (c *ConsumerHandler) groupMessagesHandler(ctx context.Context, groupID stri
func (c *ConsumerHandler) offlinePushMsg(ctx context.Context, msg *sdkws.MsgData, offlinePushUserIDs []string) error {
title, content, opts, err := c.getOfflinePushInfos(msg)
if err != nil {
log.ZError(ctx, "getOfflinePushInfos failed", err, "msg", msg)
return err
}
err = c.offlinePusher.Push(ctx, offlinePushUserIDs, title, content, opts)
Expand Down Expand Up @@ -361,7 +363,7 @@ func (c *ConsumerHandler) getOfflinePushInfos(msg *sdkws.MsgData) (title, conten
IsAtSelf bool `json:"isAtSelf"`
}

opts = &options.Opts{Signal: &options.Signal{}}
opts = &options.Opts{Signal: &options.Signal{ClientMsgID: msg.ClientMsgID}}
if msg.OfflinePushInfo != nil {
opts.IOSBadgeCount = msg.OfflinePushInfo.IOSBadgeCount
opts.IOSPushSound = msg.OfflinePushInfo.IOSPushSound
Expand Down
Loading