From 29ade0f817051fe4ba2a6995a8ac20c509877d97 Mon Sep 17 00:00:00 2001 From: Godfrain Jacques Date: Thu, 21 Dec 2023 10:05:30 -0800 Subject: [PATCH] fix (@status-go/stickers) Stickers still show in the recent list after being uninstalled (#4474) fixes #12677 --- multiaccounts/accounts/database.go | 2 +- multiaccounts/settings/database.go | 17 +- .../settings/database_settings_manager.go | 77 +++++ .../database_data_modification_settings.go | 222 +++++++++++++ .../mocks/database_data_retriever_mock.go | 249 ++++++++++++++ .../mocks/database_info_retriever_mock.go | 213 ++++++++++++ .../mocks/database_settings_manager_mock.go | 309 ++++++++++++++++++ protocol/messenger_sync_settings.go | 2 +- services/stickers/recent.go | 38 ++- services/stickers/recent_test.go | 205 ++++++++++++ 10 files changed, 1322 insertions(+), 12 deletions(-) create mode 100644 multiaccounts/settings/database_settings_manager.go create mode 100644 multiaccounts/settings/mocks/database_data_modification_settings.go create mode 100644 multiaccounts/settings/mocks/database_data_retriever_mock.go create mode 100644 multiaccounts/settings/mocks/database_info_retriever_mock.go create mode 100644 multiaccounts/settings/mocks/database_settings_manager_mock.go create mode 100644 services/stickers/recent_test.go diff --git a/multiaccounts/accounts/database.go b/multiaccounts/accounts/database.go index 1a192f771..47ad4f749 100644 --- a/multiaccounts/accounts/database.go +++ b/multiaccounts/accounts/database.go @@ -283,7 +283,7 @@ func (a *Keypair) Operability() AccountOperable { // Database sql wrapper for operations with browser objects. type Database struct { - *settings.Database + settings.DatabaseSettingsManager *notificationssettings.NotificationsSettings *sociallinkssettings.SocialLinksSettings *walletsettings.WalletSettings diff --git a/multiaccounts/settings/database.go b/multiaccounts/settings/database.go index 3fe66ff9c..0a6836bb9 100644 --- a/multiaccounts/settings/database.go +++ b/multiaccounts/settings/database.go @@ -76,7 +76,22 @@ func MakeNewDB(db *sql.DB) (*Database, error) { return dbInstances[filename], nil } -// Set a notifier for setting changes +func (db *Database) GetDB() *sql.DB { + return db.db +} + +func (db *Database) GetSyncQueue() chan SyncSettingField { + return db.SyncQueue +} + +func (db *Database) GetChangesSubscriptions() []chan *SyncSettingField { + return db.changesSubscriptions +} + +func (db *Database) GetNotifier() Notifier { + return db.notifier +} + func (db *Database) SetSettingsNotifier(n Notifier) { db.notifier = n } diff --git a/multiaccounts/settings/database_settings_manager.go b/multiaccounts/settings/database_settings_manager.go new file mode 100644 index 000000000..dc5cd7045 --- /dev/null +++ b/multiaccounts/settings/database_settings_manager.go @@ -0,0 +1,77 @@ +package settings + +import ( + "database/sql" + "encoding/json" + + "github.com/status-im/status-go/eth-node/types" + "github.com/status-im/status-go/params" +) + +type DatabaseSettingsManager interface { + GetDB() *sql.DB + GetSyncQueue() chan SyncSettingField + GetChangesSubscriptions() []chan *SyncSettingField + GetNotifier() Notifier + GetSettingLastSynced(setting SettingField) (result uint64, err error) + GetSettings() (Settings, error) + GetNotificationsEnabled() (result bool, err error) + GetProfilePicturesVisibility() (result int, err error) + GetPublicKey() (string, error) + GetFleet() (string, error) + GetDappsAddress() (rst types.Address, err error) + GetPinnedMailservers() (rst map[string]string, err error) + GetDefaultSyncPeriod() (result uint32, err error) + GetMessagesFromContactsOnly() (result bool, err error) + GetProfilePicturesShowTo() (result int64, err error) + GetLatestDerivedPath() (result uint, err error) + GetCurrentStatus(status interface{}) error + GetMnemonicWasNotShown() (result bool, err error) + GetPreferredUsername() (string, error) + GetCurrency() (string, error) + GetInstalledStickerPacks() (rst *json.RawMessage, err error) + GetPendingStickerPacks() (rst *json.RawMessage, err error) + GetRecentStickers() (rst *json.RawMessage, err error) + GetWalletRootAddress() (rst types.Address, err error) + GetEIP1581Address() (rst types.Address, err error) + GetMasterAddress() (rst types.Address, err error) + GetTestNetworksEnabled() (result bool, err error) + GetIsSepoliaEnabled() (result bool, err error) + GetTokenGroupByCommunity() (result bool, err error) + GetTelemetryServerURL() (string, error) + + SetSettingsNotifier(n Notifier) + SetSettingLastSynced(setting SettingField, clock uint64) error + SetLastBackup(time uint64) error + SetBackupFetched(fetched bool) error + SetPinnedMailservers(mailservers map[string]string) error + SetUseMailservers(value bool) error + SetTokenGroupByCommunity(value bool) error + + CreateSettings(s Settings, n params.NodeConfig) error + SaveSetting(setting string, value interface{}) error + SaveSettingField(sf SettingField, value interface{}) error + DeleteMnemonic() error + SaveSyncSetting(setting SettingField, value interface{}, clock uint64) error + CanUseMailservers() (result bool, err error) + CanSyncOnMobileNetwork() (result bool, err error) + ShouldBroadcastUserStatus() (result bool, err error) + BackupEnabled() (result bool, err error) + AutoMessageEnabled() (result bool, err error) + LastBackup() (result uint64, err error) + BackupFetched() (result bool, err error) + ENSName() (string, error) + DeviceName() (string, error) + DisplayName() (string, error) + Bio() (string, error) + Mnemonic() (string, error) + MnemonicRemoved() (result bool, err error) + GifAPIKey() (string, error) + MutualContactEnabled() (result bool, err error) + GifRecents() (recents json.RawMessage, err error) + GifFavorites() (favorites json.RawMessage, err error) + ProfileMigrationNeeded() (result bool, err error) + URLUnfurlingMode() (result int64, err error) + SubscribeToChanges() chan *SyncSettingField + MnemonicWasShown() error +} diff --git a/multiaccounts/settings/mocks/database_data_modification_settings.go b/multiaccounts/settings/mocks/database_data_modification_settings.go new file mode 100644 index 000000000..300ba253c --- /dev/null +++ b/multiaccounts/settings/mocks/database_data_modification_settings.go @@ -0,0 +1,222 @@ +package mocksettings + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + + settings "github.com/status-im/status-go/multiaccounts/settings" + params "github.com/status-im/status-go/params" +) + +// CreateSettings mocks base method. +func (m *MockDatabaseSettingsManager) CreateSettings(s settings.Settings, n params.NodeConfig) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateSettings", s, n) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateSettings indicates an expected call of CreateSettings. +func (mr *MockDatabaseSettingsManagerMockRecorder) CreateSettings(s, n interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSettings", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).CreateSettings), s, n) +} + +// SaveSetting mocks base method. +func (m *MockDatabaseSettingsManager) SaveSetting(setting string, value interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SaveSetting", setting, value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SaveSetting indicates an expected call of SaveSetting. +func (mr *MockDatabaseSettingsManagerMockRecorder) SaveSetting(setting, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveSetting", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SaveSetting), setting, value) +} + +// SaveSettingField mocks base method. +func (m *MockDatabaseSettingsManager) SaveSettingField(sf settings.SettingField, value interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SaveSettingField", sf, value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SaveSettingField indicates an expected call of SaveSettingField. +func (mr *MockDatabaseSettingsManagerMockRecorder) SaveSettingField(sf, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveSettingField", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SaveSettingField), sf, value) +} + +// DeleteMnemonic mocks base method. +func (m *MockDatabaseSettingsManager) DeleteMnemonic() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteMnemonic") + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteMnemonic indicates an expected call of DeleteMnemonic. +func (mr *MockDatabaseSettingsManagerMockRecorder) DeleteMnemonic() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteMnemonic", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).DeleteMnemonic)) +} + +// SaveSyncSetting mocks base method. +func (m *MockDatabaseSettingsManager) SaveSyncSetting(setting settings.SettingField, value interface{}, clock uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SaveSyncSetting", setting, value, clock) + ret0, _ := ret[0].(error) + return ret0 +} + +// SaveSyncSetting indicates an expected call of SaveSyncSetting. +func (mr *MockDatabaseSettingsManagerMockRecorder) SaveSyncSetting(setting, value, clock interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveSyncSetting", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SaveSyncSetting), setting, value, clock) +} + +// SetSettingLastSynced mocks base method. +func (m *MockDatabaseSettingsManager) SetSettingLastSynced(setting settings.SettingField, clock uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetSettingLastSynced", setting, clock) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetSettingLastSynced indicates an expected call of SetSettingLastSynced. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetSettingLastSynced(setting, clock interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSettingLastSynced", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetSettingLastSynced), setting, clock) +} + +// SetSettingsNotifier mocks base method. +func (m *MockDatabaseSettingsManager) SetSettingsNotifier(n settings.Notifier) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetSettingsNotifier", n) +} + +// SetSettingsNotifier indicates an expected call of SetSettingsNotifier. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetSettingsNotifier(n interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSettingsNotifier", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetSettingsNotifier), n) +} + +// SetLastBackup mocks base method. +func (m *MockDatabaseSettingsManager) SetLastBackup(time uint64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetLastBackup", time) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetLastBackup indicates an expected call of SetLastBackup. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetLastBackup(time interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLastBackup", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetLastBackup), time) +} + +// SetBackupFetched mocks base method. +func (m *MockDatabaseSettingsManager) SetBackupFetched(fetched bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetBackupFetched", fetched) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetBackupFetched indicates an expected call of SetBackupFetched. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetBackupFetched(fetched interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetBackupFetched", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetBackupFetched), fetched) +} + +// SetPinnedMailservers mocks base method. +func (m *MockDatabaseSettingsManager) SetPinnedMailservers(mailservers map[string]string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetPinnedMailservers", mailservers) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetPinnedMailservers indicates an expected call of SetPinnedMailservers. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetPinnedMailservers(mailservers interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPinnedMailservers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetPinnedMailservers), mailservers) +} + +// SetTokenGroupByCommunity mocks base method. +func (m *MockDatabaseSettingsManager) SetTokenGroupByCommunity(value bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetTokenGroupByCommunity", value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetTokenGroupByCommunity indicates an expected call of SetTokenGroupByCommunity. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetTokenGroupByCommunity(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTokenGroupByCommunity", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetTokenGroupByCommunity), value) +} + +// GetTelemetryServerURL mocks base method. +func (m *MockDatabaseSettingsManager) GetTelemetryServerURL() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTelemetryServerURL") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTelemetryServerURL indicates an expected call of GetTelemetryServerURL. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetTelemetryServerURL() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTelemetryServerURL", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetTelemetryServerURL)) +} + +// GetTestNetworksEnabled mocks base method. +func (m *MockDatabaseSettingsManager) GetTestNetworksEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTestNetworksEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTestNetworksEnabled indicates an expected call of GetTestNetworksEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetTestNetworksEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTestNetworksEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetTestNetworksEnabled)) +} + +// GetTokenGroupByCommunity mocks base method. +func (m *MockDatabaseSettingsManager) GetTokenGroupByCommunity() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTokenGroupByCommunity") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTokenGroupByCommunity indicates an expected call of GetTokenGroupByCommunity. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetTokenGroupByCommunity() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenGroupByCommunity", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetTokenGroupByCommunity)) +} + +// URLUnfurlingMode mocks base method. +func (m *MockDatabaseSettingsManager) URLUnfurlingMode() (int64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "URLUnfurlingMode") + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// URLUnfurlingMode indicates an expected call of URLUnfurlingMode. +func (mr *MockDatabaseSettingsManagerMockRecorder) URLUnfurlingMode() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "URLUnfurlingMode", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).URLUnfurlingMode)) +} diff --git a/multiaccounts/settings/mocks/database_data_retriever_mock.go b/multiaccounts/settings/mocks/database_data_retriever_mock.go new file mode 100644 index 000000000..414befc8f --- /dev/null +++ b/multiaccounts/settings/mocks/database_data_retriever_mock.go @@ -0,0 +1,249 @@ +package mocksettings + +import ( + json "encoding/json" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + types "github.com/status-im/status-go/eth-node/types" + settings "github.com/status-im/status-go/multiaccounts/settings" +) + +// GetSettingLastSynced mocks base method. +func (m *MockDatabaseSettingsManager) GetSettingLastSynced(setting settings.SettingField) (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSettingLastSynced", setting) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSettingLastSynced indicates an expected call of GetSettingLastSynced. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetSettingLastSynced(setting interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSettingLastSynced", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetSettingLastSynced), setting) +} + +// GetNotificationsEnabled mocks base method. +func (m *MockDatabaseSettingsManager) GetNotificationsEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNotificationsEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetNotificationsEnabled indicates an expected call of GetNotificationsEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetNotificationsEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNotificationsEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetNotificationsEnabled)) +} + +// GetProfilePicturesVisibility mocks base method. +func (m *MockDatabaseSettingsManager) GetProfilePicturesVisibility() (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetProfilePicturesVisibility") + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetProfilePicturesVisibility indicates an expected call of GetProfilePicturesVisibility. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetProfilePicturesVisibility() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfilePicturesVisibility", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetProfilePicturesVisibility)) +} + +// GetPublicKey mocks base method. +func (m *MockDatabaseSettingsManager) GetPublicKey() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPublicKey") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPublicKey indicates an expected call of GetPublicKey. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetPublicKey() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPublicKey", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetPublicKey)) +} + +// GetFleet mocks base method. +func (m *MockDatabaseSettingsManager) GetFleet() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetFleet") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetFleet indicates an expected call of GetFleet. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetFleet() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFleet", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetFleet)) +} + +// GetDappsAddress mocks base method. +func (m *MockDatabaseSettingsManager) GetDappsAddress() (types.Address, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDappsAddress") + ret0, _ := ret[0].(types.Address) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDappsAddress indicates an expected call of GetDappsAddress. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetDappsAddress() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDappsAddress", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetDappsAddress)) +} + +// GetPinnedMailservers mocks base method. +func (m *MockDatabaseSettingsManager) GetPinnedMailservers() (map[string]string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPinnedMailservers") + ret0, _ := ret[0].(map[string]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPinnedMailservers indicates an expected call of GetPinnedMailservers. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetPinnedMailservers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPinnedMailservers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetPinnedMailservers)) +} + +// GetDefaultSyncPeriod mocks base method. +func (m *MockDatabaseSettingsManager) GetDefaultSyncPeriod() (uint32, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDefaultSyncPeriod") + ret0, _ := ret[0].(uint32) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDefaultSyncPeriod indicates an expected call of GetDefaultSyncPeriod. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetDefaultSyncPeriod() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDefaultSyncPeriod", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetDefaultSyncPeriod)) +} + +// GetMessagesFromContactsOnly mocks base method. +func (m *MockDatabaseSettingsManager) GetMessagesFromContactsOnly() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMessagesFromContactsOnly") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMessagesFromContactsOnly indicates an expected call of GetMessagesFromContactsOnly. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetMessagesFromContactsOnly() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMessagesFromContactsOnly", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetMessagesFromContactsOnly)) +} + +// GetProfilePicturesShowTo mocks base method. +func (m *MockDatabaseSettingsManager) GetProfilePicturesShowTo() (int64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetProfilePicturesShowTo") + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetProfilePicturesShowTo indicates an expected call of GetProfilePicturesShowTo. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetProfilePicturesShowTo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProfilePicturesShowTo", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetProfilePicturesShowTo)) +} + +// GetLatestDerivedPath mocks base method. +func (m *MockDatabaseSettingsManager) GetLatestDerivedPath() (uint, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetLatestDerivedPath") + ret0, _ := ret[0].(uint) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetLatestDerivedPath indicates an expected call of GetLatestDerivedPath. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetLatestDerivedPath() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestDerivedPath", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetLatestDerivedPath)) +} + +// GetCurrentStatus mocks base method. +func (m *MockDatabaseSettingsManager) GetCurrentStatus(status interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCurrentStatus", status) + ret0, _ := ret[0].(error) + return ret0 +} + +// GetCurrentStatus indicates an expected call of GetCurrentStatus. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetCurrentStatus(status interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentStatus", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetCurrentStatus), status) +} + +// GetWalletRootAddress mocks base method. +func (m *MockDatabaseSettingsManager) GetWalletRootAddress() (types.Address, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetWalletRootAddress") + ret0, _ := ret[0].(types.Address) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetWalletRootAddress indicates an expected call of GetWalletRootAddress. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetWalletRootAddress() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWalletRootAddress", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetWalletRootAddress)) +} + +// GifAPIKey mocks base method. +func (m *MockDatabaseSettingsManager) GifAPIKey() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GifAPIKey") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GifAPIKey indicates an expected call of GifAPIKey. +func (mr *MockDatabaseSettingsManagerMockRecorder) GifAPIKey() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GifAPIKey", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GifAPIKey)) +} + +// GifFavorites mocks base method. +func (m *MockDatabaseSettingsManager) GifFavorites() (json.RawMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GifFavorites") + ret0, _ := ret[0].(json.RawMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GifFavorites indicates an expected call of GifFavorites. +func (mr *MockDatabaseSettingsManagerMockRecorder) GifFavorites() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GifFavorites", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GifFavorites)) +} + +// GifRecents mocks base method. +func (m *MockDatabaseSettingsManager) GifRecents() (json.RawMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GifRecents") + ret0, _ := ret[0].(json.RawMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GifRecents indicates an expected call of GifRecents. +func (mr *MockDatabaseSettingsManagerMockRecorder) GifRecents() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GifRecents", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GifRecents)) +} diff --git a/multiaccounts/settings/mocks/database_info_retriever_mock.go b/multiaccounts/settings/mocks/database_info_retriever_mock.go new file mode 100644 index 000000000..e9007b484 --- /dev/null +++ b/multiaccounts/settings/mocks/database_info_retriever_mock.go @@ -0,0 +1,213 @@ +// URLUnfurlingMode mocks base method. +package mocksettings + +import ( + sql "database/sql" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + settings "github.com/status-im/status-go/multiaccounts/settings" +) + +// GetDB mocks base method. +func (m *MockDatabaseSettingsManager) GetDB() *sql.DB { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDB") + ret0, _ := ret[0].(*sql.DB) + return ret0 +} + +// GetDB indicates an expected call of GetDB. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetDB() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDB", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetDB)) +} + +// GetSyncQueue mocks base method. +func (m *MockDatabaseSettingsManager) GetSyncQueue() chan settings.SyncSettingField { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSyncQueue") + ret0, _ := ret[0].(chan settings.SyncSettingField) + return ret0 +} + +// GetSyncQueue indicates an expected call of GetSyncQueue. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetSyncQueue() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSyncQueue", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetSyncQueue)) +} + +// GetChangesSubscriptions mocks base method. +func (m *MockDatabaseSettingsManager) GetChangesSubscriptions() []chan *settings.SyncSettingField { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChangesSubscriptions") + ret0, _ := ret[0].([]chan *settings.SyncSettingField) + return ret0 +} + +// GetChangesSubscriptions indicates an expected call of GetChangesSubscriptions. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetChangesSubscriptions() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChangesSubscriptions", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetChangesSubscriptions)) +} + +// GetNotifier mocks base method. +func (m *MockDatabaseSettingsManager) GetNotifier() settings.Notifier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetNotifier") + ret0, _ := ret[0].(settings.Notifier) + return ret0 +} + +// GetNotifier indicates an expected call of GetNotifier. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetNotifier() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNotifier", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetNotifier)) +} + +// GetSettings mocks base method. +func (m *MockDatabaseSettingsManager) GetSettings() (settings.Settings, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetSettings") + ret0, _ := ret[0].(settings.Settings) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetSettings indicates an expected call of GetSettings. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetSettings() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSettings", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetSettings)) +} + +// SubscribeToChanges mocks base method. +func (m *MockDatabaseSettingsManager) SubscribeToChanges() chan *settings.SyncSettingField { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SubscribeToChanges") + ret0, _ := ret[0].(chan *settings.SyncSettingField) + return ret0 +} + +// SubscribeToChanges indicates an expected call of SubscribeToChanges. +func (mr *MockDatabaseSettingsManagerMockRecorder) SubscribeToChanges() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeToChanges", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SubscribeToChanges)) +} + +// LastBackup mocks base method. +func (m *MockDatabaseSettingsManager) LastBackup() (uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LastBackup") + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LastBackup indicates an expected call of LastBackup. +func (mr *MockDatabaseSettingsManagerMockRecorder) LastBackup() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LastBackup", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).LastBackup)) +} + +// Mnemonic mocks base method. +func (m *MockDatabaseSettingsManager) Mnemonic() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Mnemonic") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Mnemonic indicates an expected call of Mnemonic. +func (mr *MockDatabaseSettingsManagerMockRecorder) Mnemonic() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Mnemonic", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).Mnemonic)) +} + +// MnemonicRemoved mocks base method. +func (m *MockDatabaseSettingsManager) MnemonicRemoved() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MnemonicRemoved") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MnemonicRemoved indicates an expected call of MnemonicRemoved. +func (mr *MockDatabaseSettingsManagerMockRecorder) MnemonicRemoved() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MnemonicRemoved", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).MnemonicRemoved)) +} + +// MnemonicWasShown mocks base method. +func (m *MockDatabaseSettingsManager) MnemonicWasShown() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MnemonicWasShown") + ret0, _ := ret[0].(error) + return ret0 +} + +// MnemonicWasShown indicates an expected call of MnemonicWasShown. +func (mr *MockDatabaseSettingsManagerMockRecorder) MnemonicWasShown() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MnemonicWasShown", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).MnemonicWasShown)) +} + +// MutualContactEnabled mocks base method. +func (m *MockDatabaseSettingsManager) MutualContactEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MutualContactEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MutualContactEnabled indicates an expected call of MutualContactEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) MutualContactEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MutualContactEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).MutualContactEnabled)) +} + +// ProfileMigrationNeeded mocks base method. +func (m *MockDatabaseSettingsManager) ProfileMigrationNeeded() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProfileMigrationNeeded") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProfileMigrationNeeded indicates an expected call of ProfileMigrationNeeded. +func (mr *MockDatabaseSettingsManagerMockRecorder) ProfileMigrationNeeded() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProfileMigrationNeeded", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).ProfileMigrationNeeded)) +} + +// SetUseMailservers mocks base method. +func (m *MockDatabaseSettingsManager) SetUseMailservers(value bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetUseMailservers", value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetUseMailservers indicates an expected call of SetUseMailservers. +func (mr *MockDatabaseSettingsManagerMockRecorder) SetUseMailservers(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUseMailservers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).SetUseMailservers), value) +} + +// ShouldBroadcastUserStatus mocks base method. +func (m *MockDatabaseSettingsManager) ShouldBroadcastUserStatus() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ShouldBroadcastUserStatus") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ShouldBroadcastUserStatus indicates an expected call of ShouldBroadcastUserStatus. +func (mr *MockDatabaseSettingsManagerMockRecorder) ShouldBroadcastUserStatus() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShouldBroadcastUserStatus", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).ShouldBroadcastUserStatus)) +} diff --git a/multiaccounts/settings/mocks/database_settings_manager_mock.go b/multiaccounts/settings/mocks/database_settings_manager_mock.go new file mode 100644 index 000000000..a5c99d3a7 --- /dev/null +++ b/multiaccounts/settings/mocks/database_settings_manager_mock.go @@ -0,0 +1,309 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: database_settings_manager.go + +// Package mock_settings is a generated GoMock package. +package mocksettings + +import ( + json "encoding/json" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + types "github.com/status-im/status-go/eth-node/types" +) + +// MockDatabaseSettingsManager is a mock of DatabaseSettingsManager interface. +type MockDatabaseSettingsManager struct { + ctrl *gomock.Controller + recorder *MockDatabaseSettingsManagerMockRecorder +} + +// MockDatabaseSettingsManagerMockRecorder is the mock recorder for MockDatabaseSettingsManager. +type MockDatabaseSettingsManagerMockRecorder struct { + mock *MockDatabaseSettingsManager +} + +// NewMockDatabaseSettingsManager creates a new mock instance. +func NewMockDatabaseSettingsManager(ctrl *gomock.Controller) *MockDatabaseSettingsManager { + mock := &MockDatabaseSettingsManager{ctrl: ctrl} + mock.recorder = &MockDatabaseSettingsManagerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDatabaseSettingsManager) EXPECT() *MockDatabaseSettingsManagerMockRecorder { + return m.recorder +} + +// AutoMessageEnabled mocks base method. +func (m *MockDatabaseSettingsManager) AutoMessageEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AutoMessageEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AutoMessageEnabled indicates an expected call of AutoMessageEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) AutoMessageEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AutoMessageEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).AutoMessageEnabled)) +} + +// BackupEnabled mocks base method. +func (m *MockDatabaseSettingsManager) BackupEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BackupEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BackupEnabled indicates an expected call of BackupEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) BackupEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BackupEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).BackupEnabled)) +} + +// BackupFetched mocks base method. +func (m *MockDatabaseSettingsManager) BackupFetched() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BackupFetched") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BackupFetched indicates an expected call of BackupFetched. +func (mr *MockDatabaseSettingsManagerMockRecorder) BackupFetched() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BackupFetched", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).BackupFetched)) +} + +// Bio mocks base method. +func (m *MockDatabaseSettingsManager) Bio() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Bio") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Bio indicates an expected call of Bio. +func (mr *MockDatabaseSettingsManagerMockRecorder) Bio() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bio", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).Bio)) +} + +// CanSyncOnMobileNetwork mocks base method. +func (m *MockDatabaseSettingsManager) CanSyncOnMobileNetwork() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CanSyncOnMobileNetwork") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CanSyncOnMobileNetwork indicates an expected call of CanSyncOnMobileNetwork. +func (mr *MockDatabaseSettingsManagerMockRecorder) CanSyncOnMobileNetwork() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanSyncOnMobileNetwork", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).CanSyncOnMobileNetwork)) +} + +// CanUseMailservers mocks base method. +func (m *MockDatabaseSettingsManager) CanUseMailservers() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CanUseMailservers") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CanUseMailservers indicates an expected call of CanUseMailservers. +func (mr *MockDatabaseSettingsManagerMockRecorder) CanUseMailservers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanUseMailservers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).CanUseMailservers)) +} + + + +// DeviceName mocks base method. +func (m *MockDatabaseSettingsManager) DeviceName() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeviceName") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeviceName indicates an expected call of DeviceName. +func (mr *MockDatabaseSettingsManagerMockRecorder) DeviceName() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeviceName", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).DeviceName)) +} + +// DisplayName mocks base method. +func (m *MockDatabaseSettingsManager) DisplayName() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DisplayName") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DisplayName indicates an expected call of DisplayName. +func (mr *MockDatabaseSettingsManagerMockRecorder) DisplayName() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisplayName", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).DisplayName)) +} + +// ENSName mocks base method. +func (m *MockDatabaseSettingsManager) ENSName() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ENSName") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ENSName indicates an expected call of ENSName. +func (mr *MockDatabaseSettingsManagerMockRecorder) ENSName() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ENSName", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).ENSName)) +} + +// GetCurrency mocks base method. +func (m *MockDatabaseSettingsManager) GetCurrency() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCurrency") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCurrency indicates an expected call of GetCurrency. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetCurrency() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrency", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetCurrency)) +} + +// GetEIP1581Address mocks base method. +func (m *MockDatabaseSettingsManager) GetEIP1581Address() (types.Address, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetEIP1581Address") + ret0, _ := ret[0].(types.Address) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEIP1581Address indicates an expected call of GetEIP1581Address. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetEIP1581Address() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEIP1581Address", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetEIP1581Address)) +} + + +// GetInstalledStickerPacks mocks base method. +func (m *MockDatabaseSettingsManager) GetInstalledStickerPacks() (*json.RawMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetInstalledStickerPacks") + ret0, _ := ret[0].(*json.RawMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetInstalledStickerPacks indicates an expected call of GetInstalledStickerPacks. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetInstalledStickerPacks() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInstalledStickerPacks", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetInstalledStickerPacks)) +} + +// GetIsSepoliaEnabled mocks base method. +func (m *MockDatabaseSettingsManager) GetIsSepoliaEnabled() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetIsSepoliaEnabled") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetIsSepoliaEnabled indicates an expected call of GetIsSepoliaEnabled. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetIsSepoliaEnabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIsSepoliaEnabled", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetIsSepoliaEnabled)) +} + +// GetMasterAddress mocks base method. +func (m *MockDatabaseSettingsManager) GetMasterAddress() (types.Address, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMasterAddress") + ret0, _ := ret[0].(types.Address) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMasterAddress indicates an expected call of GetMasterAddress. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetMasterAddress() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMasterAddress", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetMasterAddress)) +} + +// GetMnemonicWasNotShown mocks base method. +func (m *MockDatabaseSettingsManager) GetMnemonicWasNotShown() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMnemonicWasNotShown") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetMnemonicWasNotShown indicates an expected call of GetMnemonicWasNotShown. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetMnemonicWasNotShown() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMnemonicWasNotShown", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetMnemonicWasNotShown)) +} + +// GetPendingStickerPacks mocks base method. +func (m *MockDatabaseSettingsManager) GetPendingStickerPacks() (*json.RawMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPendingStickerPacks") + ret0, _ := ret[0].(*json.RawMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPendingStickerPacks indicates an expected call of GetPendingStickerPacks. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetPendingStickerPacks() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPendingStickerPacks", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetPendingStickerPacks)) +} + +// GetPreferredUsername mocks base method. +func (m *MockDatabaseSettingsManager) GetPreferredUsername() (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetPreferredUsername") + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetPreferredUsername indicates an expected call of GetPreferredUsername. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetPreferredUsername() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPreferredUsername", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetPreferredUsername)) +} + +// GetRecentStickers mocks base method. +func (m *MockDatabaseSettingsManager) GetRecentStickers() (*json.RawMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRecentStickers") + ret0, _ := ret[0].(*json.RawMessage) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRecentStickers indicates an expected call of GetRecentStickers. +func (mr *MockDatabaseSettingsManagerMockRecorder) GetRecentStickers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecentStickers", reflect.TypeOf((*MockDatabaseSettingsManager)(nil).GetRecentStickers)) +} \ No newline at end of file diff --git a/protocol/messenger_sync_settings.go b/protocol/messenger_sync_settings.go index fa69ae650..f44d83d2b 100644 --- a/protocol/messenger_sync_settings.go +++ b/protocol/messenger_sync_settings.go @@ -127,7 +127,7 @@ func (m *Messenger) startSyncSettingsLoop() { for { select { - case s := <-m.settings.SyncQueue: + case s := <-m.settings.GetSyncQueue(): if s.CanSync(settings.FromInterface) { logger.Debug("setting for sync received from settings.SyncQueue") diff --git a/services/stickers/recent.go b/services/stickers/recent.go index 745049221..8748c9011 100644 --- a/services/stickers/recent.go +++ b/services/stickers/recent.go @@ -10,23 +10,43 @@ import ( const maxNumberRecentStickers = 24 func (api *API) recentStickers() ([]Sticker, error) { - recentStickersList := make([]Sticker, 0) + installedStickersPacksJSON, err := api.accountsDB.GetInstalledStickerPacks() + + if err != nil || installedStickersPacksJSON == nil { + return []Sticker{}, nil + } recentStickersJSON, err := api.accountsDB.GetRecentStickers() - if err != nil { - return recentStickersList, err + + if err != nil || recentStickersJSON == nil { + return []Sticker{}, nil } - if recentStickersJSON == nil { - return recentStickersList, nil + recentStickersList := make([]Sticker, 0) + if err := json.Unmarshal(*recentStickersJSON, &recentStickersList); err != nil { + return []Sticker{}, err } - err = json.Unmarshal(*recentStickersJSON, &recentStickersList) - if err != nil { - return recentStickersList, err + var installedStickersPacks map[string]StickerPack + if err := json.Unmarshal(*installedStickersPacksJSON, &installedStickersPacks); err != nil { + return []Sticker{}, err } - return recentStickersList, nil + recentStickersListInExistingPacks := make([]Sticker, 0) + existingPackIDs := make(map[string]bool) + + for k := range installedStickersPacks { + existingPackIDs[k] = true + } + + for _, s := range recentStickersList { + packIDStr := s.PackID.String() + if _, exists := existingPackIDs[packIDStr]; exists { + recentStickersListInExistingPacks = append(recentStickersListInExistingPacks, s) + } + } + + return recentStickersListInExistingPacks, nil } func (api *API) ClearRecent() error { diff --git a/services/stickers/recent_test.go b/services/stickers/recent_test.go new file mode 100644 index 000000000..597ad78d9 --- /dev/null +++ b/services/stickers/recent_test.go @@ -0,0 +1,205 @@ +package stickers + +import ( + "context" + "encoding/json" + "math/big" + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/status-im/status-go/multiaccounts/accounts" + mock_settings "github.com/status-im/status-go/multiaccounts/settings/mocks" + "github.com/status-im/status-go/services/wallet/bigint" +) + +func SetupAPI(t *testing.T) (*API, *mock_settings.MockDatabaseSettingsManager) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + mockDB := mock_settings.NewMockDatabaseSettingsManager(ctrl) + + require.NotNil(t, mockDB) + + accountDatabase := &accounts.Database{ + DatabaseSettingsManager: mockDB, + } + + api := NewAPI(context.Background(), accountDatabase, nil, nil, nil, "test-store-dir", nil, nil) + require.NotNil(t, api) + + return api, mockDB +} + +func Test_WHEN_EmptyRecentStickers_And_EmptyStickerPacks_THEN_EmptyStickers_Returned(t *testing.T) { + + api, mockDB := SetupAPI(t) + + mockDB.EXPECT().GetInstalledStickerPacks().Return(nil, nil) + + actual, err := api.recentStickers() + + assert.NoError(t, err) + assert.Equal(t, []Sticker{}, actual) +} + +func Test_WHEN_EmptyStickerPacks_THEN_EmptyStickers_Returned(t *testing.T) { + expectedStickers := []Sticker{ + { + PackID: &bigint.BigInt{Int: big.NewInt(1)}, + URL: "sticker1", + Hash: "0x1", + }, + { + PackID: &bigint.BigInt{Int: big.NewInt(2)}, + URL: "sticker2", + Hash: "0x2", + }, + } + + expectedStickerPacks := map[string]StickerPack{} + + api, mockDB := SetupAPI(t) + + expectedStickersJSON, err := json.Marshal(expectedStickers) + require.NoError(t, err) + + expectedStickerPacksJSON, err := json.Marshal(expectedStickerPacks) + require.NoError(t, err) + + mockDB.EXPECT().GetInstalledStickerPacks().Return((*json.RawMessage)(&expectedStickerPacksJSON), nil) + mockDB.EXPECT().GetRecentStickers().Return((*json.RawMessage)(&expectedStickersJSON), nil) + + actual, err := api.recentStickers() + + require.NoError(t, err) + require.Equal(t, 0, len(actual)) + require.Equal(t, []Sticker{}, actual) +} + +func Test_WHEN_Stickers_In_Existing_SingleStickerPack_THEN_Stickers_Returned(t *testing.T) { + expectedStickers := []Sticker{ + { + PackID: &bigint.BigInt{Int: big.NewInt(1)}, + URL: "sticker1", + Hash: "0x1", + }, + { + PackID: &bigint.BigInt{Int: big.NewInt(2)}, + URL: "sticker2", + Hash: "0x2", + }, + } + + expectedStickerPacks := map[string]StickerPack{ + "1": { + ID: &bigint.BigInt{Int: big.NewInt(1)}, + Name: "test", + Author: "test", + Owner: [20]byte{}, + Price: &bigint.BigInt{Int: big.NewInt(10)}, + Preview: "", + Thumbnail: "", + Stickers: expectedStickers, + Status: 1, + }, + "2": { + ID: &bigint.BigInt{Int: big.NewInt(2)}, + Name: "test", + Author: "test", + Owner: [20]byte{}, + Price: &bigint.BigInt{Int: big.NewInt(10)}, + Preview: "", + Thumbnail: "", + Stickers: expectedStickers, + Status: 1, + }, + } + + api, mockDB := SetupAPI(t) + + expectedStickersJSON, err := json.Marshal(expectedStickers) + require.NoError(t, err) + + expectedStickerPacksJSON, err := json.Marshal(expectedStickerPacks) + require.NoError(t, err) + + mockDB.EXPECT().GetInstalledStickerPacks().Return((*json.RawMessage)(&expectedStickerPacksJSON), nil) + mockDB.EXPECT().GetRecentStickers().Return((*json.RawMessage)(&expectedStickersJSON), nil) + + actual, err := api.recentStickers() + + require.NoError(t, err) + require.Equal(t, 2, len(actual)) + require.Equal(t, expectedStickers, actual) +} + +func Test_WHEN_Stickers_In_Existing_In_MultipleStickerPacks_THEN_Stickers_Returned(t *testing.T) { + expectedStickers := []Sticker{ + { + PackID: &bigint.BigInt{Int: big.NewInt(1)}, + URL: "sticker1", + Hash: "0x1", + }, + { + PackID: &bigint.BigInt{Int: big.NewInt(2)}, + URL: "sticker2", + Hash: "0x2", + }, + } + + expectedStickerPacks := map[string]StickerPack{ + "1": { + ID: &bigint.BigInt{Int: big.NewInt(1)}, + Name: "test", + Author: "test", + Owner: [20]byte{}, + Price: &bigint.BigInt{Int: big.NewInt(10)}, + Preview: "", + Thumbnail: "", + Stickers: expectedStickers, + Status: 1, + }, + "2": { + ID: &bigint.BigInt{Int: big.NewInt(2)}, + Name: "test", + Author: "test", + Owner: [20]byte{}, + Price: &bigint.BigInt{Int: big.NewInt(10)}, + Preview: "", + Thumbnail: "", + Stickers: expectedStickers, + Status: 1, + }, + "3": { + ID: &bigint.BigInt{Int: big.NewInt(3)}, + Name: "test", + Author: "test", + Owner: [20]byte{}, + Price: &bigint.BigInt{Int: big.NewInt(10)}, + Preview: "", + Thumbnail: "", + Stickers: expectedStickers, + Status: 1, + }, + } + + api, mockDB := SetupAPI(t) + + expectedStickersJSON, err := json.Marshal(expectedStickers) + require.NoError(t, err) + + expectedStickerPacksJSON, err := json.Marshal(expectedStickerPacks) + require.NoError(t, err) + + mockDB.EXPECT().GetInstalledStickerPacks().Return((*json.RawMessage)(&expectedStickerPacksJSON), nil) + mockDB.EXPECT().GetRecentStickers().Return((*json.RawMessage)(&expectedStickersJSON), nil) + + actual, err := api.recentStickers() + + require.NoError(t, err) + require.Equal(t, 2, len(actual)) + require.Equal(t, expectedStickers, actual) +}