mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-15 14:35:57 +08:00
push
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user