mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 19:22:46 +08:00
proto modify
This commit is contained in:
parent
080dfa5563
commit
0ed07dfa2a
@ -1,7 +1,7 @@
|
||||
package fcm
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push"
|
||||
"OpenIM/internal/push/offlinepush"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
@ -42,7 +42,7 @@ func NewClient(cache cache.Model) *Fcm {
|
||||
return &Fcm{fcmMsgCli: fcmMsgClient}
|
||||
}
|
||||
|
||||
func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string, opts *push.Opts) error {
|
||||
func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
|
||||
// accounts->registrationToken
|
||||
allTokens := make(map[string][]string, 0)
|
||||
for _, account := range userIDs {
|
@ -1,7 +1,7 @@
|
||||
package fcm
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push"
|
||||
"OpenIM/internal/push/offlinepush"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
"context"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -11,6 +11,6 @@ import (
|
||||
func Test_Push(t *testing.T) {
|
||||
var redis cache.Model
|
||||
offlinePusher := NewClient(redis)
|
||||
err := offlinePusher.Push(context.Background(), []string{"userID1"}, "test", "test", &push.Opts{})
|
||||
err := offlinePusher.Push(context.Background(), []string{"userID1"}, "test", "test", &offlinepush.Opts{})
|
||||
assert.Nil(t, err)
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package getui
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push"
|
||||
"OpenIM/internal/push/offlinepush"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
http2 "OpenIM/pkg/common/http"
|
||||
@ -47,7 +47,7 @@ func NewClient(cache cache.Model) *Client {
|
||||
return &Client{cache: cache, tokenExpireTime: tokenExpireTime, taskIDTTL: taskIDTTL}
|
||||
}
|
||||
|
||||
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *push.Opts) error {
|
||||
func (g *Client) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
|
||||
token, err := g.cache.GetGetuiToken(ctx)
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
@ -150,7 +150,7 @@ func (g *Client) postReturn(url string, header map[string]string, input interfac
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return output.parseError()
|
||||
return parseError()
|
||||
}
|
||||
|
||||
func (g *Client) getTokenAndSave2Redis(ctx context.Context) (token string, err error) {
|
@ -1,8 +1,8 @@
|
||||
package jpush
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push"
|
||||
"OpenIM/internal/push/jpush/body"
|
||||
"OpenIM/internal/push/offlinepush"
|
||||
"OpenIM/internal/push/offlinepush/jpush/body"
|
||||
"OpenIM/pkg/common/config"
|
||||
http2 "OpenIM/pkg/common/http"
|
||||
"context"
|
||||
@ -31,7 +31,7 @@ func (j *JPush) getAuthorization(appKey string, masterSecret string) string {
|
||||
return Authorization
|
||||
}
|
||||
|
||||
func (j *JPush) Push(ctx context.Context, userIDs []string, title, content string, opts *push.Opts) error {
|
||||
func (j *JPush) Push(ctx context.Context, userIDs []string, title, content string, opts *offlinepush.Opts) error {
|
||||
var pf body.Platform
|
||||
pf.SetAll()
|
||||
var au body.Audience
|
20
internal/push/offlinepush/offlinepush_interface.go
Normal file
20
internal/push/offlinepush/offlinepush_interface.go
Normal file
@ -0,0 +1,20 @@
|
||||
package offlinepush
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type OfflinePusher interface {
|
||||
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
|
||||
}
|
||||
|
||||
type Opts struct {
|
||||
Signal *Signal
|
||||
IOSPushSound string
|
||||
IOSBadgeCount bool
|
||||
Ex string
|
||||
}
|
||||
|
||||
type Signal struct {
|
||||
ClientMsgID string
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package push
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push/fcm"
|
||||
"OpenIM/internal/push/getui"
|
||||
"OpenIM/internal/push/jpush"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
"context"
|
||||
)
|
||||
|
||||
type OfflinePusher interface {
|
||||
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
|
||||
}
|
||||
|
||||
func NewOfflinePusher(cache cache.Model) OfflinePusher {
|
||||
var offlinePusher OfflinePusher
|
||||
if config.Config.Push.Getui.Enable {
|
||||
offlinePusher = getui.NewClient(cache)
|
||||
}
|
||||
if config.Config.Push.Fcm.Enable {
|
||||
offlinePusher = fcm.NewClient(cache)
|
||||
}
|
||||
if config.Config.Push.Jpns.Enable {
|
||||
offlinePusher = jpush.NewClient()
|
||||
}
|
||||
return offlinePusher
|
||||
}
|
||||
|
||||
type Opts struct {
|
||||
Signal *Signal
|
||||
IOSPushSound string
|
||||
IOSBadgeCount bool
|
||||
Ex string
|
||||
}
|
||||
|
||||
type Signal struct {
|
||||
ClientMsgID string
|
||||
}
|
@ -7,8 +7,13 @@
|
||||
package push
|
||||
|
||||
import (
|
||||
"OpenIM/internal/push/offlinepush"
|
||||
"OpenIM/internal/push/offlinepush/fcm"
|
||||
"OpenIM/internal/push/offlinepush/getui"
|
||||
"OpenIM/internal/push/offlinepush/jpush"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
"OpenIM/pkg/common/db/controller"
|
||||
"OpenIM/pkg/common/db/localcache"
|
||||
"OpenIM/pkg/common/log"
|
||||
@ -26,13 +31,13 @@ import (
|
||||
type Pusher struct {
|
||||
database controller.PushDatabase
|
||||
client discoveryregistry.SvcDiscoveryRegistry
|
||||
offlinePusher OfflinePusher
|
||||
offlinePusher offlinepush.OfflinePusher
|
||||
groupLocalCache *localcache.GroupLocalCache
|
||||
conversationLocalCache *localcache.ConversationLocalCache
|
||||
successCount int
|
||||
}
|
||||
|
||||
func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher OfflinePusher, database controller.PushDatabase,
|
||||
func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
|
||||
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher {
|
||||
return &Pusher{
|
||||
database: database,
|
||||
@ -43,6 +48,20 @@ func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher Offl
|
||||
}
|
||||
}
|
||||
|
||||
func NewOfflinePusher(cache cache.Model) offlinepush.OfflinePusher {
|
||||
var offlinePusher offlinepush.OfflinePusher
|
||||
if config.Config.Push.Getui.Enable {
|
||||
offlinePusher = getui.NewClient(cache)
|
||||
}
|
||||
if config.Config.Push.Fcm.Enable {
|
||||
offlinePusher = fcm.NewClient(cache)
|
||||
}
|
||||
if config.Config.Push.Jpns.Enable {
|
||||
offlinePusher = jpush.NewClient()
|
||||
}
|
||||
return offlinePusher
|
||||
}
|
||||
|
||||
func (p *Pusher) MsgToUser(ctx context.Context, userID string, msg *sdkws.MsgData) error {
|
||||
operationID := tracelog.GetOperationID(ctx)
|
||||
var userIDs = []string{userID}
|
||||
@ -196,8 +215,8 @@ func (p *Pusher) offlinePushMsg(ctx context.Context, sourceID string, msg *sdkws
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *Opts, err error) {
|
||||
opts = &Opts{}
|
||||
func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *offlinepush.Opts, err error) {
|
||||
opts = &offlinepush.Opts{}
|
||||
if msg.ContentType > constant.SignalingNotificationBegin && msg.ContentType < constant.SignalingNotificationEnd {
|
||||
req := &sdkws.SignalReq{}
|
||||
if err := proto.Unmarshal(msg.Content, req); err != nil {
|
||||
@ -205,7 +224,7 @@ func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *Opts, err error)
|
||||
}
|
||||
switch req.Payload.(type) {
|
||||
case *sdkws.SignalReq_Invite, *sdkws.SignalReq_InviteInGroup:
|
||||
opts.Signal = &Signal{ClientMsgID: msg.ClientMsgID}
|
||||
opts.Signal = &offlinepush.Signal{ClientMsgID: msg.ClientMsgID}
|
||||
}
|
||||
}
|
||||
if msg.OfflinePushInfo != nil {
|
||||
@ -216,7 +235,7 @@ func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *Opts, err error)
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func (p *Pusher) getOfflinePushInfos(sourceID string, msg *sdkws.MsgData) (title, content string, opts *Opts, err error) {
|
||||
func (p *Pusher) getOfflinePushInfos(sourceID string, msg *sdkws.MsgData) (title, content string, opts *offlinepush.Opts, err error) {
|
||||
if p.offlinePusher == nil {
|
||||
err = errors.New("no offlinePusher is configured")
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user