feat(Contacts): refresh profile on live data update, review fixes
This commit is contained in:
parent
84f3626390
commit
e2c3cebdb5
|
@ -53,10 +53,18 @@ proc init*(self: Controller) =
|
||||||
let args = SocialLinksArgs(e)
|
let args = SocialLinksArgs(e)
|
||||||
self.delegate.onSocialLinksUpdated(args.socialLinks, args.error)
|
self.delegate.onSocialLinksUpdated(args.socialLinks, args.error)
|
||||||
|
|
||||||
self.events.on(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED) do(e: Args):
|
self.events.on(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_UPDATED) do(e: Args):
|
||||||
let args = ProfileShowcasePreferencesArgs(e)
|
let args = ProfileShowcasePreferencesArgs(e)
|
||||||
self.delegate.updateProfileShowcasePreferences(args.preferences)
|
self.delegate.updateProfileShowcasePreferences(args.preferences)
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args):
|
||||||
|
var args = ContactArgs(e)
|
||||||
|
self.delegate.onContactDetailsUpdated(args.contactId)
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_COMMUNITIES_UPDATE) do(e: Args):
|
||||||
|
let args = CommunitiesArgs(e)
|
||||||
|
self.delegate.onCommunitiesUpdated(args.communities)
|
||||||
|
|
||||||
proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int) =
|
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)
|
discard self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)
|
||||||
|
|
||||||
|
@ -75,8 +83,8 @@ proc getCommunityById*(self: Controller, id: string): CommunityDto =
|
||||||
proc getAccountByAddress*(self: Controller, address: string): WalletAccountDto =
|
proc getAccountByAddress*(self: Controller, address: string): WalletAccountDto =
|
||||||
return self.walletAccountService.getAccountByAddress(address)
|
return self.walletAccountService.getAccountByAddress(address)
|
||||||
|
|
||||||
proc getTokensByAddress*(self: Controller, address: string): seq[WalletTokenDto] =
|
proc getTokensByAddresses*(self: Controller, addresses: seq[string]): seq[WalletTokenDto] =
|
||||||
return self.walletAccountService.getTokensByAddress(address)
|
return self.walletAccountService.getTokensByAddresses(addresses)
|
||||||
|
|
||||||
proc getContactById*(self: Controller, id: string): ContactsDto =
|
proc getContactById*(self: Controller, id: string): ContactsDto =
|
||||||
return self.contactsService.getContactById(id)
|
return self.contactsService.getContactById(id)
|
||||||
|
@ -95,3 +103,6 @@ proc storeProfileShowcasePreferences*(self: Controller, preferences: ProfileShow
|
||||||
|
|
||||||
proc requestProfileShowcasePreferences*(self: Controller) =
|
proc requestProfileShowcasePreferences*(self: Controller) =
|
||||||
self.profileService.requestProfileShowcasePreferences()
|
self.profileService.requestProfileShowcasePreferences()
|
||||||
|
|
||||||
|
proc requestCommunityInfo*(self: Controller, communityId: string) =
|
||||||
|
self.communityService.requestCommunityInfo(communityId)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import NimQml
|
||||||
|
|
||||||
import app_service/common/social_links
|
import app_service/common/social_links
|
||||||
import app_service/service/profile/dto/profile_showcase_preferences
|
import app_service/service/profile/dto/profile_showcase_preferences
|
||||||
|
import app_service/service/community/dto/community
|
||||||
|
|
||||||
import models/profile_preferences_community_item
|
import models/profile_preferences_community_item
|
||||||
import models/profile_preferences_account_item
|
import models/profile_preferences_account_item
|
||||||
|
@ -64,6 +65,12 @@ method requestProfileShowcase*(self: AccessInterface, publicKey: string) {.base.
|
||||||
method updateProfileShowcasePreferences*(self: AccessInterface, preferences: ProfileShowcasePreferencesDto) {.base.} =
|
method updateProfileShowcasePreferences*(self: AccessInterface, preferences: ProfileShowcasePreferencesDto) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method onContactDetailsUpdated*(self: AccessInterface, contactId: string) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method onCommunitiesUpdated*(self: AccessInterface, communities: seq[CommunityDto]) {.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.
|
||||||
|
|
|
@ -138,13 +138,16 @@ QtObject:
|
||||||
self.recalcOrder()
|
self.recalcOrder()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
proc reset*(self: ProfileShowcaseAccountsModel) {.slot.} =
|
proc reset*(self: ProfileShowcaseAccountsModel, items: seq[ProfileShowcaseAccountItem]) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.items = @[]
|
self.items = items
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
|
proc clear*(self: ProfileShowcaseAccountsModel) {.slot.} =
|
||||||
|
self.reset(@[])
|
||||||
|
|
||||||
proc remove*(self: ProfileShowcaseAccountsModel, index: int) {.slot.} =
|
proc remove*(self: ProfileShowcaseAccountsModel, index: int) {.slot.} =
|
||||||
if index < 0 or index >= self.items.len:
|
if index < 0 or index >= self.items.len:
|
||||||
return
|
return
|
||||||
|
|
|
@ -138,13 +138,16 @@ QtObject:
|
||||||
self.recalcOrder()
|
self.recalcOrder()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
proc reset*(self: ProfileShowcaseAssetsModel) {.slot.} =
|
proc reset*(self: ProfileShowcaseAssetsModel, items: seq[ProfileShowcaseAssetItem]) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.items = @[]
|
self.items = items
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
|
proc clear*(self: ProfileShowcaseAssetsModel) {.slot.} =
|
||||||
|
self.reset(@[])
|
||||||
|
|
||||||
proc remove*(self: ProfileShowcaseAssetsModel, index: int) {.slot.} =
|
proc remove*(self: ProfileShowcaseAssetsModel, index: int) {.slot.} =
|
||||||
if index < 0 or index >= self.items.len:
|
if index < 0 or index >= self.items.len:
|
||||||
return
|
return
|
||||||
|
|
|
@ -143,13 +143,16 @@ QtObject:
|
||||||
self.recalcOrder()
|
self.recalcOrder()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
proc reset*(self: ProfileShowcaseCollectiblesModel) {.slot.} =
|
proc reset*(self: ProfileShowcaseCollectiblesModel, items: seq[ProfileShowcaseCollectibleItem]) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.items = @[]
|
self.items = items
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
|
proc clear*(self: ProfileShowcaseCollectiblesModel) {.slot.} =
|
||||||
|
self.reset(@[])
|
||||||
|
|
||||||
proc remove*(self: ProfileShowcaseCollectiblesModel, index: int) {.slot.} =
|
proc remove*(self: ProfileShowcaseCollectiblesModel, index: int) {.slot.} =
|
||||||
if index < 0 or index >= self.items.len:
|
if index < 0 or index >= self.items.len:
|
||||||
return
|
return
|
||||||
|
|
|
@ -13,6 +13,9 @@ type
|
||||||
MemberRole
|
MemberRole
|
||||||
Image
|
Image
|
||||||
Color
|
Color
|
||||||
|
Description
|
||||||
|
MembersCount
|
||||||
|
Loading
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -56,6 +59,9 @@ QtObject:
|
||||||
ModelRole.MemberRole.int: "memberRole",
|
ModelRole.MemberRole.int: "memberRole",
|
||||||
ModelRole.Image.int: "image",
|
ModelRole.Image.int: "image",
|
||||||
ModelRole.Color.int: "color",
|
ModelRole.Color.int: "color",
|
||||||
|
ModelRole.Description.int: "description",
|
||||||
|
ModelRole.MembersCount.int: "membersCount",
|
||||||
|
ModelRole.Loading.int: "loading",
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
method data(self: ProfileShowcaseCommunitiesModel, index: QModelIndex, role: int): QVariant =
|
method data(self: ProfileShowcaseCommunitiesModel, index: QModelIndex, role: int): QVariant =
|
||||||
|
@ -83,6 +89,12 @@ QtObject:
|
||||||
result = newQVariant(item.image)
|
result = newQVariant(item.image)
|
||||||
of ModelRole.Color:
|
of ModelRole.Color:
|
||||||
result = newQVariant(item.color)
|
result = newQVariant(item.color)
|
||||||
|
of ModelRole.Description:
|
||||||
|
result = newQVariant(item.description)
|
||||||
|
of ModelRole.MembersCount:
|
||||||
|
result = newQVariant(item.membersCount)
|
||||||
|
of ModelRole.Loading:
|
||||||
|
result = newQVariant(item.loading)
|
||||||
|
|
||||||
proc findIndexForCommunity(self: ProfileShowcaseCommunitiesModel, id: string): int =
|
proc findIndexForCommunity(self: ProfileShowcaseCommunitiesModel, id: string): int =
|
||||||
for i in 0 ..< self.items.len:
|
for i in 0 ..< self.items.len:
|
||||||
|
@ -124,6 +136,9 @@ QtObject:
|
||||||
ModelRole.MemberRole.int,
|
ModelRole.MemberRole.int,
|
||||||
ModelRole.Image.int,
|
ModelRole.Image.int,
|
||||||
ModelRole.Color.int,
|
ModelRole.Color.int,
|
||||||
|
ModelRole.Description.int,
|
||||||
|
ModelRole.MembersCount.int,
|
||||||
|
ModelRole.Loading.int,
|
||||||
])
|
])
|
||||||
|
|
||||||
proc upsertItemJson(self: ProfileShowcaseCommunitiesModel, itemJson: string) {.slot.} =
|
proc upsertItemJson(self: ProfileShowcaseCommunitiesModel, itemJson: string) {.slot.} =
|
||||||
|
@ -142,13 +157,16 @@ QtObject:
|
||||||
self.recalcOrder()
|
self.recalcOrder()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
proc reset*(self: ProfileShowcaseCommunitiesModel) {.slot.} =
|
proc reset*(self: ProfileShowcaseCommunitiesModel, items: seq[ProfileShowcaseCommunityItem]) =
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.items = @[]
|
self.items = items
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
self.countChanged()
|
self.countChanged()
|
||||||
self.baseModelFilterConditionsMayHaveChanged()
|
self.baseModelFilterConditionsMayHaveChanged()
|
||||||
|
|
||||||
|
proc clear*(self: ProfileShowcaseCommunitiesModel) {.slot.} =
|
||||||
|
self.reset(@[])
|
||||||
|
|
||||||
proc remove*(self: ProfileShowcaseCommunitiesModel, index: int) {.slot.} =
|
proc remove*(self: ProfileShowcaseCommunitiesModel, index: int) {.slot.} =
|
||||||
if index < 0 or index >= self.items.len:
|
if index < 0 or index >= self.items.len:
|
||||||
return
|
return
|
||||||
|
@ -190,4 +208,4 @@ QtObject:
|
||||||
proc setVisibility*(self: ProfileShowcaseCommunitiesModel, id: string, visibility: int) {.slot.} =
|
proc setVisibility*(self: ProfileShowcaseCommunitiesModel, id: string, visibility: int) {.slot.} =
|
||||||
let index = self.findIndexForCommunity(id)
|
let index = self.findIndexForCommunity(id)
|
||||||
if index != -1:
|
if index != -1:
|
||||||
self.setVisibilityByIndex(index, visibility)
|
self.setVisibilityByIndex(index, visibility)
|
||||||
|
|
|
@ -15,6 +15,9 @@ type
|
||||||
memberRole*: MemberRole
|
memberRole*: MemberRole
|
||||||
image*: string
|
image*: string
|
||||||
color*: string
|
color*: string
|
||||||
|
description*: string
|
||||||
|
membersCount*: int
|
||||||
|
loading*: bool
|
||||||
|
|
||||||
proc initProfileShowcaseCommunityItem*(community: CommunityDto, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseCommunityItem =
|
proc initProfileShowcaseCommunityItem*(community: CommunityDto, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseCommunityItem =
|
||||||
result = ProfileShowcaseCommunityItem()
|
result = ProfileShowcaseCommunityItem()
|
||||||
|
@ -27,6 +30,17 @@ proc initProfileShowcaseCommunityItem*(community: CommunityDto, visibility: Prof
|
||||||
result.memberRole = community.memberRole
|
result.memberRole = community.memberRole
|
||||||
result.image = community.images.thumbnail
|
result.image = community.images.thumbnail
|
||||||
result.color = community.color
|
result.color = community.color
|
||||||
|
result.description = community.description
|
||||||
|
result.membersCount = len(community.members)
|
||||||
|
result.loading = false
|
||||||
|
|
||||||
|
proc initProfileShowcaseCommunityLoadingItem*(communityId: string, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseCommunityItem =
|
||||||
|
result = ProfileShowcaseCommunityItem()
|
||||||
|
|
||||||
|
result.showcaseVisibility = visibility
|
||||||
|
result.order = order
|
||||||
|
result.id = communityId
|
||||||
|
result.loading = true
|
||||||
|
|
||||||
proc toProfileShowcaseCommunityItem*(jsonObj: JsonNode): ProfileShowcaseCommunityItem =
|
proc toProfileShowcaseCommunityItem*(jsonObj: JsonNode): ProfileShowcaseCommunityItem =
|
||||||
result = ProfileShowcaseCommunityItem()
|
result = ProfileShowcaseCommunityItem()
|
||||||
|
@ -43,6 +57,7 @@ proc toProfileShowcaseCommunityItem*(jsonObj: JsonNode): ProfileShowcaseCommunit
|
||||||
discard jsonObj.getProp("memberRole", result.memberRole)
|
discard jsonObj.getProp("memberRole", result.memberRole)
|
||||||
discard jsonObj.getProp("image", result.image)
|
discard jsonObj.getProp("image", result.image)
|
||||||
discard jsonObj.getProp("color", result.color)
|
discard jsonObj.getProp("color", result.color)
|
||||||
|
result.loading = false
|
||||||
|
|
||||||
proc toShowcasePreferenceItem*(self: ProfileShowcaseCommunityItem): ProfileShowcaseCommunityPreference =
|
proc toShowcasePreferenceItem*(self: ProfileShowcaseCommunityItem): ProfileShowcaseCommunityPreference =
|
||||||
result = ProfileShowcaseCommunityPreference()
|
result = ProfileShowcaseCommunityPreference()
|
||||||
|
@ -51,6 +66,15 @@ proc toShowcasePreferenceItem*(self: ProfileShowcaseCommunityItem): ProfileShowc
|
||||||
result.showcaseVisibility = self.showcaseVisibility
|
result.showcaseVisibility = self.showcaseVisibility
|
||||||
result.order = self.order
|
result.order = self.order
|
||||||
|
|
||||||
|
proc patchFromCommunity*(self: ProfileShowcaseCommunityItem, community: CommunityDto) =
|
||||||
|
self.name = community.name
|
||||||
|
self.memberRole = community.memberRole
|
||||||
|
self.image = community.images.thumbnail
|
||||||
|
self.color = community.color
|
||||||
|
self.description = community.description
|
||||||
|
self.membersCount = len(community.members)
|
||||||
|
self.loading = false
|
||||||
|
|
||||||
proc name*(self: ProfileShowcaseCommunityItem): string {.inline.} =
|
proc name*(self: ProfileShowcaseCommunityItem): string {.inline.} =
|
||||||
self.name
|
self.name
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ type
|
||||||
view: View
|
view: View
|
||||||
viewVariant: QVariant
|
viewVariant: QVariant
|
||||||
moduleLoaded: bool
|
moduleLoaded: bool
|
||||||
|
presentedPublicKey: string
|
||||||
|
|
||||||
proc newModule*(
|
proc newModule*(
|
||||||
delegate: delegate_interface.AccessInterface,
|
delegate: delegate_interface.AccessInterface,
|
||||||
|
@ -109,6 +110,10 @@ method storeProfileShowcasePreferences(self: Module,
|
||||||
accounts: seq[ProfileShowcaseAccountItem],
|
accounts: seq[ProfileShowcaseAccountItem],
|
||||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
collectibles: seq[ProfileShowcaseCollectibleItem],
|
||||||
assets: seq[ProfileShowcaseAssetItem]) =
|
assets: seq[ProfileShowcaseAssetItem]) =
|
||||||
|
if self.presentedPublicKey != singletonInstance.userProfile.getPubKey():
|
||||||
|
error "Attempt to save preferences with wrong public key"
|
||||||
|
return
|
||||||
|
|
||||||
self.controller.storeProfileShowcasePreferences(ProfileShowcasePreferencesDto(
|
self.controller.storeProfileShowcasePreferences(ProfileShowcasePreferencesDto(
|
||||||
communities: communities.map(item => item.toShowcasePreferenceItem()),
|
communities: communities.map(item => item.toShowcasePreferenceItem()),
|
||||||
accounts: accounts.map(item => item.toShowcasePreferenceItem()),
|
accounts: accounts.map(item => item.toShowcasePreferenceItem()),
|
||||||
|
@ -117,9 +122,22 @@ method storeProfileShowcasePreferences(self: Module,
|
||||||
))
|
))
|
||||||
|
|
||||||
method requestProfileShowcasePreferences(self: Module) =
|
method requestProfileShowcasePreferences(self: Module) =
|
||||||
|
let myPublicKey = singletonInstance.userProfile.getPubKey()
|
||||||
|
if self.presentedPublicKey != myPublicKey:
|
||||||
|
self.view.clearModels()
|
||||||
|
self.presentedPublicKey = myPublicKey
|
||||||
|
|
||||||
self.controller.requestProfileShowcasePreferences()
|
self.controller.requestProfileShowcasePreferences()
|
||||||
|
|
||||||
method requestProfileShowcase*(self: Module, publicKey: string) =
|
method requestProfileShowcase*(self: Module, publicKey: string) =
|
||||||
|
if publicKey == singletonInstance.userProfile.getPubKey():
|
||||||
|
self.requestProfileShowcasePreferences()
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.presentedPublicKey != publicKey:
|
||||||
|
self.view.clearModels()
|
||||||
|
self.presentedPublicKey = publicKey
|
||||||
|
|
||||||
let contact = self.controller.getContactById(publicKey)
|
let contact = self.controller.getContactById(publicKey)
|
||||||
|
|
||||||
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
||||||
|
@ -128,11 +146,17 @@ method requestProfileShowcase*(self: Module, publicKey: string) =
|
||||||
var profileAssetItems: seq[ProfileShowcaseAssetItem] = @[]
|
var profileAssetItems: seq[ProfileShowcaseAssetItem] = @[]
|
||||||
|
|
||||||
for communityEntry in contact.profileShowcase.communities:
|
for communityEntry in contact.profileShowcase.communities:
|
||||||
# TODO: what if we don't know such community?
|
|
||||||
let community = self.controller.getCommunityById(communityEntry.communityId)
|
let community = self.controller.getCommunityById(communityEntry.communityId)
|
||||||
profileCommunityItems.add(initProfileShowcaseCommunityItem(
|
if community.id == "":
|
||||||
community, ProfileShowcaseVisibility.ToEveryone, communityEntry.order))
|
self.controller.requestCommunityInfo(communityEntry.communityId)
|
||||||
|
profileCommunityItems.add(initProfileShowcaseCommunityLoadingItem(
|
||||||
|
communityEntry.communityId, ProfileShowcaseVisibility.ToEveryone, communityEntry.order))
|
||||||
|
else:
|
||||||
|
profileCommunityItems.add(initProfileShowcaseCommunityItem(
|
||||||
|
community, ProfileShowcaseVisibility.ToEveryone, communityEntry.order))
|
||||||
|
self.view.updateProfileShowcaseCommunities(profileCommunityItems)
|
||||||
|
|
||||||
|
var addresses: seq[string] = @[]
|
||||||
for account in contact.profileShowcase.accounts:
|
for account in contact.profileShowcase.accounts:
|
||||||
profileAccountItems.add(initProfileShowcaseAccountItem(
|
profileAccountItems.add(initProfileShowcaseAccountItem(
|
||||||
account.address,
|
account.address,
|
||||||
|
@ -142,17 +166,16 @@ method requestProfileShowcase*(self: Module, publicKey: string) =
|
||||||
ProfileShowcaseVisibility.ToEveryone,
|
ProfileShowcaseVisibility.ToEveryone,
|
||||||
account.order
|
account.order
|
||||||
))
|
))
|
||||||
|
addresses.add(account.address)
|
||||||
|
|
||||||
for assetEntry in contact.profileShowcase.assets:
|
for assetEntry in contact.profileShowcase.assets:
|
||||||
# TODO: need wallet api to fetch token by symbol
|
for token in self.controller.getTokensByAddresses(addresses):
|
||||||
for token in self.controller.getTokensByAddress(account.address):
|
if assetEntry.symbol == token.symbol:
|
||||||
if assetEntry.symbol == token.symbol:
|
profileAssetItems.add(initProfileShowcaseAssetItem(token, ProfileShowcaseVisibility.ToEveryone, assetEntry.order))
|
||||||
# NOTE: here can be intersections
|
|
||||||
profileAssetItems.add(initProfileShowcaseAssetItem(token,
|
|
||||||
ProfileShowcaseVisibility.ToEveryone, assetEntry.order))
|
|
||||||
|
|
||||||
# TODO: collectibles, need wallet api to fetch collectible by uid
|
self.view.updateProfileShowcaseAccounts(profileAccountItems)
|
||||||
self.view.updateProfileShowcasePreferences(profileCommunityItems, profileAccountItems, profileCollectibleItems, profileAssetItems)
|
self.view.updateProfileShowcaseAssets(profileAssetItems)
|
||||||
|
# TODO: collectibles, need wallet api to fetch collectible by uid
|
||||||
|
|
||||||
method updateProfileShowcasePreferences(self: Module, preferences: ProfileShowcasePreferencesDto) =
|
method updateProfileShowcasePreferences(self: Module, preferences: ProfileShowcasePreferencesDto) =
|
||||||
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
||||||
|
@ -162,8 +185,16 @@ method updateProfileShowcasePreferences(self: Module, preferences: ProfileShowca
|
||||||
|
|
||||||
for communityEntry in preferences.communities:
|
for communityEntry in preferences.communities:
|
||||||
let community = self.controller.getCommunityById(communityEntry.communityId)
|
let community = self.controller.getCommunityById(communityEntry.communityId)
|
||||||
profileCommunityItems.add(initProfileShowcaseCommunityItem(community, communityEntry.showcaseVisibility, communityEntry.order))
|
if community.id == "":
|
||||||
|
self.controller.requestCommunityInfo(communityEntry.communityId)
|
||||||
|
profileCommunityItems.add(initProfileShowcaseCommunityLoadingItem(
|
||||||
|
communityEntry.communityId, communityEntry.showcaseVisibility, communityEntry.order))
|
||||||
|
else:
|
||||||
|
profileCommunityItems.add(initProfileShowcaseCommunityItem(
|
||||||
|
community, communityEntry.showcaseVisibility, communityEntry.order))
|
||||||
|
self.view.updateProfileShowcaseCommunities(profileCommunityItems)
|
||||||
|
|
||||||
|
var addresses: seq[string] = @[]
|
||||||
for account in preferences.accounts:
|
for account in preferences.accounts:
|
||||||
profileAccountItems.add(initProfileShowcaseAccountItem(
|
profileAccountItems.add(initProfileShowcaseAccountItem(
|
||||||
account.address,
|
account.address,
|
||||||
|
@ -173,14 +204,27 @@ method updateProfileShowcasePreferences(self: Module, preferences: ProfileShowca
|
||||||
account.showcaseVisibility,
|
account.showcaseVisibility,
|
||||||
account.order
|
account.order
|
||||||
))
|
))
|
||||||
|
addresses.add(account.address)
|
||||||
|
|
||||||
for assetEntry in preferences.assets:
|
for assetEntry in preferences.assets:
|
||||||
# TODO: need wallet api to fetch token by symbol
|
for token in self.controller.getTokensByAddresses(addresses):
|
||||||
for token in self.controller.getTokensByAddress(account.address):
|
if assetEntry.symbol == token.symbol:
|
||||||
if assetEntry.symbol == token.symbol:
|
profileAssetItems.add(initProfileShowcaseAssetItem(token, assetEntry.showcaseVisibility, assetEntry.order))
|
||||||
# NOTE: here can be intersections
|
|
||||||
profileAssetItems.add(initProfileShowcaseAssetItem(token, assetEntry.showcaseVisibility, assetEntry.order))
|
|
||||||
|
|
||||||
# TODO: collectibles, need wallet api to fetch collectible by uid
|
self.view.updateProfileShowcaseAccounts(profileAccountItems)
|
||||||
|
self.view.updateProfileShowcaseAssets(profileAssetItems)
|
||||||
|
# TODO: collectibles, need wallet api to fetch collectible by uid
|
||||||
|
|
||||||
self.view.updateProfileShowcasePreferences(profileCommunityItems, profileAccountItems, profileCollectibleItems, profileAssetItems)
|
method onContactDetailsUpdated*(self: Module, contactId: string) =
|
||||||
|
if self.presentedPublicKey == contactId:
|
||||||
|
self.requestProfileShowcase(contactId)
|
||||||
|
|
||||||
|
method onCommunitiesUpdated*(self: Module, communities: seq[CommunityDto]) =
|
||||||
|
var profileCommunityItems = self.view.getProfileShowcaseCommunities()
|
||||||
|
|
||||||
|
for community in communities:
|
||||||
|
for item in profileCommunityItems:
|
||||||
|
if item.id == community.id:
|
||||||
|
item.patchFromCommunity(community)
|
||||||
|
|
||||||
|
self.view.updateProfileShowcaseCommunities(profileCommunityItems)
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import NimQml, json, sequtils, chronicles
|
import NimQml, json, sequtils, sugar, std/algorithm
|
||||||
|
|
||||||
import io_interface
|
import io_interface
|
||||||
import app/modules/shared_models/social_links_model
|
import app/modules/shared_models/social_links_model
|
||||||
import app/modules/shared_models/social_link_item
|
import app/modules/shared_models/social_link_item
|
||||||
|
|
||||||
import app/global/global_singleton
|
|
||||||
|
|
||||||
import models/profile_preferences_communities_model
|
import models/profile_preferences_communities_model
|
||||||
import models/profile_preferences_community_item
|
import models/profile_preferences_community_item
|
||||||
import models/profile_preferences_accounts_model
|
import models/profile_preferences_accounts_model
|
||||||
|
@ -31,7 +29,6 @@ QtObject:
|
||||||
profileShowcaseCollectiblesModelVariant: QVariant
|
profileShowcaseCollectiblesModelVariant: QVariant
|
||||||
profileShowcaseAssetsModel: ProfileShowcaseAssetsModel
|
profileShowcaseAssetsModel: ProfileShowcaseAssetsModel
|
||||||
profileShowcaseAssetsModelVariant: QVariant
|
profileShowcaseAssetsModelVariant: QVariant
|
||||||
presentedPublicKey: string
|
|
||||||
|
|
||||||
proc delete*(self: View) =
|
proc delete*(self: View) =
|
||||||
self.QObject.delete
|
self.QObject.delete
|
||||||
|
@ -202,10 +199,6 @@ QtObject:
|
||||||
read = getProfileShowcaseAssetsModel
|
read = getProfileShowcaseAssetsModel
|
||||||
|
|
||||||
proc storeProfileShowcasePreferences(self: View) {.slot.} =
|
proc storeProfileShowcasePreferences(self: View) {.slot.} =
|
||||||
if self.presentedPublicKey != singletonInstance.userProfile.getPubKey():
|
|
||||||
error "Attempt to save preferences with wrong public key"
|
|
||||||
return
|
|
||||||
|
|
||||||
let communities = self.profileShowcaseCommunitiesModel.items()
|
let communities = self.profileShowcaseCommunitiesModel.items()
|
||||||
let accounts = self.profileShowcaseAccountsModel.items()
|
let accounts = self.profileShowcaseAccountsModel.items()
|
||||||
let collectibles = self.profileShowcaseCollectiblesModel.items()
|
let collectibles = self.profileShowcaseCollectiblesModel.items()
|
||||||
|
@ -213,44 +206,29 @@ QtObject:
|
||||||
|
|
||||||
self.delegate.storeProfileShowcasePreferences(communities, accounts, collectibles, assets)
|
self.delegate.storeProfileShowcasePreferences(communities, accounts, collectibles, assets)
|
||||||
|
|
||||||
proc clearModels(self: View) {.slot.} =
|
proc clearModels*(self: View) {.slot.} =
|
||||||
self.profileShowcaseCommunitiesModel.reset()
|
self.profileShowcaseCommunitiesModel.clear()
|
||||||
self.profileShowcaseAccountsModel.reset()
|
self.profileShowcaseAccountsModel.clear()
|
||||||
self.profileShowcaseCollectiblesModel.reset()
|
self.profileShowcaseCollectiblesModel.clear()
|
||||||
self.profileShowcaseAssetsModel.reset()
|
self.profileShowcaseAssetsModel.clear()
|
||||||
|
|
||||||
proc requestProfileShowcase(self: View, publicKey: string) {.slot.} =
|
proc requestProfileShowcase(self: View, publicKey: string) {.slot.} =
|
||||||
if self.presentedPublicKey != publicKey:
|
self.delegate.requestProfileShowcase(publicKey)
|
||||||
self.clearModels()
|
|
||||||
|
|
||||||
if publicKey == singletonInstance.userProfile.getPubKey():
|
|
||||||
self.delegate.requestProfileShowcasePreferences()
|
|
||||||
else:
|
|
||||||
self.delegate.requestProfileShowcase(publicKey)
|
|
||||||
|
|
||||||
proc requestProfileShowcasePreferences(self: View) {.slot.} =
|
proc requestProfileShowcasePreferences(self: View) {.slot.} =
|
||||||
if self.presentedPublicKey != singletonInstance.userProfile.getPubKey():
|
|
||||||
self.clearModels()
|
|
||||||
|
|
||||||
self.delegate.requestProfileShowcasePreferences()
|
self.delegate.requestProfileShowcasePreferences()
|
||||||
|
|
||||||
proc updateProfileShowcase*(self: View,
|
proc getProfileShowcaseCommunities*(self: View): seq[ProfileShowcaseCommunityItem] =
|
||||||
presentedPublicKey: string,
|
return self.profileShowcaseCommunitiesModel.items()
|
||||||
communities: seq[ProfileShowcaseCommunityItem],
|
|
||||||
accounts: seq[ProfileShowcaseAccountItem],
|
|
||||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
|
||||||
assets: seq[ProfileShowcaseAssetItem]) =
|
|
||||||
self.presentedPublicKey = presentedPublicKey
|
|
||||||
|
|
||||||
self.profileShowcaseCommunitiesModel.upsertItems(communities)
|
proc updateProfileShowcaseCommunities*(self: View, communities: seq[ProfileShowcaseCommunityItem]) =
|
||||||
self.profileShowcaseAccountsModel.upsertItems(accounts)
|
self.profileShowcaseCommunitiesModel.reset(communities.sorted((a, b) => cmp(a.order, b.order), SortOrder.Ascending))
|
||||||
self.profileShowcaseCollectiblesModel.upsertItems(collectibles)
|
|
||||||
self.profileShowcaseAssetsModel.upsertItems(assets)
|
|
||||||
|
|
||||||
proc updateProfileShowcasePreferences*(self: View,
|
proc updateProfileShowcaseAccounts*(self: View, accounts: seq[ProfileShowcaseAccountItem]) =
|
||||||
communities: seq[ProfileShowcaseCommunityItem],
|
self.profileShowcaseAccountsModel.reset(accounts.sorted((a, b) => cmp(a.order, b.order), SortOrder.Ascending))
|
||||||
accounts: seq[ProfileShowcaseAccountItem],
|
|
||||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
|
||||||
assets: seq[ProfileShowcaseAssetItem]) =
|
|
||||||
self.updateProfileShowcase(singletonInstance.userProfile.getPubKey(), communities, accounts, collectibles, assets)
|
|
||||||
|
|
||||||
|
proc updateProfileShowcaseCollectibless*(self: View, collectibles: seq[ProfileShowcaseCollectibleItem]) =
|
||||||
|
self.profileShowcaseCollectiblesModel.reset(collectibles.sorted((a, b) => cmp(a.order, b.order), SortOrder.Ascending))
|
||||||
|
|
||||||
|
proc updateProfileShowcaseAssets*(self: View, assets: seq[ProfileShowcaseAssetItem]) =
|
||||||
|
self.profileShowcaseAssetsModel.reset(assets.sorted((a, b) => cmp(a.order, b.order), SortOrder.Ascending))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, json_serialization, sugar, std/algorithm
|
import json, json_serialization, sugar
|
||||||
|
|
||||||
include ../../../common/json_utils
|
include ../../../common/json_utils
|
||||||
|
|
||||||
|
@ -61,9 +61,3 @@ proc toProfileShowcase*(jsonObj: JsonNode): ProfileShowcase =
|
||||||
result.collectibles.add(jsonMsg.toProfileShowcaseCollectible())
|
result.collectibles.add(jsonMsg.toProfileShowcaseCollectible())
|
||||||
for jsonMsg in jsonObj["assets"]:
|
for jsonMsg in jsonObj["assets"]:
|
||||||
result.assets.add(jsonMsg.toProfileShowcaseAsset())
|
result.assets.add(jsonMsg.toProfileShowcaseAsset())
|
||||||
|
|
||||||
# Sort by order as early as possible
|
|
||||||
result.communities.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.accounts.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.collectibles.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.assets.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, strformat, strutils, stint, sequtils, json_serialization, std/algorithm
|
import json, strformat, strutils, stint, sequtils, json_serialization
|
||||||
|
|
||||||
include ../../../common/json_utils
|
include ../../../common/json_utils
|
||||||
include ../../../common/utils
|
include ../../../common/utils
|
||||||
|
@ -116,12 +116,6 @@ proc toProfileShowcasePreferencesDto*(jsonObj: JsonNode): ProfileShowcasePrefere
|
||||||
for jsonMsg in jsonObj["assets"]:
|
for jsonMsg in jsonObj["assets"]:
|
||||||
result.assets.add(jsonMsg.toProfileShowcaseAssetPreference())
|
result.assets.add(jsonMsg.toProfileShowcaseAssetPreference())
|
||||||
|
|
||||||
# Sort by order as early as possible
|
|
||||||
result.communities.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.accounts.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.collectibles.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
result.assets.sort((a, b) => cmp(a.order, b.order))
|
|
||||||
|
|
||||||
proc toJsonNode*(self: ProfileShowcasePreferencesDto): JsonNode =
|
proc toJsonNode*(self: ProfileShowcasePreferencesDto): JsonNode =
|
||||||
let communities = self.communities.map(entry => entry.toJsonNode())
|
let communities = self.communities.map(entry => entry.toJsonNode())
|
||||||
let accounts = self.accounts.map(entry => entry.toJsonNode())
|
let accounts = self.accounts.map(entry => entry.toJsonNode())
|
||||||
|
|
|
@ -22,7 +22,7 @@ type
|
||||||
preferences*: ProfileShowcasePreferencesDto
|
preferences*: ProfileShowcasePreferencesDto
|
||||||
|
|
||||||
# Signals which may be emitted by this service:
|
# Signals which may be emitted by this service:
|
||||||
const SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED* = "profileShowcasePreferencesLoaded"
|
const SIGNAL_PROFILE_SHOWCASE_PREFERENCES_UPDATED* = "profileShowcasePreferencesUpdated"
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type Service* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
|
@ -110,7 +110,7 @@ QtObject:
|
||||||
|
|
||||||
let preferences = rpcResponseObj["response"]["result"].toProfileShowcasePreferencesDto()
|
let preferences = rpcResponseObj["response"]["result"].toProfileShowcasePreferencesDto()
|
||||||
|
|
||||||
self.events.emit(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED,
|
self.events.emit(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_UPDATED,
|
||||||
ProfileShowcasePreferencesArgs(preferences: preferences))
|
ProfileShowcasePreferencesArgs(preferences: preferences))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error requesting profile showcase preferences", msg = e.msg
|
error "Error requesting profile showcase preferences", msg = e.msg
|
||||||
|
|
|
@ -9,7 +9,7 @@ ProfileShowcasePanel {
|
||||||
|
|
||||||
keyRole: "symbol"
|
keyRole: "symbol"
|
||||||
roleNames: ["symbol", "name", "enabledNetworkBalance"].concat(showcaseRoles)
|
roleNames: ["symbol", "name", "enabledNetworkBalance"].concat(showcaseRoles)
|
||||||
filterFunc: (modelData) => !showcaseModel.hasItemInShowcase(modelData.symbol)
|
filterFunc: (modelData) => modelData.symbol !== "" && !showcaseModel.hasItemInShowcase(modelData.symbol)
|
||||||
hiddenPlaceholderBanner: qsTr("Assets here will show on your profile")
|
hiddenPlaceholderBanner: qsTr("Assets here will show on your profile")
|
||||||
showcasePlaceholderBanner: qsTr("Assets here will be hidden from your profile")
|
showcasePlaceholderBanner: qsTr("Assets here will be hidden from your profile")
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ Control {
|
||||||
signal showcaseEntryChanged()
|
signal showcaseEntryChanged()
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
showcaseModel.reset()
|
showcaseModel.clear()
|
||||||
updateBaseModelFilters()
|
updateBaseModelFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ Control {
|
||||||
onDropped: function(drop) {
|
onDropped: function(drop) {
|
||||||
showcaseModel.setVisibilityByIndex(drop.source.visualIndex, Constants.ShowcaseVisibility.NoOne)
|
showcaseModel.setVisibilityByIndex(drop.source.visualIndex, Constants.ShowcaseVisibility.NoOne)
|
||||||
root.showcaseEntryChanged()
|
root.showcaseEntryChanged()
|
||||||
root.updateModelsAfterChange()
|
root.updateBaseModelFilters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,11 +81,17 @@ Control {
|
||||||
visible: count
|
visible: count
|
||||||
model: SortFilterProxyModel {
|
model: SortFilterProxyModel {
|
||||||
sourceModel: root.profileStore.profileShowcaseCommunitiesModel
|
sourceModel: root.profileStore.profileShowcaseCommunitiesModel
|
||||||
filters: ValueFilter {
|
filters: [
|
||||||
roleName: "showcaseVisibility"
|
ValueFilter {
|
||||||
value: Constants.ShowcaseVisibility.NoOne
|
roleName: "showcaseVisibility"
|
||||||
inverted: true
|
value: Constants.ShowcaseVisibility.NoOne
|
||||||
}
|
inverted: true
|
||||||
|
},
|
||||||
|
ValueFilter {
|
||||||
|
roleName: "loading"
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
ScrollBar.vertical: StatusScrollBar { }
|
ScrollBar.vertical: StatusScrollBar { }
|
||||||
delegate: StatusListItem { // TODO custom delegate
|
delegate: StatusListItem { // TODO custom delegate
|
||||||
|
@ -94,8 +100,8 @@ Control {
|
||||||
title: model.name
|
title: model.name
|
||||||
statusListItemTitle.font.pixelSize: 17
|
statusListItemTitle.font.pixelSize: 17
|
||||||
statusListItemTitle.font.bold: true
|
statusListItemTitle.font.bold: true
|
||||||
//subTitle: model.description // TODO: no data in showcase model
|
subTitle: model.description
|
||||||
//tertiaryTitle: qsTr("%n member(s)", "", model.members.count) // TODO: no data in showcase model
|
tertiaryTitle: qsTr("%n member(s)", "", model.membersCount)
|
||||||
asset.name: model.image ?? model.name
|
asset.name: model.image ?? model.name
|
||||||
asset.isImage: asset.name.startsWith(Constants.dataImagePrefix)
|
asset.isImage: asset.name.startsWith(Constants.dataImagePrefix)
|
||||||
asset.isLetterIdenticon: !model.image
|
asset.isLetterIdenticon: !model.image
|
||||||
|
@ -169,7 +175,6 @@ Control {
|
||||||
components: [
|
components: [
|
||||||
StatusIcon {
|
StatusIcon {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
//visible: model.walletType === Constants.watchWalletType
|
|
||||||
icon: "show"
|
icon: "show"
|
||||||
color: Theme.palette.directColor1
|
color: Theme.palette.directColor1
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue