status-go/services/accounts/settings.go

175 lines
5.1 KiB
Go
Raw Normal View History

package accounts
import (
"context"
"github.com/status-im/status-go/multiaccounts/accounts"
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/nodecfg"
"github.com/status-im/status-go/params"
2022-08-02 12:56:26 +00:00
"github.com/status-im/status-go/protocol"
)
2022-08-02 12:56:26 +00:00
func NewSettingsAPI(messenger **protocol.Messenger, db *accounts.Database, config *params.NodeConfig) *SettingsAPI {
return &SettingsAPI{messenger, db, config}
}
// SettingsAPI is class with methods available over RPC.
type SettingsAPI struct {
2022-08-02 12:56:26 +00:00
messenger **protocol.Messenger
db *accounts.Database
config *params.NodeConfig
}
func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interface{}) error {
2020-09-16 07:31:01 +00:00
// NOTE(Ferossgp): v0.62.0 Backward compatibility, skip this for older clients instead of returning error
if typ == "waku-enabled" {
return nil
}
err := api.db.SaveSetting(typ, val)
if err != nil {
return err
}
return nil
}
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
func (api *SettingsAPI) GetSettings(ctx context.Context) (settings.Settings, error) {
return api.db.GetSettings()
}
// NodeConfig returns the currently used node configuration
func (api *SettingsAPI) NodeConfig(ctx context.Context) (*params.NodeConfig, error) {
return api.config, nil
}
// Saves the nodeconfig in the database. The node must be restarted for the changes to be applied
func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, n *params.NodeConfig) error {
return nodecfg.SaveNodeConfig(api.db.DB(), n)
}
// Notifications Settings
func (api *SettingsAPI) NotificationsGetAllowNotifications() (bool, error) {
return api.db.GetAllowNotifications()
}
func (api *SettingsAPI) NotificationsSetAllowNotifications(value bool) error {
return api.db.SetAllowNotifications(value)
}
func (api *SettingsAPI) NotificationsGetOneToOneChats() (string, error) {
return api.db.GetOneToOneChats()
}
func (api *SettingsAPI) NotificationsSetOneToOneChats(value string) error {
return api.db.SetOneToOneChats(value)
}
func (api *SettingsAPI) NotificationsGetGroupChats() (string, error) {
return api.db.GetGroupChats()
}
func (api *SettingsAPI) NotificationsSetGroupChats(value string) error {
return api.db.SetGroupChats(value)
}
func (api *SettingsAPI) NotificationsGetPersonalMentions() (string, error) {
return api.db.GetPersonalMentions()
}
func (api *SettingsAPI) NotificationsSetPersonalMentions(value string) error {
return api.db.SetPersonalMentions(value)
}
func (api *SettingsAPI) NotificationsGetGlobalMentions() (string, error) {
return api.db.GetGlobalMentions()
}
func (api *SettingsAPI) NotificationsSetGlobalMentions(value string) error {
return api.db.SetGlobalMentions(value)
}
func (api *SettingsAPI) NotificationsGetAllMessages() (string, error) {
return api.db.GetAllMessages()
}
func (api *SettingsAPI) NotificationsSetAllMessages(value string) error {
return api.db.SetAllMessages(value)
}
func (api *SettingsAPI) NotificationsGetContactRequests() (string, error) {
return api.db.GetContactRequests()
}
func (api *SettingsAPI) NotificationsSetContactRequests(value string) error {
return api.db.SetContactRequests(value)
}
func (api *SettingsAPI) NotificationsGetIdentityVerificationRequests() (string, error) {
return api.db.GetIdentityVerificationRequests()
}
func (api *SettingsAPI) NotificationsSetIdentityVerificationRequests(value string) error {
return api.db.SetIdentityVerificationRequests(value)
}
func (api *SettingsAPI) NotificationsGetSoundEnabled() (bool, error) {
return api.db.GetSoundEnabled()
}
func (api *SettingsAPI) NotificationsSetSoundEnabled(value bool) error {
return api.db.SetSoundEnabled(value)
}
func (api *SettingsAPI) NotificationsGetVolume() (int, error) {
return api.db.GetVolume()
}
func (api *SettingsAPI) NotificationsSetVolume(value int) error {
return api.db.SetVolume(value)
}
func (api *SettingsAPI) NotificationsGetMessagePreview() (int, error) {
return api.db.GetMessagePreview()
}
func (api *SettingsAPI) NotificationsSetMessagePreview(value int) error {
return api.db.SetMessagePreview(value)
}
// Notifications Settings - Exemption settings
func (api *SettingsAPI) NotificationsGetExMuteAllMessages(id string) (bool, error) {
return api.db.GetExMuteAllMessages(id)
}
func (api *SettingsAPI) NotificationsGetExPersonalMentions(id string) (string, error) {
return api.db.GetExPersonalMentions(id)
}
func (api *SettingsAPI) NotificationsGetExGlobalMentions(id string) (string, error) {
return api.db.GetExGlobalMentions(id)
}
func (api *SettingsAPI) NotificationsGetExOtherMessages(id string) (string, error) {
return api.db.GetExOtherMessages(id)
}
func (api *SettingsAPI) NotificationsSetExemptions(id string, muteAllMessages bool, personalMentions string,
globalMentions string, otherMessages string) error {
return api.db.SetExemptions(id, muteAllMessages, personalMentions, globalMentions, otherMessages)
}
func (api *SettingsAPI) DeleteExemptions(id string) error {
return api.db.DeleteExemptions(id)
}
2022-08-02 12:56:26 +00:00
2024-02-16 12:57:41 +00:00
// Deprecated: Use api.go/SetBio instead
2022-08-05 11:22:35 +00:00
func (api *SettingsAPI) SetBio(bio string) error {
return (*api.messenger).SetBio(bio)
}
func (api *SettingsAPI) MnemonicWasShown() error {
return api.db.MnemonicWasShown()
}