From 0ed07dfa2a828873f7d383e0727adf7d49e1a857 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 3 Mar 2023 19:59:10 +0800 Subject: [PATCH] proto modify --- internal/push/{ => offlinepush}/fcm/push.go | 4 +- .../push/{ => offlinepush}/fcm/push_test.go | 4 +- internal/push/{ => offlinepush}/getui/body.go | 0 internal/push/{ => offlinepush}/getui/push.go | 6 +-- .../{ => offlinepush}/jpush/body/audience.go | 0 .../{ => offlinepush}/jpush/body/message.go | 0 .../jpush/body/notification.go | 0 .../{ => offlinepush}/jpush/body/options.go | 0 .../{ => offlinepush}/jpush/body/platform.go | 0 .../{ => offlinepush}/jpush/body/pushobj.go | 0 internal/push/{ => offlinepush}/jpush/push.go | 6 +-- .../push/offlinepush/offlinepush_interface.go | 20 ++++++++++ internal/push/offlinepush_interface.go | 39 ------------------- internal/push/push_to_client.go | 31 ++++++++++++--- 14 files changed, 55 insertions(+), 55 deletions(-) rename internal/push/{ => offlinepush}/fcm/push.go (97%) rename internal/push/{ => offlinepush}/fcm/push_test.go (78%) rename internal/push/{ => offlinepush}/getui/body.go (100%) rename internal/push/{ => offlinepush}/getui/push.go (97%) rename internal/push/{ => offlinepush}/jpush/body/audience.go (100%) rename internal/push/{ => offlinepush}/jpush/body/message.go (100%) rename internal/push/{ => offlinepush}/jpush/body/notification.go (100%) rename internal/push/{ => offlinepush}/jpush/body/options.go (100%) rename internal/push/{ => offlinepush}/jpush/body/platform.go (100%) rename internal/push/{ => offlinepush}/jpush/body/pushobj.go (100%) rename internal/push/{ => offlinepush}/jpush/push.go (92%) create mode 100644 internal/push/offlinepush/offlinepush_interface.go delete mode 100644 internal/push/offlinepush_interface.go diff --git a/internal/push/fcm/push.go b/internal/push/offlinepush/fcm/push.go similarity index 97% rename from internal/push/fcm/push.go rename to internal/push/offlinepush/fcm/push.go index c530d2342..77b8c8f7a 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/offlinepush/fcm/push.go @@ -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 { diff --git a/internal/push/fcm/push_test.go b/internal/push/offlinepush/fcm/push_test.go similarity index 78% rename from internal/push/fcm/push_test.go rename to internal/push/offlinepush/fcm/push_test.go index 360133311..611c1f697 100644 --- a/internal/push/fcm/push_test.go +++ b/internal/push/offlinepush/fcm/push_test.go @@ -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) } diff --git a/internal/push/getui/body.go b/internal/push/offlinepush/getui/body.go similarity index 100% rename from internal/push/getui/body.go rename to internal/push/offlinepush/getui/body.go diff --git a/internal/push/getui/push.go b/internal/push/offlinepush/getui/push.go similarity index 97% rename from internal/push/getui/push.go rename to internal/push/offlinepush/getui/push.go index 5f51b1083..296421da4 100644 --- a/internal/push/getui/push.go +++ b/internal/push/offlinepush/getui/push.go @@ -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) { diff --git a/internal/push/jpush/body/audience.go b/internal/push/offlinepush/jpush/body/audience.go similarity index 100% rename from internal/push/jpush/body/audience.go rename to internal/push/offlinepush/jpush/body/audience.go diff --git a/internal/push/jpush/body/message.go b/internal/push/offlinepush/jpush/body/message.go similarity index 100% rename from internal/push/jpush/body/message.go rename to internal/push/offlinepush/jpush/body/message.go diff --git a/internal/push/jpush/body/notification.go b/internal/push/offlinepush/jpush/body/notification.go similarity index 100% rename from internal/push/jpush/body/notification.go rename to internal/push/offlinepush/jpush/body/notification.go diff --git a/internal/push/jpush/body/options.go b/internal/push/offlinepush/jpush/body/options.go similarity index 100% rename from internal/push/jpush/body/options.go rename to internal/push/offlinepush/jpush/body/options.go diff --git a/internal/push/jpush/body/platform.go b/internal/push/offlinepush/jpush/body/platform.go similarity index 100% rename from internal/push/jpush/body/platform.go rename to internal/push/offlinepush/jpush/body/platform.go diff --git a/internal/push/jpush/body/pushobj.go b/internal/push/offlinepush/jpush/body/pushobj.go similarity index 100% rename from internal/push/jpush/body/pushobj.go rename to internal/push/offlinepush/jpush/body/pushobj.go diff --git a/internal/push/jpush/push.go b/internal/push/offlinepush/jpush/push.go similarity index 92% rename from internal/push/jpush/push.go rename to internal/push/offlinepush/jpush/push.go index 403bb24cb..9a1fa791d 100644 --- a/internal/push/jpush/push.go +++ b/internal/push/offlinepush/jpush/push.go @@ -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 diff --git a/internal/push/offlinepush/offlinepush_interface.go b/internal/push/offlinepush/offlinepush_interface.go new file mode 100644 index 000000000..0060b3e30 --- /dev/null +++ b/internal/push/offlinepush/offlinepush_interface.go @@ -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 +} diff --git a/internal/push/offlinepush_interface.go b/internal/push/offlinepush_interface.go deleted file mode 100644 index 8cf788c83..000000000 --- a/internal/push/offlinepush_interface.go +++ /dev/null @@ -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 -} diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index c493d484e..d5325c0f3 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -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