Peer syncing toggle (#4758)

* Peer syncing toggle

* bindata.go
This commit is contained in:
Alexander 2024-03-05 11:44:09 +01:00 committed by GitHub
parent c217692c76
commit 26bc564b38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 575 additions and 345 deletions

View File

@ -67,6 +67,7 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
s.UseMailservers = true
s.PreviewPrivacy = true
s.PeerSyncingEnabled = false
s.Currency = "usd"
s.LinkPreviewRequestEnabled = true

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
ALTER TABLE settings ADD COLUMN peer_syncing_enabled BOOLEAN NOT NULL DEFAULT FALSE;

View File

@ -310,6 +310,7 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
defaultSettings.UseMailservers = true
defaultSettings.PreviewPrivacy = true
defaultSettings.PeerSyncingEnabled = false
defaultSettings.Currency = "usd"
defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone
defaultSettings.LinkPreviewRequestEnabled = true

View File

@ -358,6 +358,7 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
defaultSettings.UseMailservers = true
defaultSettings.PreviewPrivacy = true
defaultSettings.PeerSyncingEnabled = false
defaultSettings.Currency = "usd"
defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone
defaultSettings.LinkPreviewRequestEnabled = true

View File

@ -235,6 +235,7 @@ func defaultSettings(generatedAccountInfo generator.GeneratedAccountInfo, derive
defaultSettings.UseMailservers = true
defaultSettings.PreviewPrivacy = true
defaultSettings.PeerSyncingEnabled = false
defaultSettings.Currency = "usd"
defaultSettings.ProfilePicturesVisibility = settings.ProfilePicturesVisibilityEveryone
defaultSettings.LinkPreviewRequestEnabled = true

View File

@ -506,13 +506,21 @@ var (
dBColumnName: "mnemonic_was_not_shown",
valueHandler: BoolHandler,
}
PeerSyncingEnabled = SettingField{
reactFieldName: "peer-syncing-enabled?",
dBColumnName: "peer_syncing_enabled",
valueHandler: BoolHandler,
}
SettingFieldRegister = []SettingField{
AnonMetricsShouldSend,
Appearance,
AutoMessageEnabled,
BackupEnabled,
BackupFetched,
Bio,
ChaosMode,
CollectibleGroupByCollection,
CollectibleGroupByCommunity,
Currency,
CurrentUserStatus,
CustomBootNodes,
@ -520,14 +528,16 @@ var (
DappsAddress,
DefaultSyncPeriod,
DeviceName,
DisplayAssetsBelowBalance,
DisplayAssetsBelowBalanceThreshold,
DisplayName,
Bio,
EIP1581Address,
Fleet,
GifAPIKey,
GifFavourites,
GifRecents,
HideHomeTooltip,
IsGoerliEnabled,
KeycardInstanceUID,
KeycardPairedOn,
KeycardPairing,
@ -547,10 +557,12 @@ var (
NodeConfig,
NotificationsEnabled,
OpenseaEnabled,
PeerSyncingEnabled,
PhotoPath,
PinnedMailservers,
PreferredName,
PreviewPrivacy,
ProfileMigrationNeeded,
ProfilePicturesShowTo,
ProfilePicturesVisibility,
PublicKey,
@ -561,27 +573,21 @@ var (
RemotePushNotificationsEnabled,
SendPushNotifications,
SendStatusUpdates,
ShowCommunityAssetWhenSendingTokens,
StickersPacksInstalled,
StickersPacksPending,
StickersRecentStickers,
SyncingOnMobileNetwork,
TelemetryServerURL,
TestNetworksEnabled,
TokenGroupByCommunity,
URLUnfurlingMode,
UseMailservers,
WakuBloomFilterMode,
WalletRootAddress,
WalletSetUpPassed,
WalletVisibleTokens,
WebviewAllowPermissionRequests,
ProfileMigrationNeeded,
IsGoerliEnabled,
TokenGroupByCommunity,
ShowCommunityAssetWhenSendingTokens,
DisplayAssetsBelowBalance,
DisplayAssetsBelowBalanceThreshold,
CollectibleGroupByCollection,
CollectibleGroupByCommunity,
URLUnfurlingMode,
}
)

View File

@ -391,7 +391,8 @@ func (db *Database) GetSettings() (Settings, error) {
gif_favorites, opensea_enabled, last_backup, backup_enabled, telemetry_server_url, auto_message_enabled, gif_api_key,
test_networks_enabled, mutual_contact_enabled, profile_migration_needed, is_goerli_enabled, wallet_token_preferences_group_by_community, url_unfurling_mode,
omit_transfers_history_scan, mnemonic_was_not_shown, wallet_show_community_asset_when_sending_tokens, wallet_display_assets_below_balance,
wallet_display_assets_below_balance_threshold, wallet_collectible_preferences_group_by_collection, wallet_collectible_preferences_group_by_community
wallet_display_assets_below_balance_threshold, wallet_collectible_preferences_group_by_collection, wallet_collectible_preferences_group_by_community,
peer_syncing_enabled
FROM
settings
WHERE
@ -475,6 +476,7 @@ func (db *Database) GetSettings() (Settings, error) {
&s.DisplayAssetsBelowBalanceThreshold,
&s.CollectibleGroupByCollection,
&s.CollectibleGroupByCommunity,
&s.PeerSyncingEnabled,
)
return s, err
@ -763,6 +765,18 @@ func (db *Database) GetIsGoerliEnabled() (result bool, err error) {
return result, err
}
func (db *Database) SetPeerSyncingEnabled(value bool) error {
return db.SaveSettingField(PeerSyncingEnabled, value)
}
func (db *Database) GetPeerSyncingEnabled() (result bool, err error) {
err = db.makeSelectRow(PeerSyncingEnabled).Scan(&result)
if err == sql.ErrNoRows {
return result, nil
}
return result, err
}
func (db *Database) GetTokenGroupByCommunity() (result bool, err error) {
err = db.makeSelectRow(TokenGroupByCommunity).Scan(&result)
if err == sql.ErrNoRows {

View File

@ -49,6 +49,7 @@ type DatabaseSettingsManager interface {
SetPinnedMailservers(mailservers map[string]string) error
SetUseMailservers(value bool) error
SetTokenGroupByCommunity(value bool) error
SetPeerSyncingEnabled(value bool) error
CreateSettings(s Settings, n params.NodeConfig) error
SaveSetting(setting string, value interface{}) error
@ -76,4 +77,5 @@ type DatabaseSettingsManager interface {
URLUnfurlingMode() (result int64, err error)
SubscribeToChanges() chan *SyncSettingField
MnemonicWasShown() error
GetPeerSyncingEnabled() (result bool, err error)
}

View File

@ -198,6 +198,20 @@ func (mr *MockDatabaseSettingsManagerMockRecorder) SetUseMailservers(value inter
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUseMailservers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetUseMailservers), value)
}
// SetPeerSyncingEnabled mocks base method.
func (m *MockDatabaseSettingsManager) SetPeerSyncingEnabled(value bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetPeerSyncingEnabled", value)
ret0, _ := ret[0].(error)
return ret0
}
// SetPeerSyncingEnabled indicates an expected call of SetPeerSyncingEnabled.
func (mr *MockDatabaseSettingsManagerMockRecorder) SetPeerSyncingEnabled(value interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPeerSyncingEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetPeerSyncingEnabled), value)
}
// ShouldBroadcastUserStatus mocks base method.
func (m *MockDatabaseSettingsManager) ShouldBroadcastUserStatus() (bool, error) {
m.ctrl.T.Helper()

View File

@ -305,3 +305,18 @@ func (mr *MockDatabaseSettingsManagerMockRecorder) GetRecentStickers() *gomock.C
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecentStickers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetRecentStickers))
}
// GetPeerSyncingEnabled mocks base method.
func (m *MockDatabaseSettingsManager) GetPeerSyncingEnabled() (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPeerSyncingEnabled")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPeerSyncingEnabled indicates an expected call of GetPeerSyncingEnabled.
func (mr *MockDatabaseSettingsManagerMockRecorder) GetPeerSyncingEnabled() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPeerSyncingEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetPeerSyncingEnabled))
}

View File

@ -213,6 +213,7 @@ type Settings struct {
CollectibleGroupByCollection bool `json:"collectible-group-by-collection?,omitempty"`
CollectibleGroupByCommunity bool `json:"collectible-group-by-community?,omitempty"`
URLUnfurlingMode URLUnfurlingModeType `json:"url-unfurling-mode,omitempty"`
PeerSyncingEnabled bool `json:"peer-syncing-enabled?,omitempty"`
}
func (s Settings) MarshalJSON() ([]byte, error) {

View File

@ -341,6 +341,8 @@ func stickersRecentStickersProtobufFactoryStruct(s Settings, clock uint64, chatI
return buildRawStickersRecentStickersSyncMessage(srs, clock, chatID)
}
// Helpers
func assertBytes(value interface{}) ([]byte, error) {
v, ok := value.([]byte)
if !ok {

View File

@ -62,7 +62,15 @@ func (m *Messenger) handleDatasyncMetadata(response *common.HandleMessageRespons
return nil
}
err := m.OnDatasyncOffer(response)
isPeerSyncingEnabled, err := m.settings.GetPeerSyncingEnabled()
if err != nil {
return err
}
if !isPeerSyncingEnabled {
return nil
}
err = m.OnDatasyncOffer(response)
if err != nil {
return err
}
@ -102,6 +110,14 @@ func (m *Messenger) sendDatasyncOffers() error {
return nil
}
isPeerSyncingEnabled, err := m.settings.GetPeerSyncingEnabled()
if err != nil {
return err
}
if !isPeerSyncingEnabled {
return nil
}
communities, err := m.communitiesManager.Joined()
if err != nil {
return err

View File

@ -57,3 +57,15 @@ func (m *Messenger) SetCustomizationColor(ctx context.Context, request *requests
}
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
}

View File

@ -0,0 +1,9 @@
package requests
type TogglePeerSyncingRequest struct {
Enabled bool `json:"enabled"`
}
func (a *TogglePeerSyncingRequest) Validate() error {
return nil
}

View File

@ -1499,6 +1499,10 @@ func (api *PublicAPI) ToggleUseMailservers(value bool) error {
return api.service.messenger.ToggleUseMailservers(value)
}
func (api *PublicAPI) TogglePeerSyncing(request *requests.TogglePeerSyncingRequest) error {
return api.service.messenger.TogglePeerSyncing(request)
}
func (api *PublicAPI) SetPinnedMailservers(pinnedMailservers map[string]string) error {
return api.service.messenger.SetPinnedMailservers(pinnedMailservers)
}