2019-08-20 15:38:40 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-05 11:10:26 +00:00
|
|
|
"errors"
|
2019-08-20 15:38:40 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-03-23 18:47:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2022-01-12 20:04:43 +00:00
|
|
|
"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"
|
|
|
|
"github.com/status-im/status-go/protocol/identity"
|
2019-08-20 15:38:40 +00:00
|
|
|
)
|
|
|
|
|
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}
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 09:58:25 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-27 09:58:25 +00:00
|
|
|
return api.db.SaveSetting(typ, val)
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
func (api *SettingsAPI) GetSettings(ctx context.Context) (settings.Settings, error) {
|
2019-12-27 09:58:25 +00:00
|
|
|
return api.db.GetSettings()
|
2019-08-20 15:38:40 +00:00
|
|
|
}
|
2022-01-12 20:04:43 +00:00
|
|
|
|
2022-02-27 14:46:17 +00:00
|
|
|
// NodeConfig returns the currently used node configuration
|
2022-01-12 20:04:43 +00:00
|
|
|
func (api *SettingsAPI) NodeConfig(ctx context.Context) (*params.NodeConfig, error) {
|
2022-02-27 14:46:17 +00:00
|
|
|
return api.config, nil
|
2022-01-12 20:04:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 14:46:17 +00:00
|
|
|
// Saves the nodeconfig in the database. The node must be restarted for the changes to be applied
|
2022-01-12 20:04:43 +00:00
|
|
|
func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, n *params.NodeConfig) error {
|
|
|
|
return nodecfg.SaveNodeConfig(api.db.DB(), n)
|
|
|
|
}
|
2022-05-20 08:59:36 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2022-08-05 11:22:35 +00:00
|
|
|
func (api *SettingsAPI) SetBio(bio string) error {
|
|
|
|
return (*api.messenger).SetBio(bio)
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:56:26 +00:00
|
|
|
func (api *SettingsAPI) GetSocialLinks() (identity.SocialLinks, error) {
|
|
|
|
return api.db.GetSocialLinks()
|
|
|
|
}
|
|
|
|
|
2023-06-05 11:10:26 +00:00
|
|
|
func (api *SettingsAPI) AddOrReplaceSocialLinks(links identity.SocialLinks) error {
|
|
|
|
for _, link := range links {
|
|
|
|
if len(link.Text) == 0 {
|
|
|
|
return errors.New("`Text` field of a social link must be set")
|
|
|
|
}
|
|
|
|
if len(link.URL) == 0 {
|
|
|
|
return errors.New("`URL` field of a social link must be set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*api.messenger).AddOrReplaceSocialLinks(links)
|
2022-08-02 12:56:26 +00:00
|
|
|
}
|