github.com/status-im/status-go@v1.1.0/services/accounts/settings.go (about)

     1  package accounts
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/status-im/status-go/multiaccounts/accounts"
     7  	"github.com/status-im/status-go/multiaccounts/settings"
     8  	"github.com/status-im/status-go/nodecfg"
     9  	"github.com/status-im/status-go/params"
    10  	"github.com/status-im/status-go/protocol"
    11  )
    12  
    13  func NewSettingsAPI(messenger **protocol.Messenger, db *accounts.Database, config *params.NodeConfig) *SettingsAPI {
    14  	return &SettingsAPI{messenger, db, config}
    15  }
    16  
    17  // SettingsAPI is class with methods available over RPC.
    18  type SettingsAPI struct {
    19  	messenger **protocol.Messenger
    20  	db        *accounts.Database
    21  	config    *params.NodeConfig
    22  }
    23  
    24  func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interface{}) error {
    25  	// NOTE(Ferossgp): v0.62.0 Backward compatibility, skip this for older clients instead of returning error
    26  	if typ == "waku-enabled" {
    27  		return nil
    28  	}
    29  
    30  	err := api.db.SaveSetting(typ, val)
    31  	if err != nil {
    32  		return err
    33  	}
    34  
    35  	return nil
    36  }
    37  
    38  func (api *SettingsAPI) GetSettings(ctx context.Context) (settings.Settings, error) {
    39  	return api.db.GetSettings()
    40  }
    41  
    42  // NodeConfig returns the currently used node configuration
    43  func (api *SettingsAPI) NodeConfig(ctx context.Context) (*params.NodeConfig, error) {
    44  	return api.config, nil
    45  }
    46  
    47  // Saves the nodeconfig in the database. The node must be restarted for the changes to be applied
    48  func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, n *params.NodeConfig) error {
    49  	return nodecfg.SaveNodeConfig(api.db.DB(), n)
    50  }
    51  
    52  // Notifications Settings
    53  func (api *SettingsAPI) NotificationsGetAllowNotifications() (bool, error) {
    54  	return api.db.GetAllowNotifications()
    55  }
    56  
    57  func (api *SettingsAPI) NotificationsSetAllowNotifications(value bool) error {
    58  	return api.db.SetAllowNotifications(value)
    59  }
    60  
    61  func (api *SettingsAPI) NotificationsGetOneToOneChats() (string, error) {
    62  	return api.db.GetOneToOneChats()
    63  }
    64  
    65  func (api *SettingsAPI) NotificationsSetOneToOneChats(value string) error {
    66  	return api.db.SetOneToOneChats(value)
    67  }
    68  
    69  func (api *SettingsAPI) NotificationsGetGroupChats() (string, error) {
    70  	return api.db.GetGroupChats()
    71  }
    72  
    73  func (api *SettingsAPI) NotificationsSetGroupChats(value string) error {
    74  	return api.db.SetGroupChats(value)
    75  }
    76  
    77  func (api *SettingsAPI) NotificationsGetPersonalMentions() (string, error) {
    78  	return api.db.GetPersonalMentions()
    79  }
    80  
    81  func (api *SettingsAPI) NotificationsSetPersonalMentions(value string) error {
    82  	return api.db.SetPersonalMentions(value)
    83  }
    84  
    85  func (api *SettingsAPI) NotificationsGetGlobalMentions() (string, error) {
    86  	return api.db.GetGlobalMentions()
    87  }
    88  
    89  func (api *SettingsAPI) NotificationsSetGlobalMentions(value string) error {
    90  	return api.db.SetGlobalMentions(value)
    91  }
    92  
    93  func (api *SettingsAPI) NotificationsGetAllMessages() (string, error) {
    94  	return api.db.GetAllMessages()
    95  }
    96  
    97  func (api *SettingsAPI) NotificationsSetAllMessages(value string) error {
    98  	return api.db.SetAllMessages(value)
    99  }
   100  
   101  func (api *SettingsAPI) NotificationsGetContactRequests() (string, error) {
   102  	return api.db.GetContactRequests()
   103  }
   104  
   105  func (api *SettingsAPI) NotificationsSetContactRequests(value string) error {
   106  	return api.db.SetContactRequests(value)
   107  }
   108  
   109  func (api *SettingsAPI) NotificationsGetIdentityVerificationRequests() (string, error) {
   110  	return api.db.GetIdentityVerificationRequests()
   111  }
   112  
   113  func (api *SettingsAPI) NotificationsSetIdentityVerificationRequests(value string) error {
   114  	return api.db.SetIdentityVerificationRequests(value)
   115  }
   116  
   117  func (api *SettingsAPI) NotificationsGetSoundEnabled() (bool, error) {
   118  	return api.db.GetSoundEnabled()
   119  }
   120  
   121  func (api *SettingsAPI) NotificationsSetSoundEnabled(value bool) error {
   122  	return api.db.SetSoundEnabled(value)
   123  }
   124  
   125  func (api *SettingsAPI) NotificationsGetVolume() (int, error) {
   126  	return api.db.GetVolume()
   127  }
   128  
   129  func (api *SettingsAPI) NotificationsSetVolume(value int) error {
   130  	return api.db.SetVolume(value)
   131  }
   132  
   133  func (api *SettingsAPI) NotificationsGetMessagePreview() (int, error) {
   134  	return api.db.GetMessagePreview()
   135  }
   136  
   137  func (api *SettingsAPI) NotificationsSetMessagePreview(value int) error {
   138  	return api.db.SetMessagePreview(value)
   139  }
   140  
   141  // Notifications Settings - Exemption settings
   142  func (api *SettingsAPI) NotificationsGetExMuteAllMessages(id string) (bool, error) {
   143  	return api.db.GetExMuteAllMessages(id)
   144  }
   145  
   146  func (api *SettingsAPI) NotificationsGetExPersonalMentions(id string) (string, error) {
   147  	return api.db.GetExPersonalMentions(id)
   148  }
   149  
   150  func (api *SettingsAPI) NotificationsGetExGlobalMentions(id string) (string, error) {
   151  	return api.db.GetExGlobalMentions(id)
   152  }
   153  
   154  func (api *SettingsAPI) NotificationsGetExOtherMessages(id string) (string, error) {
   155  	return api.db.GetExOtherMessages(id)
   156  }
   157  
   158  func (api *SettingsAPI) NotificationsSetExemptions(id string, muteAllMessages bool, personalMentions string,
   159  	globalMentions string, otherMessages string) error {
   160  	return api.db.SetExemptions(id, muteAllMessages, personalMentions, globalMentions, otherMessages)
   161  }
   162  
   163  func (api *SettingsAPI) DeleteExemptions(id string) error {
   164  	return api.db.DeleteExemptions(id)
   165  }
   166  
   167  // Deprecated: Use api.go/SetBio instead
   168  func (api *SettingsAPI) SetBio(bio string) error {
   169  	return (*api.messenger).SetBio(bio)
   170  }
   171  
   172  func (api *SettingsAPI) MnemonicWasShown() error {
   173  	return api.db.MnemonicWasShown()
   174  }