Skip to content
Snippets Groups Projects
Commit 6b5d1182 authored by Jonah Husson's avatar Jonah Husson
Browse files

move notifications functions to separate file

parent 5923e8c8
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,6 @@ import ( ...@@ -25,7 +25,6 @@ import (
"gitlab.com/elixxir/client/rekey" "gitlab.com/elixxir/client/rekey"
"gitlab.com/elixxir/client/user" "gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/comms/connect" "gitlab.com/elixxir/comms/connect"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/crypto/large"
"gitlab.com/elixxir/crypto/signature/rsa" "gitlab.com/elixxir/crypto/signature/rsa"
...@@ -596,48 +595,3 @@ func (cl *Client) WriteToSessionFile(replacement string, store globals.Storage) ...@@ -596,48 +595,3 @@ func (cl *Client) WriteToSessionFile(replacement string, store globals.Storage)
return nil return nil
} }
// RegisterForNotifications sends a message to notification bot indicating it
// is registering for notifications
func (cl *Client) RegisterForNotifications(notificationToken []byte) error {
// Pull the host from the manage
notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
// Send the register message
_, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
&mixmessages.NotificationToken{
Token: notificationToken,
})
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
// UnregisterForNotifications sends a message to notification bot indicating it
// no longer wants to be registered for notifications
func (cl *Client) UnregisterForNotifications() error {
// Pull the host from the manage
notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
// Send the unregister message
_, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
...@@ -560,49 +560,3 @@ func TestClient_GetCommManager(t *testing.T) { ...@@ -560,49 +560,3 @@ func TestClient_GetCommManager(t *testing.T) {
t.Error("Received session not the same as the real session") t.Error("Received session not the same as the real session")
} }
} }
// Happy path
func TestClient_RegisterForNotifications(t *testing.T) {
// Initialize client with dummy storage
storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
client, err := NewClient(&storage, "hello", "", def)
if err != nil {
t.Errorf("Failed to initialize dummy client: %s", err.Error())
}
// InitNetwork to gateways and reg server
err = client.InitNetwork()
if err != nil {
t.Errorf("Client failed of connect: %+v", err)
}
token := make([]byte, 32)
err = client.RegisterForNotifications(token)
if err != nil {
t.Errorf("Expected happy path, received error: %+v", err)
}
}
// Happy path
func TestClient_UnregisterForNotifications(t *testing.T) {
// Initialize client with dummy storage
storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
client, err := NewClient(&storage, "hello", "", def)
if err != nil {
t.Errorf("Failed to initialize dummy client: %s", err.Error())
}
// InitNetwork to gateways and reg server
err = client.InitNetwork()
if err != nil {
t.Errorf("Client failed of connect: %+v", err)
}
err = client.UnregisterForNotifications()
if err != nil {
t.Errorf("Expected happy path, received error: %+v", err)
}
}
package api
import (
"github.com/pkg/errors"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/primitives/id"
)
// RegisterForNotifications sends a message to notification bot indicating it
// is registering for notifications
func (cl *Client) RegisterForNotifications(notificationToken []byte) error {
// Pull the host from the manage
notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
// Send the register message
_, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
&mixmessages.NotificationToken{
Token: notificationToken,
})
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
// UnregisterForNotifications sends a message to notification bot indicating it
// no longer wants to be registered for notifications
func (cl *Client) UnregisterForNotifications() error {
// Pull the host from the manage
notificationBotHost, ok := cl.receptionManager.Comms.GetHost(id.NOTIFICATION_BOT)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
// Send the unregister message
_, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
package api
import "testing"
// Happy path
func TestClient_RegisterForNotifications(t *testing.T) {
// Initialize client with dummy storage
storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
client, err := NewClient(&storage, "hello", "", def)
if err != nil {
t.Errorf("Failed to initialize dummy client: %s", err.Error())
return
}
// InitNetwork to gateways and reg server
err = client.InitNetwork()
if err != nil {
t.Errorf("Client failed of connect: %+v", err)
}
token := make([]byte, 32)
err = client.RegisterForNotifications(token)
if err != nil {
t.Errorf("Expected happy path, received error: %+v", err)
}
}
// Happy path
func TestClient_UnregisterForNotifications(t *testing.T) {
// Initialize client with dummy storage
storage := DummyStorage{LocationA: "Blah", StoreA: []byte{'a', 'b', 'c'}}
client, err := NewClient(&storage, "hello", "", def)
if err != nil {
t.Errorf("Failed to initialize dummy client: %s", err.Error())
}
// InitNetwork to gateways and reg server
err = client.InitNetwork()
if err != nil {
t.Errorf("Client failed of connect: %+v", err)
}
err = client.UnregisterForNotifications()
if err != nil {
t.Errorf("Expected happy path, received error: %+v", err)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment