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
This commit is contained in:
Pascal Precht 2022-06-15 17:29:14 +02:00 committed by r4bbit.eth
parent 858caeca73
commit 882c0dcc2b
6 changed files with 48 additions and 2 deletions

View File

@ -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

View File

@ -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()

View File

@ -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")
raise newException(ValueError, "No implementation available")
method emitProfilePicturesShowToChanged*(self: AccessInterface, value: int) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -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()

View File

@ -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)

View File

@ -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
error "reading exemptions setting error: ", id = id, errDesription