feat(settings/profile): add bio and social links functionality to profile module

iterates: #6797
This commit is contained in:
Patryk Osmaczko 2022-08-10 10:22:18 +02:00 committed by osmaczko
parent cbfe8cb19e
commit 6804e2aa91
5 changed files with 148 additions and 8 deletions

View File

@ -83,7 +83,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
result.controller = controller.newController(result) result.controller = controller.newController(result)
result.moduleLoaded = false result.moduleLoaded = false
result.profileModule = profile_module.newModule(result, profileService) result.profileModule = profile_module.newModule(result, profileService, settingsService)
result.contactsModule = contacts_module.newModule(result, events, contactsService, chatService) result.contactsModule = contacts_module.newModule(result, events, contactsService, chatService)
result.languageModule = language_module.newModule(result, events, languageService) result.languageModule = language_module.newModule(result, events, languageService)
result.privacyModule = privacy_module.newModule(result, events, settingsService, privacyService, generalService) result.privacyModule = privacy_module.newModule(result, events, settingsService, privacyService, generalService)

View File

@ -1,17 +1,21 @@
import io_interface import io_interface
import ../../../../../app_service/service/profile/service as profile_service 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 type
Controller* = ref object of RootObj Controller* = ref object of RootObj
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
profileService: profile_service.Service profileService: profile_service.Service
settingsService: settings_service.Service
proc newController*(delegate: io_interface.AccessInterface, proc newController*(delegate: io_interface.AccessInterface,
profileService: profile_service.Service): Controller = profileService: profile_service.Service, settingsService: settings_service.Service): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.profileService = profileService result.profileService = profileService
result.settingsService = settingsService
proc delete*(self: Controller) = proc delete*(self: Controller) =
discard discard
@ -27,3 +31,15 @@ proc deleteIdentityImage*(self: Controller, address: string) =
proc setDisplayName*(self: Controller, displayName: string) = proc setDisplayName*(self: Controller, displayName: string) =
self.profileService.setDisplayName(displayName) self.profileService.setDisplayName(displayName)
proc getSocialLinks*(self: Controller): SocialLinks =
self.settingsService.getSocialLinks()
proc setSocialLinks*(self: Controller, links: SocialLinks): bool =
self.settingsService.setSocialLinks(links)
proc getBio*(self: Controller): string =
self.settingsService.getBio()
proc setBio*(self: Controller, bio: string): bool =
self.settingsService.setBio(bio)

View File

@ -22,9 +22,18 @@ method storeIdentityImage*(self: AccessInterface, imageUrl: string, aX: int, aY:
method deleteIdentityImage*(self: AccessInterface) {.base.} = method deleteIdentityImage*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getBio*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method setBio*(self: AccessInterface, bio: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method setDisplayName*(self: AccessInterface, displayName: string) {.base.} = method setDisplayName*(self: AccessInterface, displayName: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method saveSocialLinks*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface # View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi # Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim. # inheritance, which is not well supported in Nim.

View File

@ -1,10 +1,15 @@
import NimQml, chronicles import NimQml, chronicles, sequtils, sugar
import ./io_interface, ./view, ./controller import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import ../../../../global/global_singleton import ../../../../global/global_singleton
import ../../../../../app_service/service/profile/service as profile_service import ../../../../../app_service/service/profile/service as profile_service
import ../../../../../app_service/service/settings/service as settings_service
import ../../../../../app_service/common/social_links
import ../../../shared_models/social_links_model
import ../../../shared_models/social_link_item
export io_interface export io_interface
@ -20,12 +25,12 @@ type
moduleLoaded: bool moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, proc newModule*(delegate: delegate_interface.AccessInterface,
profileService: profile_service.Service): Module = profileService: profile_service.Service, settingsService: settings_service.Service): Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, profileService) result.controller = controller.newController(result, profileService, settingsService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*(self: Module) = method delete*(self: Module) =
@ -43,7 +48,21 @@ method isLoaded*(self: Module): bool =
method getModuleAsVariant*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
func hasCustomLink(socialLinks: seq[SocialLinkItem]): bool =
for socialLinkItem in socialLinks:
if socialLinkItem.linkType() == LinkType.Custom:
return true
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
var socialLinkItems = toSocialLinkItems(self.controller.getSocialLinks())
# Add custom link placeholder
if not socialLinkItems.hasCustomLink:
socialLinkItems.add(initSocialLinkItem("", "", LinkType.Custom))
self.view.socialLinksModel().setItems(socialLinkItems)
self.view.temporarySocialLinksModel().setItems(socialLinkItems)
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.profileModuleDidLoad() self.delegate.profileModuleDidLoad()
@ -58,3 +77,13 @@ method deleteIdentityImage*(self: Module) =
method setDisplayName*(self: Module, displayName: string) = method setDisplayName*(self: Module, displayName: string) =
self.controller.setDisplayName(displayName) self.controller.setDisplayName(displayName)
method getBio(self: Module): string =
self.controller.getBio()
method setBio(self: Module, bio: string): bool =
self.controller.setBio(bio)
method saveSocialLinks*(self: Module): bool =
let socialLinks = map(self.view.temporarySocialLinksModel.items(), x => SocialLink(text: x.text, url: x.url))
return self.controller.setSocialLinks(socialLinks)

View File

@ -1,19 +1,33 @@
import NimQml import NimQml, json
import ./io_interface import io_interface
import ../../../shared_models/social_links_model
import ../../../shared_models/social_link_item
QtObject: QtObject:
type type
View* = ref object of QObject View* = ref object of QObject
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
socialLinksModel: SocialLinksModel
socialLinksModelVariant: QVariant
temporarySocialLinksModel: SocialLinksModel # used for editing purposes
temporarySocialLinksModelVariant: QVariant
proc delete*(self: View) = proc delete*(self: View) =
self.QObject.delete self.QObject.delete
self.socialLinksModel.delete
self.socialLinksModelVariant.delete
self.temporarySocialLinksModel.delete
self.temporarySocialLinksModelVariant.delete
proc newView*(delegate: io_interface.AccessInterface): View = proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete) new(result, delete)
result.QObject.setup result.QObject.setup
result.delegate = delegate result.delegate = delegate
result.socialLinksModel = newSocialLinksModel()
result.socialLinksModelVariant = newQVariant(result.socialLinksModel)
result.temporarySocialLinksModel = newSocialLinksModel()
result.temporarySocialLinksModelVariant = newQVariant(result.temporarySocialLinksModel)
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
@ -32,3 +46,75 @@ QtObject:
proc setDisplayName(self: View, displayName: string) {.slot.} = proc setDisplayName(self: View, displayName: string) {.slot.} =
self.delegate.setDisplayName(displayName) self.delegate.setDisplayName(displayName)
proc socialLinksModel*(self: View): SocialLinksModel =
return self.socialLinksModel
proc getSocialLinksModel(self: View): QVariant {.slot.} =
return self.socialLinksModelVariant
QtProperty[QVariant] socialLinksModel:
read = getSocialLinksModel
proc temporarySocialLinksModel*(self: View): SocialLinksModel =
return self.temporarySocialLinksModel
proc getTemporarySocialLinksModel(self: View): QVariant {.slot.} =
return self.temporarySocialLinksModelVariant
QtProperty[QVariant] temporarySocialLinksModel:
read = getTemporarySocialLinksModel
proc socialLinksDirtyChanged*(self: View) {.signal.}
proc areSocialLinksDirty(self: View): bool {.slot.} =
self.socialLinksModel.items != self.temporarySocialLinksModel.items
proc socialLinksJsonChanged*(self: View) {.signal.}
proc getSocialLinksJson(self: View): string {.slot.} =
$(%*self.socialLinksModel.items)
QtProperty[string] socialLinksJson:
read = getSocialLinksJson
notify = socialLinksJsonChanged
QtProperty[bool] socialLinksDirty:
read = areSocialLinksDirty
notify = socialLinksDirtyChanged
proc createCustomLink(self: View, text: string, url: string) {.slot.} =
self.temporarySocialLinksModel.appendItem(initSocialLinkItem(text, url, LinkType.Custom))
self.socialLinksDirtyChanged()
proc removeCustomLink(self: View, uuid: string) {.slot.} =
if (self.temporarySocialLinksModel.removeItem(uuid)):
self.socialLinksDirtyChanged()
proc updateLink(self: View, uuid: string, text: string, url: string): bool {.slot.} =
if (self.temporarySocialLinksModel.updateItem(uuid, text, url)):
self.socialLinksDirtyChanged()
proc resetSocialLinks(self: View): bool {.slot.} =
if (self.areSocialLinksDirty()):
self.temporarySocialLinksModel.setItems(self.socialLinksModel.items)
self.socialLinksDirtyChanged()
proc saveSocialLinks(self: View): bool {.slot.} =
result = self.delegate.saveSocialLinks()
if (result):
self.socialLinksModel.setItems(self.temporarySocialLinksModel.items)
self.socialLinksDirtyChanged()
self.socialLinksJsonChanged()
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()