fix(@desktop/profile): changing username is not immediately updating
Fixes #5765
This commit is contained in:
parent
04b864ddd2
commit
88bbfef179
|
@ -1,4 +1,4 @@
|
|||
import NimQml
|
||||
import NimQml, chronicles
|
||||
|
||||
import ../../app_service/service/general/service as general_service
|
||||
import ../../app_service/service/keychain/service as keychain_service
|
||||
|
@ -38,6 +38,9 @@ import ../global/global_singleton
|
|||
|
||||
import ../core/[main]
|
||||
|
||||
logScope:
|
||||
topics = "app-controller"
|
||||
|
||||
type
|
||||
AppController* = ref object of RootObj
|
||||
statusFoundation: StatusFoundation
|
||||
|
@ -147,7 +150,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
|||
result.transactionService = transaction_service.newService(statusFoundation.events, statusFoundation.threadpool,
|
||||
result.walletAccountService, result.networkService, result.settingsService, result.tokenService)
|
||||
result.bookmarkService = bookmark_service.newService()
|
||||
result.profileService = profile_service.newService()
|
||||
result.profileService = profile_service.newService(result.contactsService, result.settingsService)
|
||||
result.stickersService = stickers_service.newService(
|
||||
statusFoundation.events,
|
||||
statusFoundation.threadpool,
|
||||
|
@ -353,8 +356,9 @@ proc buildAndRegisterLocalAccountSensitiveSettings(self: AppController) =
|
|||
|
||||
proc buildAndRegisterUserProfile(self: AppController) =
|
||||
let pubKey = self.settingsService.getPublicKey()
|
||||
let alias = self.settingsService.getName()
|
||||
let preferredName = self.settingsService.getPreferredName()
|
||||
let displayName = self.settingsService.getDisplayName()
|
||||
var displayName = self.settingsService.getDisplayName()
|
||||
let ensUsernames = self.settingsService.getEnsUsernames()
|
||||
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
|
||||
let sendUserStatus = self.settingsService.getSendStatusUpdates()
|
||||
|
@ -369,7 +373,12 @@ proc buildAndRegisterUserProfile(self: AppController) =
|
|||
elif(img.imgType == "thumbnail"):
|
||||
thumbnail = img.uri
|
||||
|
||||
singletonInstance.userProfile.setFixedData(loggedInAccount.name, loggedInAccount.keyUid, pubKey)
|
||||
# loggedInAccount.name and displayName must be the same, if not, we are using loggedInAccount.name
|
||||
if (loggedInAccount.name != displayName):
|
||||
info "login account name and display name stored in settings differ"
|
||||
displayName = loggedInAccount.name
|
||||
|
||||
singletonInstance.userProfile.setFixedData(alias, loggedInAccount.keyUid, pubKey)
|
||||
singletonInstance.userProfile.setDisplayName(displayName)
|
||||
singletonInstance.userProfile.setPreferredName(preferredName)
|
||||
singletonInstance.userProfile.setEnsName(firstEnsName)
|
||||
|
|
|
@ -115,6 +115,8 @@ QtObject:
|
|||
notify = nameChanged
|
||||
|
||||
proc setDisplayName*(self: UserProfile, displayName: string) = # Not a slot
|
||||
if(self.displayName == displayName):
|
||||
return
|
||||
self.displayName = displayName
|
||||
self.nameChanged()
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ proc delete*(self: Controller) =
|
|||
proc init*(self: Controller) =
|
||||
discard
|
||||
|
||||
proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] =
|
||||
return self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||
proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int) =
|
||||
self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||
|
||||
proc deleteIdentityImage*(self: Controller, address: string) =
|
||||
self.profileService.deleteIdentityImage(address)
|
||||
|
||||
proc setDisplayName*(self: Controller, displayName: string): bool =
|
||||
proc setDisplayName*(self: Controller, displayName: string) =
|
||||
self.profileService.setDisplayName(displayName)
|
|
@ -50,25 +50,11 @@ method viewDidLoad*(self: Module) =
|
|||
method storeIdentityImage*(self: Module, imageUrl: string, aX: int, aY: int, bX: int, bY: int) =
|
||||
let address = singletonInstance.userProfile.getAddress()
|
||||
let image = singletonInstance.utils.formatImagePath(imageUrl)
|
||||
let storedImages = self.controller.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||
if(storedImages.len == 0):
|
||||
error "error: array of stored images is empty"
|
||||
return
|
||||
|
||||
for img in storedImages:
|
||||
if(img.imgType == "large"):
|
||||
singletonInstance.userProfile.setLargeImage(img.uri)
|
||||
elif(img.imgType == "thumbnail"):
|
||||
singletonInstance.userProfile.setThumbnailImage(img.uri)
|
||||
self.controller.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||
|
||||
method deleteIdentityImage*(self: Module) =
|
||||
let address = singletonInstance.userProfile.getAddress()
|
||||
self.controller.deleteIdentityImage(address)
|
||||
singletonInstance.userProfile.setLargeImage("")
|
||||
singletonInstance.userProfile.setThumbnailImage("")
|
||||
|
||||
method setDisplayName*(self: Module, displayName: string) =
|
||||
if self.controller.setDisplayName(displayName):
|
||||
singletonInstance.userProfile.setDisplayName(displayName)
|
||||
else:
|
||||
error "could not set display name"
|
||||
self.controller.setDisplayName(displayName)
|
||||
|
|
|
@ -228,7 +228,8 @@ QtObject:
|
|||
# If we try to get the contact details of ourselves, just return our own info
|
||||
return ContactsDto(
|
||||
id: singletonInstance.userProfile.getPubKey(),
|
||||
name: singletonInstance.userProfile.getName(),
|
||||
displayName: singletonInstance.userProfile.getDisplayName(),
|
||||
name: singletonInstance.userProfile.getEnsName(),
|
||||
alias: singletonInstance.userProfile.getUsername(),
|
||||
ensVerified: singletonInstance.userProfile.getEnsName().len > 0,
|
||||
added: true,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import json, chronicles
|
||||
|
||||
import ../contacts/service as contact_service
|
||||
import ../settings/service as settings_service
|
||||
import ../../../app/global/global_singleton
|
||||
|
||||
import ../../../backend/accounts as status_accounts
|
||||
|
||||
import ./dto/profile as profile_dto
|
||||
|
@ -11,26 +15,39 @@ logScope:
|
|||
|
||||
type
|
||||
Service* = ref object of RootObj
|
||||
contactService: contact_service.Service
|
||||
settingsService: settings_service.Service
|
||||
|
||||
proc delete*(self: Service) =
|
||||
discard
|
||||
|
||||
proc newService*(): Service =
|
||||
proc newService*(contactService: contact_service.Service, settingsService: settings_service.Service): Service =
|
||||
result = Service()
|
||||
result.contactService = contactService
|
||||
result.settingsService = settingsService
|
||||
|
||||
proc init*(self: Service) =
|
||||
discard
|
||||
|
||||
proc storeIdentityImage*(self: Service, address: string, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] =
|
||||
proc storeIdentityImage*(self: Service, address: string, image: string, aX: int, aY: int, bX: int, bY: int) =
|
||||
try:
|
||||
let response = status_accounts.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||
|
||||
if(not response.error.isNil):
|
||||
error "could not store identity images"
|
||||
return
|
||||
if(response.result.kind != JArray):
|
||||
error "error: ", procName="storeIdentityImage", errDesription = "response is not an array"
|
||||
return
|
||||
if(response.result.len == 0):
|
||||
error "error: array of stored images is empty"
|
||||
return
|
||||
|
||||
for img in response.result:
|
||||
result.add(toImage(img))
|
||||
let imageDto = toImage(img)
|
||||
if(imageDto.imgType == "large"):
|
||||
singletonInstance.userProfile.setLargeImage(imageDto.uri)
|
||||
elif(imageDto.imgType == "thumbnail"):
|
||||
singletonInstance.userProfile.setThumbnailImage(imageDto.uri)
|
||||
|
||||
except Exception as e:
|
||||
error "error: ", procName="storeIdentityImage", errName = e.name, errDesription = e.msg
|
||||
|
@ -38,14 +55,26 @@ proc storeIdentityImage*(self: Service, address: string, image: string, aX: int,
|
|||
proc deleteIdentityImage*(self: Service, address: string) =
|
||||
try:
|
||||
let response = status_accounts.deleteIdentityImage(address)
|
||||
if(not response.error.isNil):
|
||||
error "could not delete identity images"
|
||||
return
|
||||
singletonInstance.userProfile.setLargeImage("")
|
||||
singletonInstance.userProfile.setThumbnailImage("")
|
||||
|
||||
except Exception as e:
|
||||
error "error: ", procName="deleteIdentityImage", errName = e.name, errDesription = e.msg
|
||||
|
||||
proc setDisplayName*(self: Service, displayName: string): bool =
|
||||
proc setDisplayName*(self: Service, displayName: string) =
|
||||
try:
|
||||
discard status_accounts.setDisplayName(displayName)
|
||||
return true
|
||||
let response = status_accounts.setDisplayName(displayName)
|
||||
if(not response.error.isNil):
|
||||
error "could not set display name"
|
||||
return
|
||||
if(not self.settingsService.saveDisplayName(displayName)):
|
||||
error "could save display name to the settings"
|
||||
return
|
||||
|
||||
singletonInstance.userProfile.setDisplayName(displayName)
|
||||
|
||||
except Exception as e:
|
||||
error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg
|
||||
return false
|
||||
error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg
|
|
@ -44,7 +44,7 @@ const KEY_AUTO_MESSAGE_ENABLED* = "auto-message-enabled?"
|
|||
const KEY_GIF_FAVORITES* = "gifs/favorite-gifs"
|
||||
const KEY_GIF_RECENTS* = "gifs/recent-gifs"
|
||||
const KEY_GIF_API_KEY* = "gifs/api-key"
|
||||
const KEY_DISPLAY_NAME = "display-name"
|
||||
const KEY_DISPLAY_NAME* = "display-name"
|
||||
const KEY_TEST_NETWORKS_ENABLED* = "test-networks-enabled?"
|
||||
|
||||
const PROFILE_PICTURES_VISIBILITY_CONTACTS_ONLY* = 1
|
||||
|
|
|
@ -121,6 +121,12 @@ proc getPreferredName*(self: Service): string =
|
|||
proc getDisplayName*(self: Service): string =
|
||||
return self.settings.displayName
|
||||
|
||||
proc saveDisplayName*(self: Service, value: string): bool =
|
||||
if(self.saveSetting(KEY_DISPLAY_NAME, value)):
|
||||
self.settings.displayName = value
|
||||
return true
|
||||
return false
|
||||
|
||||
proc saveNewEnsUsername*(self: Service, username: string): bool =
|
||||
var newEnsUsernames = self.settings.ensUsernames
|
||||
newEnsUsernames.add(username)
|
||||
|
|
Loading…
Reference in New Issue