-
Notifications
You must be signed in to change notification settings - Fork 249
/
messenger_settings.go
71 lines (57 loc) · 1.76 KB
/
messenger_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
package protocol
import (
"context"
"github.com/status-im/status-go/nodecfg"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/timesource"
)
func (m *Messenger) SetLightClient(request *requests.SetLightClient) error {
return nodecfg.SetLightClient(m.database, request.Enabled)
}
func (m *Messenger) SetLogLevel(request *requests.SetLogLevel) error {
if err := request.Validate(); err != nil {
return err
}
return nodecfg.SetLogLevel(m.database, request.LogLevel)
}
func (m *Messenger) SetCustomNodes(request *requests.SetCustomNodes) error {
return nodecfg.SetWakuV2CustomNodes(m.database, request.CustomNodes)
}
func (m *Messenger) SetCustomizationColor(ctx context.Context, request *requests.SetCustomizationColor) error {
if err := request.Validate(); err != nil {
return err
}
acc, err := m.multiAccounts.GetAccount(request.KeyUID)
if err != nil {
return err
}
acc.CustomizationColor = request.CustomizationColor
//Use a combination of wall clock + lamport timestamp, just like Chat#NextClockAndTimestamp
tNow := timesource.GetCurrentTimeInMillis()
if acc.CustomizationColorClock >= tNow {
acc.CustomizationColorClock++
} else {
acc.CustomizationColorClock = tNow
}
affected, err := m.multiAccounts.UpdateAccountCustomizationColor(request.KeyUID, string(acc.CustomizationColor), acc.CustomizationColorClock)
if err != nil {
return err
}
if affected > 0 {
err = m.syncAccountCustomizationColor(ctx, acc)
if err != nil {
return err
}
}
return nil
}
func (m *Messenger) TogglePeerSyncing(request *requests.TogglePeerSyncingRequest) error {
if err := request.Validate(); err != nil {
return err
}
err := m.settings.SetPeerSyncingEnabled(request.Enabled)
if err != nil {
return err
}
return nil
}