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