Remove any logic from api.go [breaking-change] (#851)

Deprecated `Notify` binding got removed.
This commit is contained in:
Adam Babik 2018-04-23 15:34:49 +02:00 committed by GitHub
parent 5f075eeaba
commit b85e50cbc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 61 deletions

View File

@ -144,15 +144,11 @@ func (api *StatusAPI) VerifyAccountPassword(keyStoreDir, address, password strin
// using provided password. Once verification is done, decrypted key is injected into Whisper (as a single identity,
// all previous identities are removed).
func (api *StatusAPI) SelectAccount(address, password string) error {
// FIXME(oleg-raev): This method doesn't make stop, it rather resets its cells to an initial state
// and should be properly renamed, for example: ResetCells
api.b.jailManager.Stop()
return api.b.SelectAccount(address, password)
}
// Logout clears whisper identities
func (api *StatusAPI) Logout() error {
api.b.jailManager.Stop()
return api.b.Logout()
}
@ -209,53 +205,18 @@ func (api *StatusAPI) SetJailBaseJS(js string) {
api.b.jailManager.SetBaseJS(js)
}
// Notify sends a push notification to the device with the given token.
// @deprecated
func (api *StatusAPI) Notify(token string) string {
api.log.Debug("Notify", "token", token)
message := "Hello World1"
tokens := []string{token}
err := api.b.newNotification().Send(message, fcm.NotificationPayload{}, tokens...)
if err != nil {
api.log.Error("Notify failed", "error", err)
}
return token
}
// NotifyUsers send notifications to users.
func (api *StatusAPI) NotifyUsers(message string, payload fcm.NotificationPayload, tokens ...string) error {
api.log.Debug("Notify", "tokens", tokens)
err := api.b.newNotification().Send(message, payload, tokens...)
if err != nil {
api.log.Error("Notify failed", "error", err)
}
return err
return api.b.NotifyUsers(message, payload, tokens...)
}
// ConnectionChange handles network state changes logic.
func (api *StatusAPI) ConnectionChange(typ string, expensive bool) {
state := ConnectionState{
Type: NewConnectionType(typ),
Expensive: expensive,
}
if typ == "none" {
state.Offline = true
}
api.b.ConnectionChange(state)
api.b.ConnectionChange(typ, expensive)
}
// AppStateChange handles app state changes (background/foreground).
// state values: see https://facebook.github.io/react-native/docs/appstate.html
func (api *StatusAPI) AppStateChange(state string) {
appState, err := ParseAppState(state)
if err != nil {
log.Error("AppStateChange failed, ignoring", "error", err)
return // and do nothing
}
api.b.AppStateChange(appState)
api.b.AppStateChange(state)
}

View File

@ -9,6 +9,8 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
fcmlib "github.com/NaySoftware/go-fcm"
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/jail"
"github.com/status-im/status-go/geth/node"
@ -305,11 +307,20 @@ func (b *StatusBackend) registerHandlers() error {
//
// ConnectionChange handles network state changes logic.
func (b *StatusBackend) ConnectionChange(state ConnectionState) {
func (b *StatusBackend) ConnectionChange(typ string, expensive bool) {
b.mu.Lock()
defer b.mu.Unlock()
state := ConnectionState{
Type: NewConnectionType(typ),
Expensive: expensive,
}
if typ == "none" {
state.Offline = true
}
b.log.Info("Network state change", "old", b.connectionState, "new", state)
b.connectionState = state
// logic of handling state changes here
@ -317,8 +328,15 @@ func (b *StatusBackend) ConnectionChange(state ConnectionState) {
}
// AppStateChange handles app state changes (background/foreground).
func (b *StatusBackend) AppStateChange(state AppState) {
b.log.Info("App State changed.", "new-state", state)
// state values: see https://facebook.github.io/react-native/docs/appstate.html
func (b *StatusBackend) AppStateChange(state string) {
appState, err := ParseAppState(state)
if err != nil {
log.Error("AppStateChange failed, ignoring", "error", err)
return // and do nothing
}
b.log.Info("App State changed", "new-state", appState)
// TODO: put node in low-power mode if the app is in background (or inactive)
// and normal mode if the app is in foreground.
@ -326,6 +344,10 @@ func (b *StatusBackend) AppStateChange(state AppState) {
// Logout clears whisper identities.
func (b *StatusBackend) Logout() error {
// FIXME(oleg-raev): This method doesn't make stop, it rather resets its cells to an initial state
// and should be properly renamed, for example: ResetCells
b.jailManager.Stop()
whisperService, err := b.statusNode.WhisperService()
switch err {
case node.ErrServiceUnknown: // Whisper was never registered
@ -366,6 +388,10 @@ func (b *StatusBackend) ReSelectAccount() error {
// using provided password. Once verification is done, decrypted key is injected into Whisper (as a single identity,
// all previous identities are removed).
func (b *StatusBackend) SelectAccount(address, password string) error {
// FIXME(oleg-raev): This method doesn't make stop, it rather resets its cells to an initial state
// and should be properly renamed, for example: ResetCells
b.jailManager.Stop()
err := b.accountManager.SelectAccount(address, password)
if err != nil {
return err
@ -388,3 +414,13 @@ func (b *StatusBackend) SelectAccount(address, password string) error {
return nil
}
// NotifyUsers sends push notifications to users.
func (b *StatusBackend) NotifyUsers(message string, payload fcmlib.NotificationPayload, tokens ...string) error {
err := b.newNotification().Send(message, payload, tokens...)
if err != nil {
b.log.Error("Notify failed", "error", err)
}
return err
}

View File

@ -187,7 +187,7 @@ func TestBackendAccountsConcurrently(t *testing.T) {
}
func TestBackendConnectionChangesConcurrently(t *testing.T) {
connections := []ConnectionType{ConnectionUnknown, ConnectionCellular, ConnectionWifi}
connections := [...]string{"wifi", "cellular"}
backend := NewStatusBackend()
count := 3
@ -197,11 +197,7 @@ func TestBackendConnectionChangesConcurrently(t *testing.T) {
wg.Add(1)
go func() {
connIdx := rand.Intn(len(connections))
backend.ConnectionChange(ConnectionState{
Offline: false,
Type: connections[connIdx],
Expensive: false,
})
backend.ConnectionChange(connections[connIdx], false)
wg.Done()
}()
}

View File

@ -400,14 +400,6 @@ func makeJSONResponse(err error) *C.char {
return C.CString(string(outBytes))
}
// Notify sends push notification by given token
// @deprecated
//export Notify
func Notify(token *C.char) *C.char {
res := statusAPI.Notify(C.GoString(token))
return C.CString(res)
}
// NotifyUsers sends push notifications by given tokens.
//export NotifyUsers
func NotifyUsers(message, payloadJSON, tokensArray *C.char) (outCBytes *C.char) {

View File

@ -10,6 +10,7 @@ import (
"time"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/geth/jail"
"github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/geth/signal"
@ -114,6 +115,8 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(s.Backend.SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password))
EnsureNodeSync(s.Backend.StatusNode().EnsureSync)
// obtain VM for a given chat (to send custom JS to jailed version of Send())
@ -134,8 +137,6 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
event := envelope.Event.(map[string]interface{})
s.T().Logf("transaction queued and will be completed shortly, id: %v", event["id"])
s.NoError(s.Backend.SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password))
txID := event["id"].(string)
result := s.Backend.ApproveSignRequest(txID, TestConfig.Account1.Password)
txHash.SetBytes(result.Response.Bytes())