Skip to content

Commit

Permalink
fix(@desktop/sync): settings/bio sync&backup handling
Browse files Browse the repository at this point in the history
Part of #10389 issue.
  • Loading branch information
saledjenic committed May 31, 2023
1 parent c5dc8e7 commit 46d6b16
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/main/profile_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
result.controller = controller.newController(result)
result.moduleLoaded = false

result.profileModule = profile_module.newModule(result, profileService, settingsService)
result.profileModule = profile_module.newModule(result, events, profileService, settingsService)
result.contactsModule = contacts_module.newModule(result, events, contactsService, chatService)
result.languageModule = language_module.newModule(result, events, languageService)
result.privacyModule = privacy_module.newModule(result, events, settingsService, keychainService, privacyService, generalService)
Expand All @@ -108,7 +108,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
result, events, settingsService, ensService, walletAccountService, networkService, tokenService
)
result.communitiesModule = communities_module.newModule(result, communityService)
result.keycardModule = keycard_module.newModule(result, events, keycardService, settingsService, networkService,
result.keycardModule = keycard_module.newModule(result, events, keycardService, settingsService, networkService,
privacyService, accountsService, walletAccountService, keychainService)

result.walletModule = wallet_module.newModule(result, events, walletAccountService, settingsService, networkService)
Expand Down
11 changes: 8 additions & 3 deletions src/app/modules/main/profile_section/profile/controller.nim
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import io_interface

import ../../../../core/eventemitter
import ../../../../../app_service/service/profile/service as profile_service
import ../../../../../app_service/service/settings/service as settings_service
import ../../../../../app_service/common/social_links

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
profileService: profile_service.Service
settingsService: settings_service.Service

proc newController*(delegate: io_interface.AccessInterface,
proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter,
profileService: profile_service.Service, settingsService: settings_service.Service): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.profileService = profileService
result.settingsService = settingsService

proc delete*(self: Controller) =
discard

proc init*(self: Controller) =
discard
self.events.on(SIGNAL_BIO_UPDATED) do(e: Args):
let args = SettingsTextValueArgs(e)
self.delegate.onBioChanged(args.value)

proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int) =
discard self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
Expand All @@ -42,4 +47,4 @@ proc getBio*(self: Controller): string =
self.settingsService.getBio()

proc setBio*(self: Controller, bio: string): bool =
self.settingsService.setBio(bio)
self.settingsService.saveBio(bio)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ method deleteIdentityImage*(self: AccessInterface) {.base.} =
method getBio*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")

method setBio*(self: AccessInterface, bio: string): bool {.base.} =
method setBio*(self: AccessInterface, bio: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onBioChanged*(self: AccessInterface, bio: string) {.base.} =
raise newException(ValueError, "No implementation available")

method setDisplayName*(self: AccessInterface, displayName: string) {.base.} =
Expand Down
12 changes: 8 additions & 4 deletions src/app/modules/main/profile_section/profile/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
import ../../../../global/global_singleton

import ../../../../core/eventemitter
import ../../../../../app_service/service/profile/service as profile_service
import ../../../../../app_service/service/settings/service as settings_service
import ../../../../../app_service/common/social_links
Expand All @@ -24,13 +25,13 @@ type
viewVariant: QVariant
moduleLoaded: bool

proc newModule*(delegate: delegate_interface.AccessInterface,
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter,
profileService: profile_service.Service, settingsService: settings_service.Service): Module =
result = Module()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, profileService, settingsService)
result.controller = controller.newController(result, events, profileService, settingsService)
result.moduleLoaded = false

method delete*(self: Module) =
Expand Down Expand Up @@ -72,8 +73,11 @@ method setDisplayName*(self: Module, displayName: string) =
method getBio(self: Module): string =
self.controller.getBio()

method setBio(self: Module, bio: string): bool =
self.controller.setBio(bio)
method setBio(self: Module, bio: string) =
discard self.controller.setBio(bio)

method onBioChanged*(self: Module, bio: string) =
self.view.emitBioChangedSignal()

method saveSocialLinks*(self: Module): bool =
let socialLinks = map(self.view.temporarySocialLinksModel.items(), x => SocialLink(text: x.text, url: x.url))
Expand Down
12 changes: 6 additions & 6 deletions src/app/modules/main/profile_section/profile/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QtObject:
proc temporarySocialLinksJsonChanged*(self: View) {.signal.}
proc getTemporarySocialLinksJson(self: View): string {.slot.} =
$(%*self.temporarySocialLinksModel.items)


QtProperty[string] socialLinksJson:
read = getSocialLinksJson
Expand Down Expand Up @@ -126,13 +126,13 @@ QtObject:
proc bioChanged*(self: View) {.signal.}
proc getBio(self: View): string {.slot.} =
self.delegate.getBio()

QtProperty[string] bio:
read = getBio
notify = bioChanged

proc setBio(self: View, bio: string): bool {.slot.} =
result = self.delegate.setBio(bio)
if (result):
self.bioChanged()
proc setBio(self: View, bio: string) {.slot.} =
self.delegate.setBio(bio)

proc emitBioChangedSignal*(self: View) =
self.bioChanged()

23 changes: 10 additions & 13 deletions src/app_service/service/settings/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const DEFAULT_FLEET* = $Fleet.StatusProd
# Signals:
const SIGNAL_CURRENCY_UPDATED* = "currencyUpdated"
const SIGNAL_DISPLAY_NAME_UPDATED* = "displayNameUpdated"
const SIGNAL_BIO_UPDATED* = "bioUpdated"
const SIGNAL_CURRENT_USER_STATUS_UPDATED* = "currentUserStatusUpdated"

logScope:
Expand Down Expand Up @@ -94,6 +95,9 @@ QtObject:
if settingsField.name == KEY_DISPLAY_NAME:
self.settings.displayName = settingsField.value
self.events.emit(SIGNAL_DISPLAY_NAME_UPDATED, SettingsTextValueArgs(value: settingsField.value))
if settingsField.name == KEY_BIO:
self.settings.bio = settingsField.value
self.events.emit(SIGNAL_BIO_UPDATED, SettingsTextValueArgs(value: settingsField.value))

self.initialized = true

Expand Down Expand Up @@ -901,19 +905,12 @@ QtObject:
proc getBio*(self: Service): string =
self.settings.bio

proc setBio*(self: Service, bio: string): bool =
result = false
try:
let response = status_settings.setBio(bio)

if(not response.error.isNil):
error "error setting bio", errDescription = response.error.message

self.settings.bio = bio
result = true
except Exception as e:
error "error setting bio", errDesription = e.msg

proc saveBio*(self: Service, value: string): bool =
if(self.saveSetting(KEY_BIO, value)):
self.settings.bio = value
self.events.emit(SIGNAL_BIO_UPDATED, SettingsTextValueArgs(value: self.settings.bio))
return true
return false

proc getSocialLinks*(self: Service): SocialLinks =
return self.socialLinks
Expand Down
3 changes: 0 additions & 3 deletions src/backend/settings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ proc setExemptions*(id: string, muteAllMessages: bool, personalMentions: string,
proc deleteExemptions*(id: string): RpcResponse[JsonNode] {.raises: [Exception].} =
return core.callPrivateRPC("settings_deleteExemptions", %* [id])

proc setBio*(value: string): RpcResponse[JsonNode] {.raises: [Exception].} =
return core.callPrivateRPC("settings_setBio", %* [value])

proc setSocialLinks*(value: JsonNode): RpcResponse[JsonNode] {.raises: [Exception].} =
return core.callPrivateRPC("settings_setSocialLinks", %* [value])

Expand Down

0 comments on commit 46d6b16

Please sign in to comment.