Skip to content

Commit

Permalink
feat(Contacts): Show profile showcase data for contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev authored and jrainville committed Nov 9, 2023
1 parent c5e3738 commit 84f3626
Show file tree
Hide file tree
Showing 24 changed files with 459 additions and 255 deletions.
2 changes: 1 addition & 1 deletion src/app/modules/main/profile_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 13 additions & 11 deletions src/app/modules/main/profile_section/profile/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,21 +20,24 @@ type
settingsService: settings_service.Service
communityService: community_service.Service
walletAccountService: wallet_account_service.Service
contactsService: contacts_service.Service

proc newController*(
delegate: io_interface.AccessInterface,
events: EventEmitter,
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
result.profileService = profileService
result.settingsService = settingsService
result.communityService = communityService
result.walletAccountService = walletAccountService
result.contactsService = contactsService

proc delete*(self: Controller) =
discard
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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()
7 changes: 5 additions & 2 deletions src/app/modules/main/profile_section/profile/io_interface.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,42 +12,46 @@ 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
(visibilityInt >= ord(low(ProfileShowcaseVisibility)) and
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 getEntryDto*(self: ProfileShowcaseAccountItem): ProfileShowcaseEntryDto =
result = ProfileShowcaseEntryDto()
proc toShowcasePreferenceItem*(self: ProfileShowcaseAccountItem): ProfileShowcaseAccountPreference =
result = ProfileShowcaseAccountPreference()

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +11,6 @@ type
Address
Name
Emoji
WalletType
ColorId

QtObject:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -122,33 +118,32 @@ QtObject:
ModelRole.Order.int,
ModelRole.Address.int,
ModelRole.Name.int,
ModelRole.WalletType.int,
ModelRole.Emoji.int,
ModelRole.ColorId.int,
])

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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand All @@ -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

Expand Down
Loading

0 comments on commit 84f3626

Please sign in to comment.