From 9efed591dab6f0bcaa316e3a5f54f5ce1b795b3a Mon Sep 17 00:00:00 2001 From: Evgeny Danienko <6655321@bk.ru> Date: Wed, 18 Oct 2017 23:17:40 +0300 Subject: [PATCH] Notifier constructor renamed --- geth/api/api.go | 2 +- geth/api/backend.go | 22 +++++++++++----------- geth/common/notification.go | 6 +++--- geth/common/notification_mock.go | 12 ++++++------ geth/notification/fcm/notifier.go | 6 +++--- geth/notification/fcm/notifier_test.go | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/geth/api/api.go b/geth/api/api.go index 377a46a5f..be639abbf 100644 --- a/geth/api/api.go +++ b/geth/api/api.go @@ -204,7 +204,7 @@ func (api *StatusAPI) Notify(token string) error { "sum": "Happy Day", } - err := api.b.notifier().Notify(msg, token) + err := api.b.newNotification().Send(msg, token) if err != nil { log.Error("Notify failed:", err) } diff --git a/geth/api/backend.go b/geth/api/backend.go index d52b25aa9..b4fc458da 100644 --- a/geth/api/backend.go +++ b/geth/api/backend.go @@ -24,12 +24,12 @@ const ( // StatusBackend implements Status.im service type StatusBackend struct { sync.Mutex - nodeReady chan struct{} // channel to wait for when node is fully ready - nodeManager common.NodeManager - accountManager common.AccountManager - txQueueManager common.TxQueueManager - jailManager common.JailManager - notifier common.NotifierConstructor + nodeReady chan struct{} // channel to wait for when node is fully ready + nodeManager common.NodeManager + accountManager common.AccountManager + txQueueManager common.TxQueueManager + jailManager common.JailManager + newNotification common.NotificationConstructor } // NewStatusBackend create a new NewStatusBackend instance @@ -43,11 +43,11 @@ func NewStatusBackend() *StatusBackend { notificationManager := fcm.NewNotifier(fcmServerKey) return &StatusBackend{ - nodeManager: nodeManager, - accountManager: accountManager, - jailManager: jailManager, - txQueueManager: txQueueManager, - notifier: notificationManager, + nodeManager: nodeManager, + accountManager: accountManager, + jailManager: jailManager, + txQueueManager: txQueueManager, + newNotification: notificationManager, } } diff --git a/geth/common/notification.go b/geth/common/notification.go index dcd67ccd4..34ba674c7 100644 --- a/geth/common/notification.go +++ b/geth/common/notification.go @@ -2,8 +2,8 @@ package common // Notifier manages Push Notifications. type Notifier interface { - Notify(body interface{}, tokens ...string) error + Send(body interface{}, tokens ...string) error } -// NotifierConstructor returns constructor of configured instance Notifier interface. -type NotifierConstructor func() Notifier +// 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 index acb145e76..accbd8cd8 100644 --- a/geth/common/notification_mock.go +++ b/geth/common/notification_mock.go @@ -32,19 +32,19 @@ func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder { return m.recorder } -// Notify mocks base method -func (m *MockNotifier) Notify(body interface{}, tokens ...string) error { +// Send mocks base method +func (m *MockNotifier) Send(body interface{}, tokens ...string) error { varargs := []interface{}{body} for _, a := range tokens { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "Notify", varargs...) + ret := m.ctrl.Call(m, "Send", varargs...) ret0, _ := ret[0].(error) return ret0 } -// Notify indicates an expected call of Notify -func (mr *MockNotifierMockRecorder) Notify(body interface{}, tokens ...interface{}) *gomock.Call { +// Send indicates an expected call of Send +func (mr *MockNotifierMockRecorder) Send(body interface{}, tokens ...interface{}) *gomock.Call { varargs := append([]interface{}{body}, tokens...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Notify", reflect.TypeOf((*MockNotifier)(nil).Notify), varargs...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockNotifier)(nil).Send), varargs...) } diff --git a/geth/notification/fcm/notifier.go b/geth/notification/fcm/notifier.go index f43e2d59e..7ebcfe280 100644 --- a/geth/notification/fcm/notifier.go +++ b/geth/notification/fcm/notifier.go @@ -12,14 +12,14 @@ type Notifier struct { } // NewNotifier Firebase Cloud Messaging client constructor. -func NewNotifier(key string) func() common.Notifier { +func NewNotifier(key string) common.NotificationConstructor { return func() common.Notifier { return &Notifier{fcm.NewFcmClient(key)} } } -// Notify preparation and send to the tokens list. -func (n *Notifier) Notify(body interface{}, tokens ...string) error { +// Send send to the tokens list. +func (n *Notifier) Send(body interface{}, tokens ...string) error { n.setPayload(¬ification.Payload{ Title: "Status - new message", Body: "ping", diff --git a/geth/notification/fcm/notifier_test.go b/geth/notification/fcm/notifier_test.go index 320fd6798..91cbbe551 100644 --- a/geth/notification/fcm/notifier_test.go +++ b/geth/notification/fcm/notifier_test.go @@ -39,7 +39,7 @@ func (s *NotifierTestSuite) TestNotifySuccess() { s.fcmClientMock.EXPECT().Send().Return(nil, nil).Times(1) fcmClient := Notifier{s.fcmClientMock} - err := fcmClient.Notify(body, ids...) + err := fcmClient.Send(body, ids...) s.NoError(err) } @@ -55,7 +55,7 @@ func (s *NotifierTestSuite) TestNotifyError() { s.fcmClientMock.EXPECT().Send().Return(nil, expectedError).Times(1) fcmClient := Notifier{s.fcmClientMock} - err := fcmClient.Notify(body, ids...) + err := fcmClient.Send(body, ids...) s.Equal(expectedError, err) }