drive settings from client

This commit is contained in:
Andrea Maria Piana 2020-07-15 14:25:01 +02:00
parent 8130e5b402
commit be1800f2ec
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
7 changed files with 144 additions and 68 deletions

View File

@ -12,6 +12,7 @@
// 0005_waku_mode.up.sql (146B)
// 0006_appearance.up.sql (67B)
// 0007_enable_waku_default.up.sql (38B)
// 0008_add_push_notifications.up.sql (214B)
// doc.go (74B)
package migrations
@ -321,6 +322,26 @@ func _0007_enable_waku_defaultUpSql() (*asset, error) {
return a, nil
}
var __0008_add_push_notificationsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x28\x4a\xcd\xcd\x2f\x49\x8d\x2f\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x2b\x8e\x4f\xcd\x4b\x4c\xca\x49\x4d\x51\x70\xf2\xf7\xf7\x71\x75\xf4\xb3\xe6\x22\x64\x54\x71\x6a\x5e\x0a\x16\x83\x88\x37\x00\x43\x6f\x7c\x71\x6a\x51\x59\x6a\x11\xa6\x53\x00\x01\x00\x00\xff\xff\xfc\xde\xba\xf0\xd6\x00\x00\x00")
func _0008_add_push_notificationsUpSqlBytes() ([]byte, error) {
return bindataRead(
__0008_add_push_notificationsUpSql,
"0008_add_push_notifications.up.sql",
)
}
func _0008_add_push_notificationsUpSql() (*asset, error) {
bytes, err := _0008_add_push_notificationsUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 214, mode: os.FileMode(0644), modTime: time.Unix(1594815858, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x77, 0x87, 0xd3, 0xd7, 0x50, 0x58, 0x80, 0x8f, 0x56, 0x4c, 0x2f, 0x1b, 0x58, 0x4d, 0x98, 0xdd, 0x3, 0xc5, 0x91, 0xad, 0x5e, 0xfe, 0xb, 0x54, 0xb3, 0x7e, 0xd8, 0xf7, 0x25, 0xa0, 0xda}}
return a, nil
}
var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00")
func docGoBytes() ([]byte, error) {
@ -456,6 +477,8 @@ var _bindata = map[string]func() (*asset, error){
"0007_enable_waku_default.up.sql": _0007_enable_waku_defaultUpSql,
"0008_add_push_notifications.up.sql": _0008_add_push_notificationsUpSql,
"doc.go": docGo,
}
@ -500,19 +523,20 @@ type bintree struct {
}
var _bintree = &bintree{nil, map[string]*bintree{
"0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}},
"0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}},
"0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}},
"0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}},
"0003_settings.down.sql": &bintree{_0003_settingsDownSql, map[string]*bintree{}},
"0003_settings.up.sql": &bintree{_0003_settingsUpSql, map[string]*bintree{}},
"0004_pending_stickers.down.sql": &bintree{_0004_pending_stickersDownSql, map[string]*bintree{}},
"0004_pending_stickers.up.sql": &bintree{_0004_pending_stickersUpSql, map[string]*bintree{}},
"0005_waku_mode.down.sql": &bintree{_0005_waku_modeDownSql, map[string]*bintree{}},
"0005_waku_mode.up.sql": &bintree{_0005_waku_modeUpSql, map[string]*bintree{}},
"0006_appearance.up.sql": &bintree{_0006_appearanceUpSql, map[string]*bintree{}},
"0007_enable_waku_default.up.sql": &bintree{_0007_enable_waku_defaultUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},
"0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}},
"0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}},
"0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}},
"0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}},
"0003_settings.down.sql": &bintree{_0003_settingsDownSql, map[string]*bintree{}},
"0003_settings.up.sql": &bintree{_0003_settingsUpSql, map[string]*bintree{}},
"0004_pending_stickers.down.sql": &bintree{_0004_pending_stickersDownSql, map[string]*bintree{}},
"0004_pending_stickers.up.sql": &bintree{_0004_pending_stickersUpSql, map[string]*bintree{}},
"0005_waku_mode.down.sql": &bintree{_0005_waku_modeDownSql, map[string]*bintree{}},
"0005_waku_mode.up.sql": &bintree{_0005_waku_modeUpSql, map[string]*bintree{}},
"0006_appearance.up.sql": &bintree{_0006_appearanceUpSql, map[string]*bintree{}},
"0007_enable_waku_default.up.sql": &bintree{_0007_enable_waku_defaultUpSql, map[string]*bintree{}},
"0008_add_push_notifications.up.sql": &bintree{_0008_add_push_notificationsUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},
}}
// RestoreAsset restores an asset under the given directory.

View File

@ -0,0 +1,3 @@
ALTER TABLE settings ADD COLUMN remote_push_notifications_enabled BOOLEAN;
ALTER TABLE settings ADD COLUMN send_push_notifications BOOLEAN;
ALTER TABLE settings ADD COLUMN push_notification_server_enabled BOOLEAN;

View File

@ -38,46 +38,49 @@ type Account struct {
type Settings struct {
// required
Address types.Address `json:"address"`
ChaosMode bool `json:"chaos-mode?,omitempty"`
Currency string `json:"currency,omitempty"`
CurrentNetwork string `json:"networks/current-network"`
CustomBootnodes *json.RawMessage `json:"custom-bootnodes,omitempty"`
CustomBootnodesEnabled *json.RawMessage `json:"custom-bootnodes-enabled?,omitempty"`
DappsAddress types.Address `json:"dapps-address"`
EIP1581Address types.Address `json:"eip1581-address"`
Fleet *string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip?,omitempty"`
InstallationID string `json:"installation-id"`
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
LastUpdated *int64 `json:"last-updated,omitempty"`
LatestDerivedPath uint `json:"latest-derived-path"`
LogLevel *string `json:"log-level,omitempty"`
Mnemonic *string `json:"mnemonic,omitempty"`
Name string `json:"name,omitempty"`
Networks *json.RawMessage `json:"networks/networks"`
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"`
PreferredName *string `json:"preferred-name,omitempty"`
PreviewPrivacy bool `json:"preview-privacy?"`
PublicKey string `json:"public-key"`
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers/packs-installed,omitempty"`
StickerPacksPending *json.RawMessage `json:"stickers/packs-pending,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers/recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network?,omitempty"`
Appearance uint `json:"appearance"`
Usernames *json.RawMessage `json:"usernames,omitempty"`
WalletRootAddress types.Address `json:"wallet-root-address,omitempty"`
WalletSetUpPassed bool `json:"wallet-set-up-passed?,omitempty"`
WalletVisibleTokens *json.RawMessage `json:"wallet/visible-tokens,omitempty"`
WakuEnabled bool `json:"waku-enabled,omitempty"`
WakuBloomFilterMode bool `json:"waku-bloom-filter-mode,omitempty"`
Address types.Address `json:"address"`
ChaosMode bool `json:"chaos-mode?,omitempty"`
Currency string `json:"currency,omitempty"`
CurrentNetwork string `json:"networks/current-network"`
CustomBootnodes *json.RawMessage `json:"custom-bootnodes,omitempty"`
CustomBootnodesEnabled *json.RawMessage `json:"custom-bootnodes-enabled?,omitempty"`
DappsAddress types.Address `json:"dapps-address"`
EIP1581Address types.Address `json:"eip1581-address"`
Fleet *string `json:"fleet,omitempty"`
HideHomeTooltip bool `json:"hide-home-tooltip?,omitempty"`
InstallationID string `json:"installation-id"`
KeyUID string `json:"key-uid"`
KeycardInstanceUID string `json:"keycard-instance-uid,omitempty"`
KeycardPAiredOn int64 `json:"keycard-paired-on,omitempty"`
KeycardPairing string `json:"keycard-pairing,omitempty"`
LastUpdated *int64 `json:"last-updated,omitempty"`
LatestDerivedPath uint `json:"latest-derived-path"`
LogLevel *string `json:"log-level,omitempty"`
Mnemonic *string `json:"mnemonic,omitempty"`
Name string `json:"name,omitempty"`
Networks *json.RawMessage `json:"networks/networks"`
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
PhotoPath string `json:"photo-path"`
PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"`
PreferredName *string `json:"preferred-name,omitempty"`
PreviewPrivacy bool `json:"preview-privacy?"`
PublicKey string `json:"public-key"`
PushNotificationServerEnabled bool `json:"push-notification-server-enabled,omitempty"`
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled,omitempty"`
SigningPhrase string `json:"signing-phrase"`
StickerPacksInstalled *json.RawMessage `json:"stickers/packs-installed,omitempty"`
StickerPacksPending *json.RawMessage `json:"stickers/packs-pending,omitempty"`
StickersRecentStickers *json.RawMessage `json:"stickers/recent-stickers,omitempty"`
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network?,omitempty"`
SendPushNotifications bool `json:"send-push-notifications,omitempty"`
Appearance uint `json:"appearance"`
Usernames *json.RawMessage `json:"usernames,omitempty"`
WalletRootAddress types.Address `json:"wallet-root-address,omitempty"`
WalletSetUpPassed bool `json:"wallet-set-up-passed?,omitempty"`
WalletVisibleTokens *json.RawMessage `json:"wallet/visible-tokens,omitempty"`
WakuEnabled bool `json:"waku-enabled,omitempty"`
WakuBloomFilterMode bool `json:"waku-bloom-filter-mode,omitempty"`
}
func NewDB(db *sql.DB) *Database {
@ -246,6 +249,25 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET remember_syncing_choice = ? WHERE synthetic_id = 'id'")
case "remote-push-notifications-enabled":
_, ok := value.(bool)
if !ok {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET remote_push_notifications_enabled = ? WHERE synthetic_id = 'id'")
case "push-notifications-server-enabled":
_, ok := value.(bool)
if !ok {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET push_notification_server_enabled = ? WHERE synthetic_id = 'id'")
case "send-push-notifications":
_, ok := value.(bool)
if !ok {
return ErrInvalidConfig
}
update, err = db.db.Prepare("UPDATE settings SET send_push_notifications = ? WHERE synthetic_id = 'id'")
case "stickers/packs-installed":
value = &sqlite.JSONBlob{value}
update, err = db.db.Prepare("UPDATE settings SET stickers_packs_installed = ? WHERE synthetic_id = 'id'")

View File

@ -256,15 +256,18 @@ func NewMessenger(
}
pushNotificationClientPersistence := push_notification_client.NewPersistence(database)
// Hardcoding for now
pushNotificationClientConfig := &push_notification_client.Config{
Identity: identity,
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
SendEnabled: true,
Logger: logger,
RemoteNotificationsEnabled: true,
InstallationID: installationID,
pushNotificationClientConfig := c.pushNotificationClientConfig
if pushNotificationClientConfig == nil {
pushNotificationClientConfig = &push_notification_client.Config{}
}
// Overriding until we handle sending/receiving from multiple identities
pushNotificationClientConfig.Identity = identity
// Hardcoding this for now, as it's the only one we support
pushNotificationClientConfig.TokenType = protobuf.PushNotificationRegistration_APN_TOKEN
pushNotificationClientConfig.Logger = logger
pushNotificationClientConfig.InstallationID = installationID
pushNotificationClient := push_notification_client.New(pushNotificationClientPersistence, pushNotificationClientConfig, processor)
handler := newMessageHandler(identity, logger, &sqlitePersistence{db: database})

View File

@ -5,6 +5,7 @@ import (
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/encryption"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/push_notification_client"
"github.com/status-im/status-go/protocol/push_notification_server"
"github.com/status-im/status-go/protocol/transport"
"go.uber.org/zap"
@ -34,6 +35,7 @@ type config struct {
verifyTransactionClient EthClient
pushNotificationServerConfig *push_notification_server.Config
pushNotificationClientConfig *push_notification_client.Config
logger *zap.Logger
}
@ -98,6 +100,13 @@ func WithPushNotificationServerConfig(pushNotificationServerConfig *push_notific
}
}
func WithPushNotificationClientConfig(pushNotificationClientConfig *push_notification_client.Config) Option {
return func(c *config) error {
c.pushNotificationClientConfig = pushNotificationClientConfig
return nil
}
}
func WithDatasync() func(c *config) error {
return func(c *config) error {
c.featureFlags.Datasync = true

View File

@ -338,7 +338,7 @@ func _1593087212_add_mute_chatDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593087212_add_mute_chat.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1593087310, 0)}
info := bindataFileInfo{name: "1593087212_add_mute_chat.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1594393604, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
return a, nil
}
@ -358,7 +358,7 @@ func _1593087212_add_mute_chatUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1593087212_add_mute_chat.up.sql", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1593091669, 0)}
info := bindataFileInfo{name: "1593087212_add_mute_chat.up.sql", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1594393604, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x9, 0xa0, 0x4a, 0x8e, 0x23, 0xe4, 0xce, 0xbc, 0xd4, 0x9, 0xeb, 0xf9, 0x67, 0x90, 0xc0, 0x4b, 0x67, 0x84, 0xe4, 0x42, 0x8d, 0x0, 0x17, 0x29, 0x7f, 0x12, 0xbf, 0x7d, 0x4e, 0x78, 0xec}}
return a, nil
}

View File

@ -33,6 +33,7 @@ import (
coretypes "github.com/status-im/status-go/eth-node/core/types"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/push_notification_client"
"github.com/status-im/status-go/protocol/push_notification_server"
"github.com/status-im/status-go/protocol/transport"
)
@ -145,7 +146,12 @@ func (s *Service) InitProtocol(identity *ecdsa.PrivateKey, db *sql.DB, logger *z
EnvelopeEventsHandler: EnvelopeSignalHandler{},
Logger: logger,
}
options := buildMessengerOptions(s.config, identity, db, envelopesMonitorConfig, logger)
s.accountsDB = accounts.NewDB(db)
options, err := buildMessengerOptions(s.config, identity, db, envelopesMonitorConfig, s.accountsDB, logger)
if err != nil {
return err
}
messenger, err := protocol.NewMessenger(
identity,
@ -156,7 +162,6 @@ func (s *Service) InitProtocol(identity *ecdsa.PrivateKey, db *sql.DB, logger *z
if err != nil {
return err
}
s.accountsDB = accounts.NewDB(db)
s.messenger = messenger
return messenger.Init()
}
@ -446,8 +451,9 @@ func buildMessengerOptions(
identity *ecdsa.PrivateKey,
db *sql.DB,
envelopesMonitorConfig *transport.EnvelopesMonitorConfig,
accountsDB *accounts.Database,
logger *zap.Logger,
) []protocol.Option {
) ([]protocol.Option, error) {
options := []protocol.Option{
protocol.WithCustomLogger(logger),
protocol.WithDatabase(db),
@ -458,14 +464,23 @@ func buildMessengerOptions(
if config.DataSyncEnabled {
options = append(options, protocol.WithDatasync())
}
settings, err := accountsDB.GetSettings()
if err != nil {
return nil, err
}
if config.PushNotificationServerEnabled {
if config.PushNotificationServerEnabled || settings.PushNotificationServerEnabled {
config := &push_notification_server.Config{
Logger: logger,
}
options = append(options, protocol.WithPushNotificationServerConfig(config))
}
options = append(options, protocol.WithPushNotificationClientConfig(&push_notification_client.Config{
SendEnabled: settings.SendPushNotifications,
RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled,
}))
if config.VerifyTransactionURL != "" {
client := &verifyTransactionClient{
url: config.VerifyTransactionURL,
@ -474,5 +489,5 @@ func buildMessengerOptions(
options = append(options, protocol.WithVerifyTransactionClient(client))
}
return options
return options, nil
}