From e0c11ae2619dc52e9f595c644026b51070ae8c1b Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Wed, 15 Jun 2022 18:28:47 +0200 Subject: [PATCH] fix(Privacy): handle sync setting for `profile-pictures-visibility` Part of #5201 --- src/app/modules/main/profile_section/privacy/controller.nim | 4 ++++ .../modules/main/profile_section/privacy/io_interface.nim | 3 +++ src/app/modules/main/profile_section/privacy/module.nim | 3 +++ src/app_service/service/settings/dto/settings.nim | 2 +- src/app_service/service/settings/service.nim | 6 +++++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/modules/main/profile_section/privacy/controller.nim b/src/app/modules/main/profile_section/privacy/controller.nim index 6703499af2..20da36bdd7 100644 --- a/src/app/modules/main/profile_section/privacy/controller.nim +++ b/src/app/modules/main/profile_section/privacy/controller.nim @@ -41,6 +41,10 @@ proc init*(self: Controller) = var args = SettingProfilePictureArgs(e) self.delegate.emitProfilePicturesShowToChanged(args.value) + self.events.on(SIGNAL_SETTING_PROFILE_PICTURES_VISIBILITY_CHANGED) do(e: Args): + var args = SettingProfilePictureArgs(e) + self.delegate.emitProfilePicturesVisibilityChanged(args.value) + proc isMnemonicBackedUp*(self: Controller): bool = return self.privacyService.isMnemonicBackedUp() diff --git a/src/app/modules/main/profile_section/privacy/io_interface.nim b/src/app/modules/main/profile_section/privacy/io_interface.nim index 82ac43ed33..ca39813209 100644 --- a/src/app/modules/main/profile_section/privacy/io_interface.nim +++ b/src/app/modules/main/profile_section/privacy/io_interface.nim @@ -74,3 +74,6 @@ method getPasswordStrengthScore*(self: AccessInterface, password: string): int { method emitProfilePicturesShowToChanged*(self: AccessInterface, value: int) {.base.} = raise newException(ValueError, "No implementation available") +method emitProfilePicturesVisibilityChanged*(self: AccessInterface, value: int) {.base.} = + raise newException(ValueError, "No implementation available") + diff --git a/src/app/modules/main/profile_section/privacy/module.nim b/src/app/modules/main/profile_section/privacy/module.nim index c243ae9c4e..f1ecb2453f 100644 --- a/src/app/modules/main/profile_section/privacy/module.nim +++ b/src/app/modules/main/profile_section/privacy/module.nim @@ -93,6 +93,9 @@ method setProfilePicturesShowTo*(self: Module, value: int) = method emitProfilePicturesShowToChanged*(self: Module, value: int) = self.view.profilePicturesShowToChanged() +method emitProfilePicturesVisibilityChanged*(self: Module, value: int) = + self.view.profilePicturesVisibilityChanged() + method getProfilePicturesVisibility*(self: Module): int = self.controller.getProfilePicturesVisibility() diff --git a/src/app_service/service/settings/dto/settings.nim b/src/app_service/service/settings/dto/settings.nim index 3a4fb3182c..7e2b6a5829 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -180,7 +180,7 @@ proc toSettingsFieldDto*(jsonObj: JsonNode): SettingsFieldDto = field.name = jsonObj["name"].getStr() case field.name: - of KEY_PROFILE_PICTURES_SHOW_TO: + of KEY_PROFILE_PICTURES_SHOW_TO, KEY_PROFILE_PICTURES_VISIBILITY: field.value = jsonObj["value"].getInt().intToStr else: field.value = jsonObj["value"].getStr() diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index b014ab2496..4b474f89ed 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -22,6 +22,7 @@ const DEFAULT_FLEET* = $Fleet.Prod const SIGNAL_CURRENT_USER_STATUS_UPDATED* = "currentUserStatusUpdated" const SIGNAL_SETTING_PROFILE_PICTURES_SHOW_TO_CHANGED* = "profilePicturesShowToChanged" +const SIGNAL_SETTING_PROFILE_PICTURES_VISIBILITY_CHANGED* = "profilePicturesVisibilityChanged" logScope: topics = "settings-service" @@ -35,7 +36,6 @@ type SettingProfilePictureArgs* = ref object of Args value*: int - QtObject: type Service* = ref object of QObject events: EventEmitter @@ -71,6 +71,10 @@ QtObject: self.settings.profilePicturesShowTo = settingsfield.value.parseInt self.events.emit(SIGNAL_SETTING_PROFILE_PICTURES_SHOW_TO_CHANGED, SettingProfilePictureArgs(value: self.settings.profilePicturesShowTo)) + if settingsField.name == KEY_PROFILE_PICTURES_VISIBILITY: + self.settings.profilePicturesVisibility = settingsfield.value.parseInt + self.events.emit(SIGNAL_SETTING_PROFILE_PICTURES_VISIBILITY_CHANGED, SettingProfilePictureArgs(value: self.settings.profilePicturesVisibility)) + proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int): bool = try: let response = status_settings.saveSettings(attribute, value)