From 882c0dcc2b333fcef3d6ff6cff0e332bb537fd4d Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:29:14 +0200 Subject: [PATCH] fix(Privacy): handle sync setting of `show-profile-pictures-to` There are a bunch of settings which are synced an not handled by desktop, one of them being the `profile-pictures-show-to` setting. This commit introduces a new `SettingsFieldDto` so we can react to message signals that include individual setting fields that originate from syncing. The first setting hanlded is the one mentioned above, so a new application signal is introduced to inform the app that there was an update in that particular setting, so it can re-render the view. Partially addresses #5201 --- src/app/core/signals/remote_signals/messages.nim | 6 ++++++ .../main/profile_section/privacy/controller.nim | 4 ++++ .../profile_section/privacy/io_interface.nim | 6 +++++- .../main/profile_section/privacy/module.nim | 3 +++ .../service/settings/dto/settings.nim | 16 ++++++++++++++++ src/app_service/service/settings/service.nim | 15 ++++++++++++++- 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/app/core/signals/remote_signals/messages.nim b/src/app/core/signals/remote_signals/messages.nim index f8e4f01d97..f7c1f2287c 100644 --- a/src/app/core/signals/remote_signals/messages.nim +++ b/src/app/core/signals/remote_signals/messages.nim @@ -9,6 +9,7 @@ import ../../../../app_service/service/community/dto/[community] import ../../../../app_service/service/activity_center/dto/[notification] import ../../../../app_service/service/contacts/dto/[contacts, status_update] import ../../../../app_service/service/devices/dto/[device] +import ../../../../app_service/service/settings/dto/[settings] type MessageSignal* = ref object of Signal bookmarks*: seq[BookmarkDto] @@ -25,6 +26,7 @@ type MessageSignal* = ref object of Signal statusUpdates*: seq[StatusUpdateDto] deletedMessages*: seq[RemovedMessageDto] currentStatus*: seq[StatusUpdateDto] + settings*: seq[SettingsFieldDto] proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal = var signal:MessageSignal = MessageSignal() @@ -91,5 +93,9 @@ proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal = for jsonPinnedMessage in event["event"]["pinMessages"]: signal.pinnedMessages.add(jsonPinnedMessage.toPinnedMessageUpdateDto()) + if event["event"]{"settings"} != nil: + for jsonSettingsField in event["event"]["settings"]: + signal.settings.add(jsonSettingsField.toSettingsFieldDto()) + result = signal diff --git a/src/app/modules/main/profile_section/privacy/controller.nim b/src/app/modules/main/profile_section/privacy/controller.nim index 69aef824da..6703499af2 100644 --- a/src/app/modules/main/profile_section/privacy/controller.nim +++ b/src/app/modules/main/profile_section/privacy/controller.nim @@ -37,6 +37,10 @@ proc init*(self: Controller) = var args = OperationSuccessArgs(e) self.delegate.onPasswordChanged(args.success, args.errorMsg) + self.events.on(SIGNAL_SETTING_PROFILE_PICTURES_SHOW_TO_CHANGED) do(e: Args): + var args = SettingProfilePictureArgs(e) + self.delegate.emitProfilePicturesShowToChanged(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 37afb51a99..82ac43ed33 100644 --- a/src/app/modules/main/profile_section/privacy/io_interface.nim +++ b/src/app/modules/main/profile_section/privacy/io_interface.nim @@ -69,4 +69,8 @@ method setProfilePicturesVisibility*(self: AccessInterface, value: int) {.base.} raise newException(ValueError, "No implementation available") method getPasswordStrengthScore*(self: AccessInterface, password: string): int {.base.} = - raise newException(ValueError, "No implementation available") \ No newline at end of file + raise newException(ValueError, "No implementation available") + +method emitProfilePicturesShowToChanged*(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 4d91b8115a..c243ae9c4e 100644 --- a/src/app/modules/main/profile_section/privacy/module.nim +++ b/src/app/modules/main/profile_section/privacy/module.nim @@ -90,6 +90,9 @@ method setProfilePicturesShowTo*(self: Module, value: int) = if (self.controller.setProfilePicturesShowTo(value)): self.view.profilePicturesShowToChanged() +method emitProfilePicturesShowToChanged*(self: Module, value: int) = + self.view.profilePicturesShowToChanged() + 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 68df3aa930..3a4fb3182c 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -92,6 +92,11 @@ type CurrentUserStatus* = object clock*: int64 text*: string +type + SettingsFieldDto* = object + name*: string + value*: string + type SettingsDto* = object # There is no point to keep all these info as settings, but we must follow status-go response address*: string @@ -170,6 +175,17 @@ proc toCurrentUserStatus*(jsonObj: JsonNode): CurrentUserStatus = discard jsonObj.getProp("clock", result.clock) discard jsonObj.getProp("text", result.text) +proc toSettingsFieldDto*(jsonObj: JsonNode): SettingsFieldDto = + var field = SettingsFieldDto() + field.name = jsonObj["name"].getStr() + + case field.name: + of KEY_PROFILE_PICTURES_SHOW_TO: + field.value = jsonObj["value"].getInt().intToStr + else: + field.value = jsonObj["value"].getStr() + result = field + proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = discard jsonObj.getProp(KEY_ADDRESS, result.address) discard jsonObj.getProp(KEY_CURRENCY, result.currency) diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index c150c10898..b014ab2496 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -21,6 +21,7 @@ const DEFAULT_TELEMETRY_SERVER_URL* = "https://telemetry.status.im" const DEFAULT_FLEET* = $Fleet.Prod const SIGNAL_CURRENT_USER_STATUS_UPDATED* = "currentUserStatusUpdated" +const SIGNAL_SETTING_PROFILE_PICTURES_SHOW_TO_CHANGED* = "profilePicturesShowToChanged" logScope: topics = "settings-service" @@ -30,6 +31,11 @@ type statusType*: StatusType text*: string +type + SettingProfilePictureArgs* = ref object of Args + value*: int + + QtObject: type Service* = ref object of QObject events: EventEmitter @@ -58,6 +64,13 @@ QtObject: var statusUpdate = receivedData.currentStatus[0] self.events.emit(SIGNAL_CURRENT_USER_STATUS_UPDATED, CurrentUserStatusArgs(statusType: statusUpdate.statusType, text: statusUpdate.text)) + if receivedData.settings.len > 0: + for settingsField in receivedData.settings: + + if settingsField.name == KEY_PROFILE_PICTURES_SHOW_TO: + self.settings.profilePicturesShowTo = settingsfield.value.parseInt + self.events.emit(SIGNAL_SETTING_PROFILE_PICTURES_SHOW_TO_CHANGED, SettingProfilePictureArgs(value: self.settings.profilePicturesShowTo)) + proc saveSetting(self: Service, attribute: string, value: string | JsonNode | bool | int): bool = try: let response = status_settings.saveSettings(attribute, value) @@ -848,4 +861,4 @@ QtObject: except Exception as e: let errDesription = e.msg - error "reading exemptions setting error: ", id = id, errDesription \ No newline at end of file + error "reading exemptions setting error: ", id = id, errDesription