fix(@desktop/profile): changing username is not immediately updating

Fixes #5765
This commit is contained in:
Sale Djenic 2022-05-19 12:24:53 +02:00 committed by Iuri Matias
parent 04b864ddd2
commit 88bbfef179
8 changed files with 67 additions and 34 deletions

View File

@ -1,4 +1,4 @@
import NimQml import NimQml, chronicles
import ../../app_service/service/general/service as general_service import ../../app_service/service/general/service as general_service
import ../../app_service/service/keychain/service as keychain_service import ../../app_service/service/keychain/service as keychain_service
@ -38,6 +38,9 @@ import ../global/global_singleton
import ../core/[main] import ../core/[main]
logScope:
topics = "app-controller"
type type
AppController* = ref object of RootObj AppController* = ref object of RootObj
statusFoundation: StatusFoundation statusFoundation: StatusFoundation
@ -147,7 +150,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.transactionService = transaction_service.newService(statusFoundation.events, statusFoundation.threadpool, result.transactionService = transaction_service.newService(statusFoundation.events, statusFoundation.threadpool,
result.walletAccountService, result.networkService, result.settingsService, result.tokenService) result.walletAccountService, result.networkService, result.settingsService, result.tokenService)
result.bookmarkService = bookmark_service.newService() result.bookmarkService = bookmark_service.newService()
result.profileService = profile_service.newService() result.profileService = profile_service.newService(result.contactsService, result.settingsService)
result.stickersService = stickers_service.newService( result.stickersService = stickers_service.newService(
statusFoundation.events, statusFoundation.events,
statusFoundation.threadpool, statusFoundation.threadpool,
@ -353,8 +356,9 @@ proc buildAndRegisterLocalAccountSensitiveSettings(self: AppController) =
proc buildAndRegisterUserProfile(self: AppController) = proc buildAndRegisterUserProfile(self: AppController) =
let pubKey = self.settingsService.getPublicKey() let pubKey = self.settingsService.getPublicKey()
let alias = self.settingsService.getName()
let preferredName = self.settingsService.getPreferredName() let preferredName = self.settingsService.getPreferredName()
let displayName = self.settingsService.getDisplayName() var displayName = self.settingsService.getDisplayName()
let ensUsernames = self.settingsService.getEnsUsernames() let ensUsernames = self.settingsService.getEnsUsernames()
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: "" let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
let sendUserStatus = self.settingsService.getSendStatusUpdates() let sendUserStatus = self.settingsService.getSendStatusUpdates()
@ -369,7 +373,12 @@ proc buildAndRegisterUserProfile(self: AppController) =
elif(img.imgType == "thumbnail"): elif(img.imgType == "thumbnail"):
thumbnail = img.uri 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.setDisplayName(displayName)
singletonInstance.userProfile.setPreferredName(preferredName) singletonInstance.userProfile.setPreferredName(preferredName)
singletonInstance.userProfile.setEnsName(firstEnsName) singletonInstance.userProfile.setEnsName(firstEnsName)

View File

@ -115,6 +115,8 @@ QtObject:
notify = nameChanged notify = nameChanged
proc setDisplayName*(self: UserProfile, displayName: string) = # Not a slot proc setDisplayName*(self: UserProfile, displayName: string) = # Not a slot
if(self.displayName == displayName):
return
self.displayName = displayName self.displayName = displayName
self.nameChanged() self.nameChanged()

View File

@ -19,11 +19,11 @@ proc delete*(self: Controller) =
proc init*(self: Controller) = proc init*(self: Controller) =
discard discard
proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] = proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int) =
return self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY) self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
proc deleteIdentityImage*(self: Controller, address: string) = proc deleteIdentityImage*(self: Controller, address: string) =
self.profileService.deleteIdentityImage(address) self.profileService.deleteIdentityImage(address)
proc setDisplayName*(self: Controller, displayName: string): bool = proc setDisplayName*(self: Controller, displayName: string) =
self.profileService.setDisplayName(displayName) self.profileService.setDisplayName(displayName)

View File

@ -50,25 +50,11 @@ method viewDidLoad*(self: Module) =
method storeIdentityImage*(self: Module, imageUrl: string, aX: int, aY: int, bX: int, bY: int) = method storeIdentityImage*(self: Module, imageUrl: string, aX: int, aY: int, bX: int, bY: int) =
let address = singletonInstance.userProfile.getAddress() let address = singletonInstance.userProfile.getAddress()
let image = singletonInstance.utils.formatImagePath(imageUrl) let image = singletonInstance.utils.formatImagePath(imageUrl)
let storedImages = self.controller.storeIdentityImage(address, image, aX, aY, bX, bY) 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)
method deleteIdentityImage*(self: Module) = method deleteIdentityImage*(self: Module) =
let address = singletonInstance.userProfile.getAddress() let address = singletonInstance.userProfile.getAddress()
self.controller.deleteIdentityImage(address) self.controller.deleteIdentityImage(address)
singletonInstance.userProfile.setLargeImage("")
singletonInstance.userProfile.setThumbnailImage("")
method setDisplayName*(self: Module, displayName: string) = method setDisplayName*(self: Module, displayName: string) =
if self.controller.setDisplayName(displayName): self.controller.setDisplayName(displayName)
singletonInstance.userProfile.setDisplayName(displayName)
else:
error "could not set display name"

View File

@ -228,7 +228,8 @@ QtObject:
# If we try to get the contact details of ourselves, just return our own info # If we try to get the contact details of ourselves, just return our own info
return ContactsDto( return ContactsDto(
id: singletonInstance.userProfile.getPubKey(), id: singletonInstance.userProfile.getPubKey(),
name: singletonInstance.userProfile.getName(), displayName: singletonInstance.userProfile.getDisplayName(),
name: singletonInstance.userProfile.getEnsName(),
alias: singletonInstance.userProfile.getUsername(), alias: singletonInstance.userProfile.getUsername(),
ensVerified: singletonInstance.userProfile.getEnsName().len > 0, ensVerified: singletonInstance.userProfile.getEnsName().len > 0,
added: true, added: true,

View File

@ -1,5 +1,9 @@
import json, chronicles 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 ../../../backend/accounts as status_accounts
import ./dto/profile as profile_dto import ./dto/profile as profile_dto
@ -11,26 +15,39 @@ logScope:
type type
Service* = ref object of RootObj Service* = ref object of RootObj
contactService: contact_service.Service
settingsService: settings_service.Service
proc delete*(self: Service) = proc delete*(self: Service) =
discard discard
proc newService*(): Service = proc newService*(contactService: contact_service.Service, settingsService: settings_service.Service): Service =
result = Service() result = Service()
result.contactService = contactService
result.settingsService = settingsService
proc init*(self: Service) = proc init*(self: Service) =
discard 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: try:
let response = status_accounts.storeIdentityImage(address, image, aX, aY, bX, bY) 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): if(response.result.kind != JArray):
error "error: ", procName="storeIdentityImage", errDesription = "response is not an array" error "error: ", procName="storeIdentityImage", errDesription = "response is not an array"
return return
if(response.result.len == 0):
error "error: array of stored images is empty"
return
for img in response.result: 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: except Exception as e:
error "error: ", procName="storeIdentityImage", errName = e.name, errDesription = e.msg 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) = proc deleteIdentityImage*(self: Service, address: string) =
try: try:
let response = status_accounts.deleteIdentityImage(address) 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: except Exception as e:
error "error: ", procName="deleteIdentityImage", errName = e.name, errDesription = e.msg error "error: ", procName="deleteIdentityImage", errName = e.name, errDesription = e.msg
proc setDisplayName*(self: Service, displayName: string): bool = proc setDisplayName*(self: Service, displayName: string) =
try: try:
discard status_accounts.setDisplayName(displayName) let response = status_accounts.setDisplayName(displayName)
return true 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: except Exception as e:
error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg
return false

View File

@ -44,7 +44,7 @@ const KEY_AUTO_MESSAGE_ENABLED* = "auto-message-enabled?"
const KEY_GIF_FAVORITES* = "gifs/favorite-gifs" const KEY_GIF_FAVORITES* = "gifs/favorite-gifs"
const KEY_GIF_RECENTS* = "gifs/recent-gifs" const KEY_GIF_RECENTS* = "gifs/recent-gifs"
const KEY_GIF_API_KEY* = "gifs/api-key" 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 KEY_TEST_NETWORKS_ENABLED* = "test-networks-enabled?"
const PROFILE_PICTURES_VISIBILITY_CONTACTS_ONLY* = 1 const PROFILE_PICTURES_VISIBILITY_CONTACTS_ONLY* = 1

View File

@ -121,6 +121,12 @@ proc getPreferredName*(self: Service): string =
proc getDisplayName*(self: Service): string = proc getDisplayName*(self: Service): string =
return self.settings.displayName 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 = proc saveNewEnsUsername*(self: Service, username: string): bool =
var newEnsUsernames = self.settings.ensUsernames var newEnsUsernames = self.settings.ensUsernames
newEnsUsernames.add(username) newEnsUsernames.add(username)