fix(profile): fix profile pic change and move it to new architecture

Fixes #3997
This commit is contained in:
Jonathan Rainville 2021-11-02 15:00:47 -04:00 committed by Iuri Matias
parent 816f737d55
commit cd428678f7
10 changed files with 81 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import ../../../../../app_service/service/accounts/service as accounts_service
import ../../../../../app_service/service/settings/service as settings_service import ../../../../../app_service/service/settings/service as settings_service
import ./item as item import ./item as item
import status/types/identity_image
export controller_interface export controller_interface
@ -59,3 +60,9 @@ method getProfile*[T](self: Controller[T]): item.Item =
) )
return item return item
method storeIdentityImage*[T](self: Controller[T], address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage =
self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
method deleteIdentityImage*[T](self: Controller[T], address: string): string =
self.profileService.deleteIdentityImage(address)

View File

@ -1,5 +1,6 @@
import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/profile/service as profile_service
import ./item import ./item
import status/types/identity_image
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
@ -14,6 +15,12 @@ method init*(self: AccessInterface) {.base.} =
method getProfile*(self: AccessInterface): Item {.base.} = method getProfile*(self: AccessInterface): Item {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method storeIdentityImage*(self: AccessInterface, address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage {.base.} =
raise newException(ValueError, "No implementation available")
method deleteIdentityImage*(self: AccessInterface, address: string): string {.base.} =
raise newException(ValueError, "No implementation available")
type type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.

View File

@ -1,3 +1,5 @@
import status/types/identity_image
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module. ## Abstract class for any input/interaction with this module.
@ -11,6 +13,12 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method storeIdentityImage*(self: AccessInterface, address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage {.base.} =
raise newException(ValueError, "No implementation available")
method deleteIdentityImage*(self: AccessInterface, address: string): string {.base.} =
raise newException(ValueError, "No implementation available")
type type
## Abstract class (concept) which must be implemented by object/s used in this ## Abstract class (concept) which must be implemented by object/s used in this
## module. ## module.

View File

@ -136,7 +136,6 @@ QtObject:
proc hasIdentityImage*(self: Model): bool {.slot.} = proc hasIdentityImage*(self: Model): bool {.slot.} =
result = (?.self.identityImage.thumbnail != "") result = (?.self.identityImage.thumbnail != "")
result = false
QtProperty[bool] hasIdentityImage: QtProperty[bool] hasIdentityImage:
read = hasIdentityImage read = hasIdentityImage

View File

@ -7,6 +7,8 @@ import ../../../../../app_service/service/profile/service as profile_service
import ../../../../../app_service/service/accounts/service as accounts_service import ../../../../../app_service/service/accounts/service as accounts_service
import ../../../../../app_service/service/settings/service as settings_service import ../../../../../app_service/service/settings/service as settings_service
import status/types/identity_image
export io_interface export io_interface
type type
@ -21,7 +23,7 @@ proc newModule*[T](delegate: T, accountsService: accounts_service.ServiceInterfa
result = Module[T]() result = Module[T]()
result.delegate = delegate result.delegate = delegate
result.view = newView(result) result.view = newView(result)
result.viewVariant = result.view.getModel result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, accountsService, settingsService, profileService) result.controller = controller.newController[Module[T]](result, accountsService, settingsService, profileService)
result.moduleLoaded = false result.moduleLoaded = false
@ -37,3 +39,9 @@ method load*[T](self: Module[T]) =
method isLoaded*[T](self: Module[T]): bool = method isLoaded*[T](self: Module[T]): bool =
return self.moduleLoaded return self.moduleLoaded
method storeIdentityImage*[T](self: Module[T], address: string, image: string, aX: int, aY: int, bX: int, bY: int): identity_image.IdentityImage =
self.controller.storeIdentityImage(address, image, aX, aY, bX, bY)
method deleteIdentityImage*[T](self: Module[T], address: string): string =
self.controller.deleteIdentityImage(address)

View File

@ -3,6 +3,9 @@ import NimQml
import ./item import ./item
import ./model import ./model
import ./io_interface import ./io_interface
import status/profile as status_profile
import status/status
import ../../../../utils/image_utils
import status/types/[identity_image, profile] import status/types/[identity_image, profile]
@ -37,3 +40,29 @@ QtObject:
proc setProfile*(self: View, profile: Item) = proc setProfile*(self: View, profile: Item) =
self.model.setProfile(profile) self.model.setProfile(profile)
self.modelChanged() self.modelChanged()
proc upload*(self: View, imageUrl: string, aX: int, aY: int, bX: int, bY: int): string {.slot.} =
var image = image_utils.formatImagePath(imageUrl)
# FIXME the function to get the file size is messed up
# var size = image_getFileSize(image)
# TODO find a way to i18n this (maybe send just a code and then QML sets the right string)
# return "Max file size is 20MB"
try:
# TODO add crop tool for the image
let identityImage = self.delegate.storeIdentityImage(self.model.address, image, aX, aY, bX, bY)
# TODO use only one type
let identityImageConverted = item.IdentityImage(
thumbnail: identityImage.thumbnail,
large: identityImage.thumbnail
)
self.model.setIdentityImage(identityImageConverted)
result = ""
except Exception as e:
echo "Error storing identity image", e.msg
result = "Error storing identity image: " & e.msg
proc remove*(self: View): string {.slot.} =
result = self.delegate.deleteIdentityImage(self.model.address)
if (result == ""):
self.model.removeIdentityImage()

View File

@ -1,4 +1,5 @@
import json, sequtils, chronicles import json, sequtils, chronicles
import status/statusgo_backend/accounts
import ./service_interface, ./dto import ./service_interface, ./dto
@ -35,4 +36,9 @@ method getProfile*(self: Service): Dto =
hasIdentityImage: false, hasIdentityImage: false,
messagesFromContactsOnly: false messagesFromContactsOnly: false
) )
method storeIdentityImage*(self: Service, address: string, image: string, aX: int, aY: int, bX: int, bY: int): IdentityImage =
storeIdentityImage(address, image, aX, aY, bX, bY)
method deleteIdentityImage*(self: Service, address: string): string =
deleteIdentityImage(address)

View File

@ -2,6 +2,10 @@ import dto
export dto export dto
import status/types/identity_image
export IdentityImage
type type
ServiceInterface* {.pure inheritable.} = ref object of RootObj ServiceInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for this service access. ## Abstract class for this service access.
@ -15,5 +19,11 @@ method init*(self: ServiceInterface) {.base.} =
method getProfile*(self: ServiceInterface): Dto {.base.} = method getProfile*(self: ServiceInterface): Dto {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method storeIdentityImage*(self: ServiceInterface, address: string, image: string, aX: int, aY: int, bX: int, bY: int): IdentityImage {.base.} =
raise newException(ValueError, "No implementation available")
method deleteIdentityImage*(self: ServiceInterface, address: string): string {.base.} =
raise newException(ValueError, "No implementation available")
# method getTokens*(self: ServiceInterface, chainId: int): seq[Dto] {.base.} = # method getTokens*(self: ServiceInterface, chainId: int): seq[Dto] {.base.} =
# raise newException(ValueError, "No implementation available") # raise newException(ValueError, "No implementation available")

View File

@ -19,7 +19,7 @@ ModalPopup {
property url largeImage: "" property url largeImage: ""
property bool hasIdentityImage: false property bool hasIdentityImage: false
signal cropFinished(var aX, var aY, var bX, var bY) signal cropFinished(string selectedImage, var aX, var aY, var bX, var bY)
signal removeImageButtonClicked() signal removeImageButtonClicked()
//% "Profile picture" //% "Profile picture"

View File

@ -6,7 +6,7 @@ QtObject {
property var profileModelInst: profileModel property var profileModelInst: profileModel
property var profileModuleInst: profileSectionModule property var profileModuleInst: profileSectionModule
property var profile: profileModule property var profile: profileModule.model
property var contactsModuleInst: contactsModule property var contactsModuleInst: contactsModule
property var aboutModuleInst: aboutModule property var aboutModuleInst: aboutModule
property var languageModuleInst: languageModule property var languageModuleInst: languageModule
@ -178,11 +178,11 @@ QtObject {
} }
function uploadImage(source, aX, aY, bX, bY) { function uploadImage(source, aX, aY, bX, bY) {
return profileModelInst.picture.upload(source, aX, aY, bX, bY) return profileModule.upload(source, aX, aY, bX, bY)
} }
function removeImage() { function removeImage() {
return profileModelInst.picture.remove() return profileModule.remove()
} }
function lookupContact(value) { function lookupContact(value) {