This commit is contained in:
wangchuxiao
2023-02-22 19:51:14 +08:00
parent 2b38381296
commit 94d50a6c71
31 changed files with 500 additions and 602 deletions
+2 -3
View File
@@ -22,7 +22,7 @@ type Fcm struct {
cache cache.Cache
}
func newFcmClient(cache cache.Cache) *Fcm {
func NewClient(cache cache.Cache) *Fcm {
opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount))
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
if err != nil {
@@ -42,7 +42,7 @@ func newFcmClient(cache cache.Cache) *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 *push.Opts) error {
// accounts->registrationToken
allTokens := make(map[string][]string, 0)
for _, account := range userIDs {
@@ -105,7 +105,6 @@ func (f *Fcm) Push(ctx context.Context, userIDs []string, title, content string,
}
messages = append(messages, temp)
}
}
messageCount := len(messages)
if messageCount > 0 {
+5 -4
View File
@@ -2,14 +2,15 @@ package fcm
import (
"Open_IM/internal/push"
"fmt"
"Open_IM/pkg/common/db/cache"
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_Push(t *testing.T) {
offlinePusher := NewFcm()
resp, err := offlinePusher.Push([]string{"test_uid"}, "test", "test", "12321", push.PushOpts{})
var redis cache.Cache
offlinePusher := NewClient(redis)
err := offlinePusher.Push(context.Background(), []string{"userID1"}, "test", "test", &push.Opts{})
assert.Nil(t, err)
fmt.Println(resp)
}