Merge pull request #756 from status-im/improvement/issue-755/restructure-notifier-interfaces

[#755] Restructure notifier interfaces
This commit is contained in:
Adrià Cidre 2018-03-23 11:29:48 +01:00 committed by GitHub
commit c7d19c56f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 67 deletions

View File

@ -113,7 +113,6 @@ mock-install: ##@other Install mocking tools
mock: ##@other Regenerate mocks
mockgen -source=geth/common/types.go -destination=geth/common/types_mock.go -package=common
mockgen -source=geth/mailservice/mailservice.go -destination=geth/mailservice/mailservice_mock.go -package=mailservice
mockgen -source=geth/common/notification.go -destination=geth/common/notification_mock.go -package=common -imports fcm=github.com/NaySoftware/go-fcm
mockgen -source=geth/notifications/push/fcm/client.go -destination=geth/notifications/push/fcm/client_mock.go -package=fcm -imports fcm=github.com/NaySoftware/go-fcm
mockgen -source=geth/transactions/fake/txservice.go -destination=geth/transactions/fake/mock.go -package=fake

View File

@ -30,7 +30,7 @@ type StatusBackend struct {
accountManager common.AccountManager
txQueueManager *transactions.Manager
jailManager jail.Manager
newNotification common.NotificationConstructor
newNotification fcm.NotificationConstructor
connectionState ConnectionState
log log.Logger
}

View File

@ -1,11 +0,0 @@
package common
import "github.com/NaySoftware/go-fcm"
// Notifier manages Push Notifications.
type Notifier interface {
Send(body string, payload fcm.NotificationPayload, tokens ...string) error
}
// NotificationConstructor returns constructor of configured instance Notifier interface.
type NotificationConstructor func() Notifier

View File

@ -1,51 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/common/notification.go
// Package common is a generated GoMock package.
package common
import (
go_fcm "github.com/NaySoftware/go-fcm"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
)
// MockNotifier is a mock of Notifier interface
type MockNotifier struct {
ctrl *gomock.Controller
recorder *MockNotifierMockRecorder
}
// MockNotifierMockRecorder is the mock recorder for MockNotifier
type MockNotifierMockRecorder struct {
mock *MockNotifier
}
// NewMockNotifier creates a new mock instance
func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier {
mock := &MockNotifier{ctrl: ctrl}
mock.recorder = &MockNotifierMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder {
return m.recorder
}
// Send mocks base method
func (m *MockNotifier) Send(body string, payload go_fcm.NotificationPayload, tokens ...string) error {
varargs := []interface{}{body, payload}
for _, a := range tokens {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Send", varargs...)
ret0, _ := ret[0].(error)
return ret0
}
// Send indicates an expected call of Send
func (mr *MockNotifierMockRecorder) Send(body, payload interface{}, tokens ...interface{}) *gomock.Call {
varargs := append([]interface{}{body, payload}, tokens...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockNotifier)(nil).Send), varargs...)
}

View File

@ -4,17 +4,24 @@ import (
"fmt"
"github.com/NaySoftware/go-fcm"
"github.com/status-im/status-go/geth/common"
)
// Notifier manages Push Notifications.
type Notifier interface {
Send(body string, payload fcm.NotificationPayload, tokens ...string) error
}
// NotificationConstructor returns constructor of configured instance Notifier interface.
type NotificationConstructor func() Notifier
// Notification represents messaging provider for notifications.
type Notification struct {
client firebaseClient
}
// NewNotification Firebase Cloud Messaging client constructor.
func NewNotification(key string) common.NotificationConstructor {
return func() common.Notifier {
func NewNotification(key string) NotificationConstructor {
return func() Notifier {
client := fcm.NewFcmClient(key).
SetDelayWhileIdle(true).
SetContentAvailable(true).