From e22fa3611125c0689843df38de791da59e03e768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Cidre?= Date: Fri, 23 Mar 2018 09:55:05 +0100 Subject: [PATCH] [#755] Restructure notifier interfaces --- Makefile | 1 - geth/api/backend.go | 2 +- geth/common/notification.go | 11 ----- geth/common/notification_mock.go | 51 --------------------- geth/notifications/push/fcm/notification.go | 13 ++++-- 5 files changed, 11 insertions(+), 67 deletions(-) delete mode 100644 geth/common/notification.go delete mode 100644 geth/common/notification_mock.go diff --git a/Makefile b/Makefile index ab9246c5f..08d07ff59 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/geth/api/backend.go b/geth/api/backend.go index e45a7433e..65cec43f4 100644 --- a/geth/api/backend.go +++ b/geth/api/backend.go @@ -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 } diff --git a/geth/common/notification.go b/geth/common/notification.go deleted file mode 100644 index e30920547..000000000 --- a/geth/common/notification.go +++ /dev/null @@ -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 diff --git a/geth/common/notification_mock.go b/geth/common/notification_mock.go deleted file mode 100644 index 70dd0682a..000000000 --- a/geth/common/notification_mock.go +++ /dev/null @@ -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...) -} diff --git a/geth/notifications/push/fcm/notification.go b/geth/notifications/push/fcm/notification.go index c36283f14..4eb3dcd83 100644 --- a/geth/notifications/push/fcm/notification.go +++ b/geth/notifications/push/fcm/notification.go @@ -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).