2023-11-27 11:08:17 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2024-02-07 15:20:54 +00:00
|
|
|
"context"
|
|
|
|
|
2023-11-27 11:08:17 +00:00
|
|
|
"github.com/status-im/status-go/nodecfg"
|
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2024-02-07 15:20:54 +00:00
|
|
|
"github.com/status-im/status-go/timesource"
|
2023-11-27 11:08:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (m *Messenger) SetLightClient(request *requests.SetLightClient) error {
|
|
|
|
return nodecfg.SetLightClient(m.database, request.Enabled)
|
|
|
|
}
|
2023-11-27 12:38:45 +00:00
|
|
|
|
|
|
|
func (m *Messenger) SetLogLevel(request *requests.SetLogLevel) error {
|
|
|
|
if err := request.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodecfg.SetLogLevel(m.database, request.LogLevel)
|
|
|
|
}
|
|
|
|
|
2024-05-24 10:54:12 +00:00
|
|
|
func (m *Messenger) SetMaxLogBackups(request *requests.SetMaxLogBackups) error {
|
|
|
|
return nodecfg.SetMaxLogBackups(m.database, request.MaxLogBackups)
|
|
|
|
}
|
|
|
|
|
2023-11-27 12:38:45 +00:00
|
|
|
func (m *Messenger) SetCustomNodes(request *requests.SetCustomNodes) error {
|
|
|
|
return nodecfg.SetWakuV2CustomNodes(m.database, request.CustomNodes)
|
|
|
|
}
|
2024-02-07 15:20:54 +00:00
|
|
|
|
2024-05-24 10:54:12 +00:00
|
|
|
func (m *Messenger) SaveNewWakuNode(request *requests.SaveNewWakuNode) error {
|
|
|
|
if err := request.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nodecfg.SaveNewWakuNode(m.database, request.NodeAddress)
|
|
|
|
}
|
|
|
|
|
2024-02-07 15:20:54 +00:00
|
|
|
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
|
|
|
|
|
2024-04-03 14:49:57 +00:00
|
|
|
if m.account != nil {
|
|
|
|
m.account.CustomizationColor = request.CustomizationColor
|
|
|
|
}
|
|
|
|
|
2024-02-07 15:20:54 +00:00
|
|
|
//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
|
|
|
|
}
|
2024-04-03 14:49:57 +00:00
|
|
|
|
|
|
|
err = m.resetLastPublishedTimeForChatIdentity()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.publishContactCode()
|
2024-02-07 15:20:54 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-03-05 10:44:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|