-
Notifications
You must be signed in to change notification settings - Fork 244
/
settings.go
192 lines (149 loc) · 5.57 KB
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package accounts
import (
"context"
"errors"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/nodecfg"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/identity"
)
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 {
messenger **protocol.Messenger
db *accounts.Database
config *params.NodeConfig
}
func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interface{}) error {
// 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
}
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)
}
func (api *SettingsAPI) SetBio(bio string) error {
return (*api.messenger).SetBio(bio)
}
func (api *SettingsAPI) GetSocialLinks() (identity.SocialLinks, error) {
return api.db.GetSocialLinks()
}
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)
}
func (api *SettingsAPI) MnemonicWasShown() error {
return api.db.MnemonicWasShown()
}