Notifier constructor renamed

This commit is contained in:
Evgeny Danienko 2017-10-18 23:17:40 +03:00
parent f159ea85a0
commit 9efed591da
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
6 changed files with 26 additions and 26 deletions

View File

@ -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)
}

View File

@ -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,
}
}

View File

@ -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

View File

@ -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...)
}

View File

@ -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(&notification.Payload{
Title: "Status - new message",
Body: "ping",

View File

@ -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)
}