feat(Contacts): Show profile showcase data for contacts
This commit is contained in:
parent
c5e37382cd
commit
84f3626390
|
@ -94,7 +94,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
|
|||
result.controller = controller.newController(result)
|
||||
result.moduleLoaded = false
|
||||
|
||||
result.profileModule = profile_module.newModule(result, events, profileService, settingsService, communityService, walletAccountService)
|
||||
result.profileModule = profile_module.newModule(result, events, profileService, settingsService, communityService, walletAccountService, contactsService)
|
||||
result.contactsModule = contacts_module.newModule(result, events, contactsService, chatService)
|
||||
result.languageModule = language_module.newModule(result, events, languageService)
|
||||
result.privacyModule = privacy_module.newModule(result, events, settingsService, keychainService, privacyService, generalService)
|
||||
|
|
|
@ -7,9 +7,10 @@ import app_service/service/profile/service as profile_service
|
|||
import app_service/service/settings/service as settings_service
|
||||
import app_service/service/community/service as community_service
|
||||
import app_service/service/wallet_account/service as wallet_account_service
|
||||
import app_service/service/contacts/service as contacts_service
|
||||
import app_service/common/social_links
|
||||
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
|
@ -19,6 +20,7 @@ type
|
|||
settingsService: settings_service.Service
|
||||
communityService: community_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
contactsService: contacts_service.Service
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
|
@ -26,7 +28,8 @@ proc newController*(
|
|||
profileService: profile_service.Service,
|
||||
settingsService: settings_service.Service,
|
||||
communityService: community_service.Service,
|
||||
walletAccountService: wallet_account_service.Service): Controller =
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
contactsService: contacts_service.Service): Controller =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
result.events = events
|
||||
|
@ -34,6 +37,7 @@ proc newController*(
|
|||
result.settingsService = settingsService
|
||||
result.communityService = communityService
|
||||
result.walletAccountService = walletAccountService
|
||||
result.contactsService = contactsService
|
||||
|
||||
proc delete*(self: Controller) =
|
||||
discard
|
||||
|
@ -50,8 +54,8 @@ proc init*(self: Controller) =
|
|||
self.delegate.onSocialLinksUpdated(args.socialLinks, args.error)
|
||||
|
||||
self.events.on(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED) do(e: Args):
|
||||
let args = ProfileShowcasePreferences(e)
|
||||
self.delegate.updateProfileShowcasePreferences(args.communities, args.accounts, args.collectibles, args.assets)
|
||||
let args = ProfileShowcasePreferencesArgs(e)
|
||||
self.delegate.updateProfileShowcasePreferences(args.preferences)
|
||||
|
||||
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)
|
||||
|
@ -74,6 +78,9 @@ proc getAccountByAddress*(self: Controller, address: string): WalletAccountDto =
|
|||
proc getTokensByAddress*(self: Controller, address: string): seq[WalletTokenDto] =
|
||||
return self.walletAccountService.getTokensByAddress(address)
|
||||
|
||||
proc getContactById*(self: Controller, id: string): ContactsDto =
|
||||
return self.contactsService.getContactById(id)
|
||||
|
||||
proc setSocialLinks*(self: Controller, links: SocialLinks) =
|
||||
self.settingsService.setSocialLinks(links)
|
||||
|
||||
|
@ -83,13 +90,8 @@ proc getBio*(self: Controller): string =
|
|||
proc setBio*(self: Controller, bio: string): bool =
|
||||
self.settingsService.saveBio(bio)
|
||||
|
||||
proc storeProfileShowcasePreferences*(self: Controller, communities, accounts, collectibles, assets: seq[ProfileShowcaseEntryDto]) =
|
||||
self.profileService.setProfileShowcasePreferences(ProfileShowcasePreferences(
|
||||
communities: communities,
|
||||
accounts: accounts,
|
||||
collectibles: collectibles,
|
||||
assets: assets
|
||||
))
|
||||
proc storeProfileShowcasePreferences*(self: Controller, preferences: ProfileShowcasePreferencesDto) =
|
||||
self.profileService.setProfileShowcasePreferences(preferences)
|
||||
|
||||
proc requestProfileShowcasePreferences*(self: Controller) =
|
||||
self.profileService.requestProfileShowcasePreferences()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml
|
||||
|
||||
import app_service/common/social_links
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
import models/profile_preferences_community_item
|
||||
import models/profile_preferences_account_item
|
||||
|
@ -58,7 +58,10 @@ method storeProfileShowcasePreferences*(self: AccessInterface,
|
|||
method requestProfileShowcasePreferences*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method updateProfileShowcasePreferences*(self: AccessInterface, communities, accounts, collectibles, assets: seq[ProfileShowcaseEntryDto]) {.base.} =
|
||||
method requestProfileShowcase*(self: AccessInterface, publicKey: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method updateProfileShowcasePreferences*(self: AccessInterface, preferences: ProfileShowcasePreferencesDto) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
# View Delegate Interface
|
||||
|
|
|
@ -2,8 +2,7 @@ import json, strutils, stint, json_serialization, tables
|
|||
|
||||
import profile_preferences_base_item
|
||||
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/wallet_account/dto/account_dto
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
include app_service/common/json_utils
|
||||
include app_service/common/utils
|
||||
|
@ -13,24 +12,32 @@ type
|
|||
address*: string
|
||||
name*: string
|
||||
emoji*: string
|
||||
walletType*: string
|
||||
colorId*: string
|
||||
|
||||
proc initProfileShowcaseAccountItem*(account: WalletAccountDto, entry: ProfileShowcaseEntryDto): ProfileShowcaseAccountItem =
|
||||
proc initProfileShowcaseAccountItem*(
|
||||
address: string,
|
||||
name: string,
|
||||
emoji: string,
|
||||
colorId: string,
|
||||
visibility: ProfileShowcaseVisibility,
|
||||
order: int): ProfileShowcaseAccountItem =
|
||||
result = ProfileShowcaseAccountItem()
|
||||
|
||||
result.showcaseVisibility = entry.showcaseVisibility
|
||||
result.order = entry.order
|
||||
|
||||
result.address = account.address
|
||||
result.name = account.name
|
||||
result.emoji = account.emoji
|
||||
result.walletType = account.walletType
|
||||
result.colorId = account.colorId
|
||||
result.address = address
|
||||
result.name = name
|
||||
result.emoji = emoji
|
||||
result.colorId = colorId
|
||||
result.showcaseVisibility = visibility
|
||||
result.order = order
|
||||
|
||||
proc toProfileShowcaseAccountItem*(jsonObj: JsonNode): ProfileShowcaseAccountItem =
|
||||
result = ProfileShowcaseAccountItem()
|
||||
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
var visibilityInt: int
|
||||
if (jsonObj.getProp("showcaseVisibility", visibilityInt) and
|
||||
|
@ -38,17 +45,13 @@ proc toProfileShowcaseAccountItem*(jsonObj: JsonNode): ProfileShowcaseAccountIte
|
|||
visibilityInt <= ord(high(ProfileShowcaseVisibility)))):
|
||||
result.showcaseVisibility = ProfileShowcaseVisibility(visibilityInt)
|
||||
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("walletType", result.walletType)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
proc toShowcasePreferenceItem*(self: ProfileShowcaseAccountItem): ProfileShowcaseAccountPreference =
|
||||
result = ProfileShowcaseAccountPreference()
|
||||
|
||||
proc getEntryDto*(self: ProfileShowcaseAccountItem): ProfileShowcaseEntryDto =
|
||||
result = ProfileShowcaseEntryDto()
|
||||
|
||||
result.id = self.address
|
||||
result.entryType = ProfileShowcaseEntryType.Account
|
||||
result.address = self.address
|
||||
result.name = self.name
|
||||
result.emoji = self.emoji
|
||||
result.colorId = self.colorId
|
||||
result.showcaseVisibility = self.showcaseVisibility
|
||||
result.order = self.order
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, tables, strutils, sequtils, json
|
||||
|
||||
import profile_preferences_account_item
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
|
@ -11,7 +11,6 @@ type
|
|||
Address
|
||||
Name
|
||||
Emoji
|
||||
WalletType
|
||||
ColorId
|
||||
|
||||
QtObject:
|
||||
|
@ -54,7 +53,6 @@ QtObject:
|
|||
|
||||
ModelRole.Address.int: "address",
|
||||
ModelRole.Name.int: "name",
|
||||
ModelRole.WalletType.int: "walletType",
|
||||
ModelRole.Emoji.int: "emoji",
|
||||
ModelRole.ColorId.int: "colorId",
|
||||
}.toTable
|
||||
|
@ -78,8 +76,6 @@ QtObject:
|
|||
result = newQVariant(item.address)
|
||||
of ModelRole.Name:
|
||||
result = newQVariant(item.name)
|
||||
of ModelRole.WalletType:
|
||||
result = newQVariant(item.walletType)
|
||||
of ModelRole.Emoji:
|
||||
result = newQVariant(item.emoji)
|
||||
of ModelRole.ColorId:
|
||||
|
@ -97,7 +93,7 @@ QtObject:
|
|||
return false
|
||||
return self.items[ind].showcaseVisibility != ProfileShowcaseVisibility.ToNoOne
|
||||
|
||||
proc baseModelFilterConditionsMayChanged*(self: ProfileShowcaseAccountsModel) {.signal.}
|
||||
proc baseModelFilterConditionsMayHaveChanged*(self: ProfileShowcaseAccountsModel) {.signal.}
|
||||
|
||||
proc appendItem*(self: ProfileShowcaseAccountsModel, item: ProfileShowcaseAccountItem) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
@ -106,7 +102,7 @@ QtObject:
|
|||
self.items.add(item)
|
||||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItemImpl(self: ProfileShowcaseAccountsModel, item: ProfileShowcaseAccountItem) =
|
||||
let ind = self.findIndexForAccount(item.address)
|
||||
|
@ -122,7 +118,6 @@ QtObject:
|
|||
ModelRole.Order.int,
|
||||
ModelRole.Address.int,
|
||||
ModelRole.Name.int,
|
||||
ModelRole.WalletType.int,
|
||||
ModelRole.Emoji.int,
|
||||
ModelRole.ColorId.int,
|
||||
])
|
||||
|
@ -130,25 +125,25 @@ QtObject:
|
|||
proc upsertItemJson(self: ProfileShowcaseAccountsModel, itemJson: string) {.slot.} =
|
||||
self.upsertItemImpl(itemJson.parseJson.toProfileShowcaseAccountItem())
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItem*(self: ProfileShowcaseAccountsModel, item: ProfileShowcaseAccountItem) =
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItems*(self: ProfileShowcaseAccountsModel, items: seq[ProfileShowcaseAccountItem]) =
|
||||
for item in items:
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc reset*(self: ProfileShowcaseAccountsModel) {.slot.} =
|
||||
self.beginResetModel()
|
||||
self.items = @[]
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc remove*(self: ProfileShowcaseAccountsModel, index: int) {.slot.} =
|
||||
if index < 0 or index >= self.items.len:
|
||||
|
@ -160,7 +155,7 @@ QtObject:
|
|||
self.items.delete(index)
|
||||
self.endRemoveRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc removeEntry*(self: ProfileShowcaseAccountsModel, address: string) {.slot.} =
|
||||
let ind = self.findIndexForAccount(address)
|
||||
|
@ -186,7 +181,7 @@ QtObject:
|
|||
let index = self.createIndex(ind, 0, nil)
|
||||
defer: index.delete
|
||||
self.dataChanged(index, index, @[ModelRole.ShowcaseVisibility.int])
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc setVisibility*(self: ProfileShowcaseAccountsModel, address: string, visibility: int) {.slot.} =
|
||||
let index = self.findIndexForAccount(address)
|
||||
|
|
|
@ -3,7 +3,7 @@ import json, strutils, stint, json_serialization, tables
|
|||
import profile_preferences_base_item
|
||||
|
||||
import app_service/service/wallet_account/dto/account_dto
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
import ../../../../shared_models/currency_amount
|
||||
|
||||
|
@ -17,18 +17,17 @@ type
|
|||
enabledNetworkBalance*: CurrencyAmount
|
||||
color*: string
|
||||
|
||||
proc initProfileShowcaseAssetItem*(token: WalletTokenDto, entry: ProfileShowcaseEntryDto): ProfileShowcaseAssetItem =
|
||||
proc initProfileShowcaseAssetItem*(token: WalletTokenDto, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseAssetItem =
|
||||
result = ProfileShowcaseAssetItem()
|
||||
|
||||
result.showcaseVisibility = entry.showcaseVisibility
|
||||
result.order = entry.order
|
||||
result.showcaseVisibility = visibility
|
||||
result.order = order
|
||||
|
||||
result.symbol = token.symbol
|
||||
result.name = token.name
|
||||
result.enabledNetworkBalance = newCurrencyAmount(token.getTotalBalanceOfSupportedChains(), token.symbol, token.decimals, false)
|
||||
result.color = token.color
|
||||
|
||||
|
||||
proc toProfileShowcaseAssetItem*(jsonObj: JsonNode): ProfileShowcaseAssetItem =
|
||||
result = ProfileShowcaseAssetItem()
|
||||
|
||||
|
@ -45,11 +44,10 @@ proc toProfileShowcaseAssetItem*(jsonObj: JsonNode): ProfileShowcaseAssetItem =
|
|||
|
||||
result.enabledNetworkBalance = jsonObj{"enabledNetworkBalance"}.toCurrencyAmount()
|
||||
|
||||
proc getEntryDto*(self: ProfileShowcaseAssetItem): ProfileShowcaseEntryDto =
|
||||
result = ProfileShowcaseEntryDto()
|
||||
proc toShowcasePreferenceItem*(self: ProfileShowcaseAssetItem): ProfileShowcaseAssetPreference =
|
||||
result = ProfileShowcaseAssetPreference()
|
||||
|
||||
result.id = self.symbol
|
||||
result.entryType = ProfileShowcaseEntryType.Asset
|
||||
result.symbol = self.symbol
|
||||
result.showcaseVisibility = self.showcaseVisibility
|
||||
result.order = self.order
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, tables, strutils, sequtils, json
|
||||
|
||||
import profile_preferences_asset_item
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
|
@ -93,7 +93,7 @@ QtObject:
|
|||
return false
|
||||
return self.items[ind].showcaseVisibility != ProfileShowcaseVisibility.ToNoOne
|
||||
|
||||
proc baseModelFilterConditionsMayChanged*(self: ProfileShowcaseAssetsModel) {.signal.}
|
||||
proc baseModelFilterConditionsMayHaveChanged*(self: ProfileShowcaseAssetsModel) {.signal.}
|
||||
|
||||
proc appendItem*(self: ProfileShowcaseAssetsModel, item: ProfileShowcaseAssetItem) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
@ -102,7 +102,7 @@ QtObject:
|
|||
self.items.add(item)
|
||||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItemImpl(self: ProfileShowcaseAssetsModel, item: ProfileShowcaseAssetItem) =
|
||||
let ind = self.findIndexForAsset(item.symbol)
|
||||
|
@ -125,25 +125,25 @@ QtObject:
|
|||
proc upsertItemJson(self: ProfileShowcaseAssetsModel, itemJson: string) {.slot.} =
|
||||
self.upsertItemImpl(itemJson.parseJson.toProfileShowcaseAssetItem())
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItem*(self: ProfileShowcaseAssetsModel, item: ProfileShowcaseAssetItem) =
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItems*(self: ProfileShowcaseAssetsModel, items: seq[ProfileShowcaseAssetItem]) =
|
||||
for item in items:
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc reset*(self: ProfileShowcaseAssetsModel) {.slot.} =
|
||||
self.beginResetModel()
|
||||
self.items = @[]
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc remove*(self: ProfileShowcaseAssetsModel, index: int) {.slot.} =
|
||||
if index < 0 or index >= self.items.len:
|
||||
|
@ -155,7 +155,7 @@ QtObject:
|
|||
self.items.delete(index)
|
||||
self.endRemoveRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc removeEntry*(self: ProfileShowcaseAssetsModel, symbol: string) {.slot.} =
|
||||
let ind = self.findIndexForAsset(symbol)
|
||||
|
@ -181,7 +181,7 @@ QtObject:
|
|||
let index = self.createIndex(ind, 0, nil)
|
||||
defer: index.delete
|
||||
self.dataChanged(index, index, @[ModelRole.ShowcaseVisibility.int])
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc setVisibility*(self: ProfileShowcaseAssetsModel, symbol: string, visibility: int) {.slot.} =
|
||||
let index = self.findIndexForAsset(symbol)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
ProfileShowcaseBaseItem* = object of RootObj
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import json, strutils, stint, json_serialization, tables
|
||||
|
||||
import profile_preferences_base_item
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
include app_service/common/json_utils
|
||||
include app_service/common/utils
|
||||
|
@ -30,11 +31,10 @@ proc toProfileShowcaseCollectibleItem*(jsonObj: JsonNode): ProfileShowcaseCollec
|
|||
discard jsonObj.getProp("imageUrl", result.imageUrl)
|
||||
discard jsonObj.getProp("backgroundColor", result.backgroundColor)
|
||||
|
||||
proc getEntryDto*(self: ProfileShowcaseCollectibleItem): ProfileShowcaseEntryDto =
|
||||
result = ProfileShowcaseEntryDto()
|
||||
proc toShowcasePreferenceItem*(self: ProfileShowcaseCollectibleItem): ProfileShowcaseCollectiblePreference =
|
||||
result = ProfileShowcaseCollectiblePreference()
|
||||
|
||||
result.id = self.uid
|
||||
result.entryType = ProfileShowcaseEntryType.Collectible
|
||||
result.uid = self.uid
|
||||
result.showcaseVisibility = self.showcaseVisibility
|
||||
result.order = self.order
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, tables, strutils, sequtils, json
|
||||
|
||||
import profile_preferences_collectible_item
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
|
@ -97,7 +97,7 @@ QtObject:
|
|||
return false
|
||||
return self.items[ind].showcaseVisibility != ProfileShowcaseVisibility.ToNoOne
|
||||
|
||||
proc baseModelFilterConditionsMayChanged*(self: ProfileShowcaseCollectiblesModel) {.signal.}
|
||||
proc baseModelFilterConditionsMayHaveChanged*(self: ProfileShowcaseCollectiblesModel) {.signal.}
|
||||
|
||||
proc appendItem*(self: ProfileShowcaseCollectiblesModel, item: ProfileShowcaseCollectibleItem) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
@ -106,7 +106,7 @@ QtObject:
|
|||
self.items.add(item)
|
||||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItemImpl(self: ProfileShowcaseCollectiblesModel, item: ProfileShowcaseCollectibleItem) =
|
||||
let ind = self.findIndexForCollectible(item.uid)
|
||||
|
@ -130,25 +130,25 @@ QtObject:
|
|||
proc upsertItemJson(self: ProfileShowcaseCollectiblesModel, itemJson: string) {.slot.} =
|
||||
self.upsertItemImpl(itemJson.parseJson.toProfileShowcaseCollectibleItem())
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItem*(self: ProfileShowcaseCollectiblesModel, item: ProfileShowcaseCollectibleItem) =
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItems*(self: ProfileShowcaseCollectiblesModel, items: seq[ProfileShowcaseCollectibleItem]) =
|
||||
for item in items:
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc reset*(self: ProfileShowcaseCollectiblesModel) {.slot.} =
|
||||
self.beginResetModel()
|
||||
self.items = @[]
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc remove*(self: ProfileShowcaseCollectiblesModel, index: int) {.slot.} =
|
||||
if index < 0 or index >= self.items.len:
|
||||
|
@ -160,7 +160,7 @@ QtObject:
|
|||
self.items.delete(index)
|
||||
self.endRemoveRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc removeEntry*(self: ProfileShowcaseCollectiblesModel, uid: string) {.slot.} =
|
||||
let ind = self.findIndexForCollectible(uid)
|
||||
|
@ -186,7 +186,7 @@ QtObject:
|
|||
let index = self.createIndex(ind, 0, nil)
|
||||
defer: index.delete
|
||||
self.dataChanged(index, index, @[ModelRole.ShowcaseVisibility.int])
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc setVisibility*(self: ProfileShowcaseCollectiblesModel, uid: string, visibility: int) {.slot.} =
|
||||
let index = self.findIndexForCollectible(uid)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml, tables, strutils, sequtils, json
|
||||
|
||||
import profile_preferences_community_item
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
|
@ -96,7 +96,7 @@ QtObject:
|
|||
return false
|
||||
return self.items[ind].showcaseVisibility != ProfileShowcaseVisibility.ToNoOne
|
||||
|
||||
proc baseModelFilterConditionsMayChanged*(self: ProfileShowcaseCommunitiesModel) {.signal.}
|
||||
proc baseModelFilterConditionsMayHaveChanged*(self: ProfileShowcaseCommunitiesModel) {.signal.}
|
||||
|
||||
proc appendItem*(self: ProfileShowcaseCommunitiesModel, item: ProfileShowcaseCommunityItem) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
@ -105,7 +105,7 @@ QtObject:
|
|||
self.items.add(item)
|
||||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItemImpl(self: ProfileShowcaseCommunitiesModel, item: ProfileShowcaseCommunityItem) =
|
||||
let ind = self.findIndexForCommunity(item.id)
|
||||
|
@ -129,25 +129,25 @@ QtObject:
|
|||
proc upsertItemJson(self: ProfileShowcaseCommunitiesModel, itemJson: string) {.slot.} =
|
||||
self.upsertItemImpl(itemJson.parseJson.toProfileShowcaseCommunityItem())
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItem*(self: ProfileShowcaseCommunitiesModel, item: ProfileShowcaseCommunityItem) =
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc upsertItems*(self: ProfileShowcaseCommunitiesModel, items: seq[ProfileShowcaseCommunityItem]) =
|
||||
for item in items:
|
||||
self.upsertItemImpl(item)
|
||||
self.recalcOrder()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc reset*(self: ProfileShowcaseCommunitiesModel) {.slot.} =
|
||||
self.beginResetModel()
|
||||
self.items = @[]
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc remove*(self: ProfileShowcaseCommunitiesModel, index: int) {.slot.} =
|
||||
if index < 0 or index >= self.items.len:
|
||||
|
@ -159,7 +159,7 @@ QtObject:
|
|||
self.items.delete(index)
|
||||
self.endRemoveRows()
|
||||
self.countChanged()
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc removeEntry*(self: ProfileShowcaseCommunitiesModel, id: string) {.slot.} =
|
||||
let ind = self.findIndexForCommunity(id)
|
||||
|
@ -185,7 +185,7 @@ QtObject:
|
|||
let index = self.createIndex(ind, 0, nil)
|
||||
defer: index.delete
|
||||
self.dataChanged(index, index, @[ModelRole.ShowcaseVisibility.int])
|
||||
self.baseModelFilterConditionsMayChanged()
|
||||
self.baseModelFilterConditionsMayHaveChanged()
|
||||
|
||||
proc setVisibility*(self: ProfileShowcaseCommunitiesModel, id: string, visibility: int) {.slot.} =
|
||||
let index = self.findIndexForCommunity(id)
|
||||
|
|
|
@ -2,8 +2,8 @@ import json, strutils, stint, json_serialization, tables
|
|||
|
||||
import profile_preferences_base_item
|
||||
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/community/dto/community
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
|
||||
include app_service/common/json_utils
|
||||
include app_service/common/utils
|
||||
|
@ -16,11 +16,11 @@ type
|
|||
image*: string
|
||||
color*: string
|
||||
|
||||
proc initProfileShowcaseCommunityItem*(community: CommunityDto, entry: ProfileShowcaseEntryDto): ProfileShowcaseCommunityItem =
|
||||
proc initProfileShowcaseCommunityItem*(community: CommunityDto, visibility: ProfileShowcaseVisibility, order: int): ProfileShowcaseCommunityItem =
|
||||
result = ProfileShowcaseCommunityItem()
|
||||
|
||||
result.showcaseVisibility = entry.showcaseVisibility
|
||||
result.order = entry.order
|
||||
result.showcaseVisibility = visibility
|
||||
result.order = order
|
||||
|
||||
result.id = community.id
|
||||
result.name = community.name
|
||||
|
@ -44,11 +44,10 @@ proc toProfileShowcaseCommunityItem*(jsonObj: JsonNode): ProfileShowcaseCommunit
|
|||
discard jsonObj.getProp("image", result.image)
|
||||
discard jsonObj.getProp("color", result.color)
|
||||
|
||||
proc getEntryDto*(self: ProfileShowcaseCommunityItem): ProfileShowcaseEntryDto =
|
||||
result = ProfileShowcaseEntryDto()
|
||||
proc toShowcasePreferenceItem*(self: ProfileShowcaseCommunityItem): ProfileShowcaseCommunityPreference =
|
||||
result = ProfileShowcaseCommunityPreference()
|
||||
|
||||
result.id = self.id
|
||||
result.entryType = ProfileShowcaseEntryType.Community
|
||||
result.communityId = self.id
|
||||
result.showcaseVisibility = self.showcaseVisibility
|
||||
result.order = self.order
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ import app_service/service/profile/service as profile_service
|
|||
import app_service/service/settings/service as settings_service
|
||||
import app_service/service/community/service as community_service
|
||||
import app_service/service/wallet_account/service as wallet_account_service
|
||||
import app_service/service/profile/dto/profile_showcase_entry
|
||||
import app_service/service/contacts/service as contacts_service
|
||||
import app_service/service/profile/dto/profile_showcase_preferences
|
||||
import app_service/common/social_links
|
||||
|
||||
import app/modules/shared_models/social_links_model
|
||||
|
@ -39,12 +40,13 @@ proc newModule*(
|
|||
profileService: profile_service.Service,
|
||||
settingsService: settings_service.Service,
|
||||
communityService: community_service.Service,
|
||||
walletAccountService: wallet_account_service.Service): Module =
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
contactsService: contacts_service.Service): Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.controller = controller.newController(result, events, profileService, settingsService, communityService, walletAccountService)
|
||||
result.controller = controller.newController(result, events, profileService, settingsService, communityService, walletAccountService, contactsService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
method delete*(self: Module) =
|
||||
|
@ -107,34 +109,77 @@ method storeProfileShowcasePreferences(self: Module,
|
|||
accounts: seq[ProfileShowcaseAccountItem],
|
||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
||||
assets: seq[ProfileShowcaseAssetItem]) =
|
||||
let communitiesDto = communities.map(item => item.getEntryDto())
|
||||
let accountsDto = accounts.map(item => item.getEntryDto())
|
||||
let collectiblesDto = collectibles.map(item => item.getEntryDto())
|
||||
let assetsDto = assets.map(item => item.getEntryDto())
|
||||
self.controller.storeProfileShowcasePreferences(communitiesDto, accountsDto, collectiblesDto, assetsDto)
|
||||
self.controller.storeProfileShowcasePreferences(ProfileShowcasePreferencesDto(
|
||||
communities: communities.map(item => item.toShowcasePreferenceItem()),
|
||||
accounts: accounts.map(item => item.toShowcasePreferenceItem()),
|
||||
collectibles: collectibles.map(item => item.toShowcasePreferenceItem()),
|
||||
assets: assets.map(item => item.toShowcasePreferenceItem())
|
||||
))
|
||||
|
||||
method requestProfileShowcasePreferences(self: Module) =
|
||||
self.controller.requestProfileShowcasePreferences()
|
||||
|
||||
method updateProfileShowcasePreferences(self: Module, communityEntries, accountEntries, collectibleEntries, assetEntries: seq[ProfileShowcaseEntryDto]) =
|
||||
method requestProfileShowcase*(self: Module, publicKey: string) =
|
||||
let contact = self.controller.getContactById(publicKey)
|
||||
|
||||
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
||||
var profileAccountItems: seq[ProfileShowcaseAccountItem] = @[]
|
||||
var profileCollectibleItems: seq[ProfileShowcaseCollectibleItem] = @[]
|
||||
var profileAssetItems: seq[ProfileShowcaseAssetItem] = @[]
|
||||
|
||||
for communityEntry in communityEntries:
|
||||
let community = self.controller.getCommunityById(communityEntry.id)
|
||||
profileCommunityItems.add(initProfileShowcaseCommunityItem(community, communityEntry))
|
||||
for communityEntry in contact.profileShowcase.communities:
|
||||
# TODO: what if we don't know such community?
|
||||
let community = self.controller.getCommunityById(communityEntry.communityId)
|
||||
profileCommunityItems.add(initProfileShowcaseCommunityItem(
|
||||
community, ProfileShowcaseVisibility.ToEveryone, communityEntry.order))
|
||||
|
||||
for accountEntry in accountEntries:
|
||||
let account = self.controller.getAccountByAddress(accountEntry.id)
|
||||
profileAccountItems.add(initProfileShowcaseAccountItem(account, accountEntry))
|
||||
for account in contact.profileShowcase.accounts:
|
||||
profileAccountItems.add(initProfileShowcaseAccountItem(
|
||||
account.address,
|
||||
account.name,
|
||||
account.emoji,
|
||||
account.colorId,
|
||||
ProfileShowcaseVisibility.ToEveryone,
|
||||
account.order
|
||||
))
|
||||
|
||||
for assetEntry in assetEntries:
|
||||
for assetEntry in contact.profileShowcase.assets:
|
||||
# TODO: need wallet api to fetch token by symbol
|
||||
for token in self.controller.getTokensByAddress(account.address):
|
||||
if assetEntry.id == token.symbol:
|
||||
profileAssetItems.add(initProfileShowcaseAssetItem(token, assetEntry))
|
||||
if assetEntry.symbol == token.symbol:
|
||||
# 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.updateProfileShowcasePreferences(profileCommunityItems, profileAccountItems, profileCollectibleItems, profileAssetItems)
|
||||
|
||||
method updateProfileShowcasePreferences(self: Module, preferences: ProfileShowcasePreferencesDto) =
|
||||
var profileCommunityItems: seq[ProfileShowcaseCommunityItem] = @[]
|
||||
var profileAccountItems: seq[ProfileShowcaseAccountItem] = @[]
|
||||
var profileCollectibleItems: seq[ProfileShowcaseCollectibleItem] = @[]
|
||||
var profileAssetItems: seq[ProfileShowcaseAssetItem] = @[]
|
||||
|
||||
for communityEntry in preferences.communities:
|
||||
let community = self.controller.getCommunityById(communityEntry.communityId)
|
||||
profileCommunityItems.add(initProfileShowcaseCommunityItem(community, communityEntry.showcaseVisibility, communityEntry.order))
|
||||
|
||||
for account in preferences.accounts:
|
||||
profileAccountItems.add(initProfileShowcaseAccountItem(
|
||||
account.address,
|
||||
account.name,
|
||||
account.emoji,
|
||||
account.colorId,
|
||||
account.showcaseVisibility,
|
||||
account.order
|
||||
))
|
||||
|
||||
for assetEntry in preferences.assets:
|
||||
# TODO: need wallet api to fetch token by symbol
|
||||
for token in self.controller.getTokensByAddress(account.address):
|
||||
if assetEntry.symbol == token.symbol:
|
||||
# NOTE: here can be intersections
|
||||
profileAssetItems.add(initProfileShowcaseAssetItem(token, assetEntry.showcaseVisibility, assetEntry.order))
|
||||
|
||||
# TODO: collectibles, need wallet api to fetch collectible by uid
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import NimQml, json, sequtils
|
||||
import NimQml, json, sequtils, chronicles
|
||||
|
||||
import io_interface
|
||||
import app/modules/shared_models/social_links_model
|
||||
import app/modules/shared_models/social_link_item
|
||||
|
||||
import app/global/global_singleton
|
||||
|
||||
import models/profile_preferences_communities_model
|
||||
import models/profile_preferences_community_item
|
||||
import models/profile_preferences_accounts_model
|
||||
|
@ -29,6 +31,7 @@ QtObject:
|
|||
profileShowcaseCollectiblesModelVariant: QVariant
|
||||
profileShowcaseAssetsModel: ProfileShowcaseAssetsModel
|
||||
profileShowcaseAssetsModelVariant: QVariant
|
||||
presentedPublicKey: string
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.QObject.delete
|
||||
|
@ -199,6 +202,10 @@ QtObject:
|
|||
read = getProfileShowcaseAssetsModel
|
||||
|
||||
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 accounts = self.profileShowcaseAccountsModel.items()
|
||||
let collectibles = self.profileShowcaseCollectiblesModel.items()
|
||||
|
@ -206,15 +213,44 @@ QtObject:
|
|||
|
||||
self.delegate.storeProfileShowcasePreferences(communities, accounts, collectibles, assets)
|
||||
|
||||
proc clearModels(self: View) {.slot.} =
|
||||
self.profileShowcaseCommunitiesModel.reset()
|
||||
self.profileShowcaseAccountsModel.reset()
|
||||
self.profileShowcaseCollectiblesModel.reset()
|
||||
self.profileShowcaseAssetsModel.reset()
|
||||
|
||||
proc requestProfileShowcase(self: View, publicKey: string) {.slot.} =
|
||||
if self.presentedPublicKey != publicKey:
|
||||
self.clearModels()
|
||||
|
||||
if publicKey == singletonInstance.userProfile.getPubKey():
|
||||
self.delegate.requestProfileShowcasePreferences()
|
||||
else:
|
||||
self.delegate.requestProfileShowcase(publicKey)
|
||||
|
||||
proc requestProfileShowcasePreferences(self: View) {.slot.} =
|
||||
if self.presentedPublicKey != singletonInstance.userProfile.getPubKey():
|
||||
self.clearModels()
|
||||
|
||||
self.delegate.requestProfileShowcasePreferences()
|
||||
|
||||
proc updateProfileShowcase*(self: View,
|
||||
presentedPublicKey: string,
|
||||
communities: seq[ProfileShowcaseCommunityItem],
|
||||
accounts: seq[ProfileShowcaseAccountItem],
|
||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
||||
assets: seq[ProfileShowcaseAssetItem]) =
|
||||
self.presentedPublicKey = presentedPublicKey
|
||||
|
||||
self.profileShowcaseCommunitiesModel.upsertItems(communities)
|
||||
self.profileShowcaseAccountsModel.upsertItems(accounts)
|
||||
self.profileShowcaseCollectiblesModel.upsertItems(collectibles)
|
||||
self.profileShowcaseAssetsModel.upsertItems(assets)
|
||||
|
||||
proc updateProfileShowcasePreferences*(self: View,
|
||||
communities: seq[ProfileShowcaseCommunityItem],
|
||||
accounts: seq[ProfileShowcaseAccountItem],
|
||||
collectibles: seq[ProfileShowcaseCollectibleItem],
|
||||
assets: seq[ProfileShowcaseAssetItem]) =
|
||||
self.profileShowcaseCommunitiesModel.upsertItems(communities)
|
||||
self.profileShowcaseAccountsModel.upsertItems(accounts)
|
||||
self.profileShowcaseCollectiblesModel.upsertItems(collectibles)
|
||||
self.profileShowcaseAssetsModel.upsertItems(assets)
|
||||
self.updateProfileShowcase(singletonInstance.userProfile.getPubKey(), communities, accounts, collectibles, assets)
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
import json, json_serialization, sugar, std/algorithm
|
||||
|
||||
include ../../../common/json_utils
|
||||
|
||||
type ProfileShowcaseCommunity* = ref object of RootObj
|
||||
communityId*: string
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseAccount* = ref object of RootObj
|
||||
address*: string
|
||||
name*: string
|
||||
colorId*: string
|
||||
emoji*: string
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseCollectible* = ref object of RootObj
|
||||
uid*: string
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseAsset* = ref object of RootObj
|
||||
symbol*: string
|
||||
order*: int
|
||||
|
||||
type ProfileShowcase* = ref object of RootObj
|
||||
communities*: seq[ProfileShowcaseCommunity]
|
||||
accounts*: seq[ProfileShowcaseAccount]
|
||||
collectibles*: seq[ProfileShowcaseCollectible]
|
||||
assets*: seq[ProfileShowcaseAsset]
|
||||
|
||||
proc toProfileShowcaseCommunity*(jsonObj: JsonNode): ProfileShowcaseCommunity =
|
||||
result = ProfileShowcaseCommunity()
|
||||
discard jsonObj.getProp("communityId", result.communityId)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
|
||||
proc toProfileShowcaseAccount*(jsonObj: JsonNode): ProfileShowcaseAccount =
|
||||
result = ProfileShowcaseAccount()
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
|
||||
proc toProfileShowcaseCollectible*(jsonObj: JsonNode): ProfileShowcaseCollectible =
|
||||
result = ProfileShowcaseCollectible()
|
||||
discard jsonObj.getProp("uid", result.uid)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
|
||||
proc toProfileShowcaseAsset*(jsonObj: JsonNode): ProfileShowcaseAsset =
|
||||
result = ProfileShowcaseAsset()
|
||||
discard jsonObj.getProp("symbol", result.symbol)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
|
||||
proc toProfileShowcase*(jsonObj: JsonNode): ProfileShowcase =
|
||||
result = ProfileShowcase()
|
||||
|
||||
for jsonMsg in jsonObj["communities"]:
|
||||
result.communities.add(jsonMsg.toProfileShowcaseCommunity())
|
||||
for jsonMsg in jsonObj["accounts"]:
|
||||
result.accounts.add(jsonMsg.toProfileShowcaseAccount())
|
||||
for jsonMsg in jsonObj["collectibles"]:
|
||||
result.collectibles.add(jsonMsg.toProfileShowcaseCollectible())
|
||||
for jsonMsg in jsonObj["assets"]:
|
||||
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))
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import json, strformat, strutils
|
||||
import ../../../common/social_links
|
||||
import ./contact_profile
|
||||
|
||||
include ../../../common/json_utils
|
||||
include ../../../common/utils
|
||||
|
@ -53,6 +54,7 @@ type ContactsDto* = object
|
|||
localNickname*: string
|
||||
bio*: string
|
||||
socialLinks*: SocialLinks
|
||||
profileShowcase*: ProfileShowcase
|
||||
image*: Images
|
||||
added*: bool
|
||||
blocked*: bool
|
||||
|
@ -167,6 +169,10 @@ proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
|
|||
if(jsonObj.getProp("socialLinks", socialLinksObj)):
|
||||
result.socialLinks = toSocialLinks(socialLinksObj)
|
||||
|
||||
var profileShowcaseObj: JsonNode
|
||||
if(jsonObj.getProp("profileShowcase", profileShowcaseObj)):
|
||||
result.profileShowcase = toProfileShowcase(profileShowcaseObj)
|
||||
|
||||
discard jsonObj.getProp("added", result.added)
|
||||
discard jsonObj.getProp("blocked", result.blocked)
|
||||
discard jsonObj.getProp("hasAddedUs", result.hasAddedUs)
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
import json, strformat, strutils, stint, json_serialization, tables
|
||||
include ../../../common/json_utils
|
||||
include ../../../common/utils
|
||||
|
||||
type ProfileShowcaseEntryType* {.pure.}= enum
|
||||
Community = 0,
|
||||
Account = 1,
|
||||
Collectible = 2,
|
||||
Asset = 3,
|
||||
|
||||
type ProfileShowcaseVisibility* {.pure.}= enum
|
||||
ToNoOne = 0,
|
||||
ToIDVerifiedContacts = 1,
|
||||
ToContacts = 2,
|
||||
ToEveryone = 3,
|
||||
|
||||
type ProfileShowcaseEntryDto* = ref object of RootObj
|
||||
id*: string
|
||||
entryType*: ProfileShowcaseEntryType
|
||||
showcaseVisibility*: ProfileShowcaseVisibility
|
||||
order*: int
|
||||
|
||||
proc `$`*(self: ProfileShowcaseEntryDto): string =
|
||||
result = fmt"""ProfileShowcaseEntryDto(
|
||||
id: {$self.id},
|
||||
entryType: {self.entryType.int},
|
||||
showcaseVisibility: {self.showcaseVisibility.int},
|
||||
order: {self.order}
|
||||
)"""
|
||||
|
||||
proc toProfileShowcaseEntryDto*(jsonObj: JsonNode): ProfileShowcaseEntryDto =
|
||||
result = ProfileShowcaseEntryDto()
|
||||
discard jsonObj.getProp("id", result.id)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
|
||||
var entryTypeInt: int
|
||||
if (jsonObj.getProp("entryType", entryTypeInt) and
|
||||
(entryTypeInt >= ord(low(ProfileShowcaseEntryType)) and
|
||||
entryTypeInt <= ord(high(ProfileShowcaseEntryType)))):
|
||||
result.entryType = ProfileShowcaseEntryType(entryTypeInt)
|
||||
|
||||
var visibilityInt: int
|
||||
if (jsonObj.getProp("showcaseVisibility", visibilityInt) and
|
||||
(visibilityInt >= ord(low(ProfileShowcaseVisibility)) and
|
||||
visibilityInt <= ord(high(ProfileShowcaseVisibility)))):
|
||||
result.showcaseVisibility = ProfileShowcaseVisibility(visibilityInt)
|
||||
|
||||
proc parseProfileShowcaseEntries*(jsonMsgs: JsonNode): seq[ProfileShowcaseEntryDto] =
|
||||
var entries: seq[ProfileShowcaseEntryDto] = @[]
|
||||
for jsonMsg in jsonMsgs:
|
||||
entries.add(jsonMsg.toProfileShowcaseEntryDto())
|
||||
return entries
|
||||
|
||||
proc toJsonNode*(self: ProfileShowcaseEntryDto): JsonNode =
|
||||
%* {
|
||||
"id": self.id,
|
||||
"entryType": self.entryType.int,
|
||||
"showcaseVisibility": self.showcaseVisibility.int,
|
||||
"order": self.order,
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
import json, strformat, strutils, stint, sequtils, json_serialization, std/algorithm
|
||||
|
||||
include ../../../common/json_utils
|
||||
include ../../../common/utils
|
||||
|
||||
type ProfileShowcaseVisibility* {.pure.}= enum
|
||||
ToNoOne = 0,
|
||||
ToIDVerifiedContacts = 1,
|
||||
ToContacts = 2,
|
||||
ToEveryone = 3,
|
||||
|
||||
type ProfileShowcaseCommunityPreference* = ref object of RootObj
|
||||
communityId*: string
|
||||
showcaseVisibility*: ProfileShowcaseVisibility
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseAccountPreference* = ref object of RootObj
|
||||
address*: string
|
||||
name*: string
|
||||
colorId*: string
|
||||
emoji*: string
|
||||
showcaseVisibility*: ProfileShowcaseVisibility
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseCollectiblePreference* = ref object of RootObj
|
||||
uid*: string
|
||||
showcaseVisibility*: ProfileShowcaseVisibility
|
||||
order*: int
|
||||
|
||||
type ProfileShowcaseAssetPreference* = ref object of RootObj
|
||||
symbol*: string
|
||||
showcaseVisibility*: ProfileShowcaseVisibility
|
||||
order*: int
|
||||
|
||||
type ProfileShowcasePreferencesDto* = ref object of RootObj
|
||||
communities*: seq[ProfileShowcaseCommunityPreference]
|
||||
accounts*: seq[ProfileShowcaseAccountPreference]
|
||||
collectibles*: seq[ProfileShowcaseCollectiblePreference]
|
||||
assets*: seq[ProfileShowcaseAssetPreference]
|
||||
|
||||
proc toProfileShowcaseVisibility*(jsonObj: JsonNode): ProfileShowcaseVisibility =
|
||||
var visibilityInt: int
|
||||
if (jsonObj.getProp("showcaseVisibility", visibilityInt) and
|
||||
(visibilityInt >= ord(low(ProfileShowcaseVisibility)) and
|
||||
visibilityInt <= ord(high(ProfileShowcaseVisibility)))):
|
||||
return ProfileShowcaseVisibility(visibilityInt)
|
||||
return ProfileShowcaseVisibility.ToNoOne
|
||||
|
||||
proc toProfileShowcaseCommunityPreference*(jsonObj: JsonNode): ProfileShowcaseCommunityPreference =
|
||||
result = ProfileShowcaseCommunityPreference()
|
||||
discard jsonObj.getProp("communityId", result.communityId)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
result.showcaseVisibility = jsonObj.toProfileShowcaseVisibility()
|
||||
|
||||
proc toJsonNode*(self: ProfileShowcaseCommunityPreference): JsonNode =
|
||||
%* {
|
||||
"communityId": self.communityId,
|
||||
"showcaseVisibility": self.showcaseVisibility.int,
|
||||
"order": self.order,
|
||||
}
|
||||
|
||||
proc toProfileShowcaseAccountPreference*(jsonObj: JsonNode): ProfileShowcaseAccountPreference =
|
||||
result = ProfileShowcaseAccountPreference()
|
||||
discard jsonObj.getProp("address", result.address)
|
||||
discard jsonObj.getProp("name", result.name)
|
||||
discard jsonObj.getProp("colorId", result.colorId)
|
||||
discard jsonObj.getProp("emoji", result.emoji)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
result.showcaseVisibility = jsonObj.toProfileShowcaseVisibility()
|
||||
|
||||
proc toJsonNode*(self: ProfileShowcaseAccountPreference): JsonNode =
|
||||
%* {
|
||||
"address": self.address,
|
||||
"name": self.name,
|
||||
"colorId": self.colorId,
|
||||
"emoji": self.emoji,
|
||||
"showcaseVisibility": self.showcaseVisibility.int,
|
||||
"order": self.order,
|
||||
}
|
||||
|
||||
proc toProfileShowcaseCollectiblePreference*(jsonObj: JsonNode): ProfileShowcaseCollectiblePreference =
|
||||
result = ProfileShowcaseCollectiblePreference()
|
||||
discard jsonObj.getProp("uid", result.uid)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
result.showcaseVisibility = jsonObj.toProfileShowcaseVisibility()
|
||||
|
||||
proc toJsonNode*(self: ProfileShowcaseCollectiblePreference): JsonNode =
|
||||
%* {
|
||||
"uid": self.uid,
|
||||
"showcaseVisibility": self.showcaseVisibility.int,
|
||||
"order": self.order,
|
||||
}
|
||||
|
||||
proc toProfileShowcaseAssetPreference*(jsonObj: JsonNode): ProfileShowcaseAssetPreference =
|
||||
result = ProfileShowcaseAssetPreference()
|
||||
discard jsonObj.getProp("symbol", result.symbol)
|
||||
discard jsonObj.getProp("order", result.order)
|
||||
result.showcaseVisibility = jsonObj.toProfileShowcaseVisibility()
|
||||
|
||||
proc toJsonNode*(self: ProfileShowcaseAssetPreference): JsonNode =
|
||||
%* {
|
||||
"symbol": self.symbol,
|
||||
"showcaseVisibility": self.showcaseVisibility.int,
|
||||
"order": self.order,
|
||||
}
|
||||
|
||||
proc toProfileShowcasePreferencesDto*(jsonObj: JsonNode): ProfileShowcasePreferencesDto =
|
||||
result = ProfileShowcasePreferencesDto()
|
||||
|
||||
for jsonMsg in jsonObj["communities"]:
|
||||
result.communities.add(jsonMsg.toProfileShowcaseCommunityPreference())
|
||||
for jsonMsg in jsonObj["accounts"]:
|
||||
result.accounts.add(jsonMsg.toProfileShowcaseAccountPreference())
|
||||
for jsonMsg in jsonObj["collectibles"]:
|
||||
result.collectibles.add(jsonMsg.toProfileShowcaseCollectiblePreference())
|
||||
for jsonMsg in jsonObj["assets"]:
|
||||
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 =
|
||||
let communities = self.communities.map(entry => entry.toJsonNode())
|
||||
let accounts = self.accounts.map(entry => entry.toJsonNode())
|
||||
let collectibles = self.collectibles.map(entry => entry.toJsonNode())
|
||||
let assets = self.assets.map(entry => entry.toJsonNode())
|
||||
|
||||
return %*[{
|
||||
"communities": communities,
|
||||
"accounts": accounts,
|
||||
"collectibles": collectibles,
|
||||
"assets": assets,
|
||||
}]
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, json, chronicles, tables, sugar, sequtils, json_serialization, std/algorithm
|
||||
import NimQml, json, chronicles, tables, sugar
|
||||
|
||||
import ../settings/service as settings_service
|
||||
import ../../../app/global/global_singleton
|
||||
|
@ -10,7 +10,7 @@ import ../../../app/core/tasks/[qt, threadpool]
|
|||
import ../../../backend/accounts as status_accounts
|
||||
|
||||
import ../accounts/dto/accounts
|
||||
import dto/profile_showcase_entry
|
||||
import dto/profile_showcase_preferences
|
||||
|
||||
include async_tasks
|
||||
|
||||
|
@ -18,11 +18,8 @@ logScope:
|
|||
topics = "profile-service"
|
||||
|
||||
type
|
||||
ProfileShowcasePreferences* = ref object of Args
|
||||
communities*: seq[ProfileShowcaseEntryDto]
|
||||
accounts*: seq[ProfileShowcaseEntryDto]
|
||||
collectibles*: seq[ProfileShowcaseEntryDto]
|
||||
assets*: seq[ProfileShowcaseEntryDto]
|
||||
ProfileShowcasePreferencesArgs* = ref object of Args
|
||||
preferences*: ProfileShowcasePreferencesDto
|
||||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED* = "profileShowcasePreferencesLoaded"
|
||||
|
@ -111,42 +108,16 @@ QtObject:
|
|||
error "Error requesting profile showcase preferences", msg = rpcResponseObj{"error"}
|
||||
return
|
||||
|
||||
let result = rpcResponseObj["response"]["result"]
|
||||
var communities = result["communities"].parseProfileShowcaseEntries()
|
||||
var accounts = result["accounts"].parseProfileShowcaseEntries()
|
||||
var collectibles = result["collectibles"].parseProfileShowcaseEntries()
|
||||
var assets = result["assets"].parseProfileShowcaseEntries()
|
||||
|
||||
# Sort by order before inserting in the model
|
||||
communities.sort((a, b) => cmp(a.order, b.order))
|
||||
accounts.sort((a, b) => cmp(a.order, b.order))
|
||||
collectibles.sort((a, b) => cmp(a.order, b.order))
|
||||
assets.sort((a, b) => cmp(a.order, b.order))
|
||||
let preferences = rpcResponseObj["response"]["result"].toProfileShowcasePreferencesDto()
|
||||
|
||||
self.events.emit(SIGNAL_PROFILE_SHOWCASE_PREFERENCES_LOADED,
|
||||
ProfileShowcasePreferences(
|
||||
communities: communities,
|
||||
accounts: accounts,
|
||||
collectibles: collectibles,
|
||||
assets: assets
|
||||
))
|
||||
ProfileShowcasePreferencesArgs(preferences: preferences))
|
||||
except Exception as e:
|
||||
error "Error requesting profile showcase preferences", msg = e.msg
|
||||
|
||||
proc setProfileShowcasePreferences*(self: Service, preferences: ProfileShowcasePreferences) =
|
||||
proc setProfileShowcasePreferences*(self: Service, preferences: ProfileShowcasePreferencesDto) =
|
||||
try:
|
||||
let communities = preferences.communities.map(entry => entry.toJsonNode())
|
||||
let accounts = preferences.accounts.map(entry => entry.toJsonNode())
|
||||
let collectibles = preferences.collectibles.map(entry => entry.toJsonNode())
|
||||
let assets = preferences.assets.map(entry => entry.toJsonNode())
|
||||
|
||||
var payload = %*[{
|
||||
"communities": communities,
|
||||
"accounts": accounts,
|
||||
"collectibles": collectibles,
|
||||
"assets": assets,
|
||||
}]
|
||||
let response = status_accounts.setProfileShowcasePreferences(payload)
|
||||
let response = status_accounts.setProfileShowcasePreferences(preferences.toJsonNode())
|
||||
if not response.error.isNil:
|
||||
error "error saving profile showcase preferences"
|
||||
except Exception as e:
|
||||
|
|
|
@ -47,7 +47,7 @@ Control {
|
|||
readonly property Connections showcaseUpdateConnections: Connections {
|
||||
target: showcaseModel
|
||||
|
||||
function onBaseModelFilterConditionsMayChanged() {
|
||||
function onBaseModelFilterConditionsMayHaveChanged() {
|
||||
root.updateBaseModelFilters()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,4 +101,8 @@ QtObject {
|
|||
function requestProfileShowcasePreferences() {
|
||||
root.profileModule.requestProfileShowcasePreferences()
|
||||
}
|
||||
|
||||
function requestProfileShowcase(publicKey) {
|
||||
root.profileModule.requestProfileShowcase(publicKey)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -693,7 +693,7 @@ Pane {
|
|||
Layout.preferredHeight: 300
|
||||
|
||||
currentTabIndex: showcaseTabBar.currentIndex
|
||||
isCurrentUser: d.isCurrentUser
|
||||
publicKey: root.publicKey
|
||||
mainDisplayName: d.mainDisplayName
|
||||
readOnly: root.readOnly
|
||||
profileStore: root.profileStore
|
||||
|
|
|
@ -18,7 +18,8 @@ Control {
|
|||
id: root
|
||||
|
||||
property alias currentTabIndex: stackLayout.currentIndex
|
||||
property bool isCurrentUser
|
||||
|
||||
property string publicKey
|
||||
property string mainDisplayName
|
||||
property bool readOnly
|
||||
property var profileStore
|
||||
|
@ -27,6 +28,8 @@ Control {
|
|||
|
||||
signal closeRequested()
|
||||
|
||||
onVisibleChanged: if (visible) profileStore.requestProfileShowcase(publicKey)
|
||||
|
||||
horizontalPadding: readOnly ? 20 : 40 // smaller in settings/preview
|
||||
topPadding: Style.current.bigPadding
|
||||
|
||||
|
@ -77,21 +80,12 @@ Control {
|
|||
cellHeight: cellWidth/2
|
||||
visible: count
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: root.isCurrentUser ? root.communitiesModel : null // TODO show other users too
|
||||
sourceModel: root.profileStore.profileShowcaseCommunitiesModel
|
||||
filters: ValueFilter {
|
||||
roleName: "joined"
|
||||
value: true
|
||||
roleName: "showcaseVisibility"
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
inverted: true
|
||||
}
|
||||
sorters: [
|
||||
RoleSorter {
|
||||
roleName: "memberRole"
|
||||
sortOrder: Qt.DescendingOrder // admin first
|
||||
},
|
||||
StringSorter {
|
||||
roleName: "name"
|
||||
caseSensitivity: Qt.CaseInsensitive
|
||||
}
|
||||
]
|
||||
}
|
||||
ScrollBar.vertical: StatusScrollBar { }
|
||||
delegate: StatusListItem { // TODO custom delegate
|
||||
|
@ -100,8 +94,8 @@ Control {
|
|||
title: model.name
|
||||
statusListItemTitle.font.pixelSize: 17
|
||||
statusListItemTitle.font.bold: true
|
||||
subTitle: model.description
|
||||
tertiaryTitle: qsTr("%n member(s)", "", model.members.count)
|
||||
//subTitle: model.description // TODO: no data in showcase model
|
||||
//tertiaryTitle: qsTr("%n member(s)", "", model.members.count) // TODO: no data in showcase model
|
||||
asset.name: model.image ?? model.name
|
||||
asset.isImage: asset.name.startsWith(Constants.dataImagePrefix)
|
||||
asset.isLetterIdenticon: !model.image
|
||||
|
@ -150,10 +144,10 @@ Control {
|
|||
spacing: Style.current.halfPadding
|
||||
visible: count
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: root.isCurrentUser ? root.walletStore.accounts : null // TODO show other users too
|
||||
filters: ValueFilter { // everything except keycards
|
||||
roleName: "walletType"
|
||||
value: Constants.keyWalletType
|
||||
sourceModel: root.profileStore.profileShowcaseAccountsModel
|
||||
filters: ValueFilter {
|
||||
roleName: "showcaseVisibility"
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
inverted: true
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +169,7 @@ Control {
|
|||
components: [
|
||||
StatusIcon {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: model.walletType === Constants.watchWalletType
|
||||
//visible: model.walletType === Constants.watchWalletType
|
||||
icon: "show"
|
||||
color: Theme.palette.directColor1
|
||||
},
|
||||
|
@ -249,7 +243,14 @@ Control {
|
|||
cellHeight: cellWidth
|
||||
visible: count
|
||||
// TODO Issue #11637: Dedicated controller for user's list of collectibles (no watch-only entries)
|
||||
model: root.isCurrentUser ? root.walletStore.ownedCollectibles : null
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: root.profileStore.profileShowcaseCollectiblesModel
|
||||
filters: ValueFilter {
|
||||
roleName: "showcaseVisibility"
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
inverted: true
|
||||
}
|
||||
}
|
||||
ScrollBar.vertical: StatusScrollBar { }
|
||||
delegate: StatusRoundedImage {
|
||||
width: GridView.view.cellWidth - Style.current.smallPadding
|
||||
|
@ -336,16 +337,12 @@ Control {
|
|||
cellHeight: cellWidth/2.5
|
||||
visible: count
|
||||
model: SortFilterProxyModel {
|
||||
// TODO show assets for all accounts, not just the current one?
|
||||
sourceModel: root.isCurrentUser ? root.walletStore.assets : null // TODO show other users too
|
||||
sorters: [
|
||||
StringSorter {
|
||||
roleName: "name"
|
||||
},
|
||||
StringSorter {
|
||||
roleName: "symbol"
|
||||
}
|
||||
]
|
||||
sourceModel: root.profileStore.profileShowcaseAssetsModel
|
||||
filters: ValueFilter {
|
||||
roleName: "showcaseVisibility"
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
inverted: true
|
||||
}
|
||||
}
|
||||
ScrollBar.vertical: StatusScrollBar { }
|
||||
delegate: StatusListItem {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d909faf5044be563c0c7b2637fd2afa5ffe8e6e9
|
||||
Subproject commit 1f6681a158f5a78e43f4f71d5f614524a3c524d6
|
Loading…
Reference in New Issue