Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import app_service/service/node_configuration/service as node_configuration_serv
import app_service/service/network/service as network_service
import app_service/service/activity_center/service as activity_center_service
import app_service/service/saved_address/service as saved_address_service
import app_service/service/following_address/service as following_address_service
import app_service/service/devices/service as devices_service
import app_service/service/mailservers/service as mailservers_service
import app_service/service/gif/service as gif_service
Expand Down Expand Up @@ -89,6 +90,7 @@ type
privacyService: privacy_service.Service
nodeConfigurationService: node_configuration_service.Service
savedAddressService: saved_address_service.Service
followingAddressService: following_address_service.Service
devicesService: devices_service.Service
mailserversService: mailservers_service.Service
nodeService: node_service.Service
Expand Down Expand Up @@ -211,6 +213,8 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.accountsService)
result.savedAddressService = saved_address_service.newService(statusFoundation.threadpool, statusFoundation.events,
result.networkService, result.settingsService)
result.followingAddressService = following_address_service.newService(statusFoundation.threadpool, statusFoundation.events,
result.networkService)
result.devicesService = devices_service.newService(statusFoundation.events, statusFoundation.threadpool,
result.settingsService, result.accountsService, result.walletAccountService)
result.mailserversService = mailservers_service.newService(statusFoundation.events, statusFoundation.threadpool,
Expand Down Expand Up @@ -262,6 +266,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.stickersService,
result.activityCenterService,
result.savedAddressService,
result.followingAddressService,
result.nodeConfigurationService,
result.devicesService,
result.mailserversService,
Expand Down Expand Up @@ -386,6 +391,7 @@ proc load(self: AppController) =
self.stickersService.init()
self.activityCenterService.init()
self.savedAddressService.init()
self.followingAddressService.init()
self.aboutService.init()
self.ensService.init()
self.tokensService.init()
Expand Down
6 changes: 5 additions & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import app_service/service/privacy/service as privacy_service
import app_service/service/stickers/service as stickers_service
import app_service/service/activity_center/service as activity_center_service
import app_service/service/saved_address/service as saved_address_service
import app_service/service/following_address/service as following_address_service
import app_service/service/node/service as node_service
import app_service/service/node_configuration/service as node_configuration_service
import app_service/service/devices/service as devices_service
Expand Down Expand Up @@ -100,6 +101,7 @@ type
accountsService: accounts_service.Service
walletAccountService: wallet_account_service.Service
savedAddressService: saved_address_service.Service
followingAddressService: following_address_service.Service
networkConnectionService: network_connection_service.Service
stickersService: stickers_service.Service
communityTokensService: community_tokens_service.Service
Expand Down Expand Up @@ -159,6 +161,7 @@ proc newModule*[T](
stickersService: stickers_service.Service,
activityCenterService: activity_center_service.Service,
savedAddressService: saved_address_service.Service,
followingAddressService: following_address_service.Service,
nodeConfigurationService: node_configuration_service.Service,
devicesService: devices_service.Service,
mailserversService: mailservers_service.Service,
Expand Down Expand Up @@ -212,6 +215,7 @@ proc newModule*[T](
result.accountsService = accountsService
result.walletAccountService = walletAccountService
result.savedAddressService = savedAddressService
result.followingAddressService = followingAddressService
result.stickersService = stickersService
result.communityTokensService = communityTokensService

Expand All @@ -220,7 +224,7 @@ proc newModule*[T](
result.walletSectionModule = wallet_section_module.newModule(
result, events, tokenService, collectibleService, currencyService,
rampService, transactionService, walletAccountService,
settingsService, savedAddressService, networkService, accountsService,
settingsService, savedAddressService, followingAddressService, networkService, accountsService,
keycardService, nodeService, networkConnectionService, devicesService,
communityTokensService, threadpool
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import io_interface, chronicles
import app/core/eventemitter
import app_service/service/following_address/service as following_address_service

logScope:
topics = "following-addresses-controller"

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
followingAddressService: following_address_service.Service

proc newController*(
delegate: io_interface.AccessInterface,
events: EventEmitter,
followingAddressService: following_address_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.followingAddressService = followingAddressService

proc delete*(self: Controller) =
discard

proc init*(self: Controller) =
self.events.on(following_address_service.SIGNAL_FOLLOWING_ADDRESSES_UPDATED) do(e:Args):
let args = following_address_service.FollowingAddressesArgs(e)
self.delegate.loadFollowingAddresses(args.userAddress)

proc getFollowingAddresses*(self: Controller, userAddress: string): seq[following_address_service.FollowingAddressDto] =
return self.followingAddressService.getFollowingAddresses(userAddress)

proc fetchFollowingAddresses*(self: Controller, userAddress: string, search: string = "", limit: int = 10, offset: int = 0) =
self.followingAddressService.fetchFollowingAddresses(userAddress, search, limit, offset)

proc getTotalFollowingCount*(self: Controller): int =
return self.followingAddressService.getTotalFollowingCount()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.

method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method load*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method loadFollowingAddresses*(self: AccessInterface, userAddress: string) {.base.} =
raise newException(ValueError, "No implementation available")

method fetchFollowingAddresses*(self: AccessInterface, userAddress: string, search: string = "", limit: int = 10, offset: int = 0) {.base.} =
raise newException(ValueError, "No implementation available")

method getTotalFollowingCount*(self: AccessInterface): int {.base.} =
raise newException(ValueError, "No implementation available")

type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import stew/shims/strformat

type
Item* = object
address: string
ensName: string
tags: seq[string]
avatar: string

proc initItem*(
address: string,
ensName: string,
tags: seq[string],
avatar: string
): Item =
result.address = address
result.ensName = ensName
result.tags = tags
result.avatar = avatar

proc `$`*(self: Item): string =
result = fmt"""FollowingAddressItem(
address: {self.address},
ensName: {self.ensName},
tags: {self.tags},
avatar: {self.avatar},
]"""

proc isEmpty*(self: Item): bool =
return self.address.len == 0

proc getAddress*(self: Item): string =
return self.address

proc getEnsName*(self: Item): string =
return self.ensName

proc getTags*(self: Item): seq[string] =
return self.tags

proc getName*(self: Item): string =
# Use ENS name if available, otherwise use address
if self.ensName.len > 0:
return self.ensName
return self.address

proc getAvatar*(self: Item): string =
return self.avatar
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import nimqml, tables, strutils, stew/shims/strformat, chronicles

import item

export item

logScope:
topics = "following-addresses-model"

type
ModelRole {.pure.} = enum
Address = UserRole + 1,
EnsName,
Tags,
Name,
Avatar

QtObject:
type
Model* = ref object of QAbstractListModel
items: seq[Item]

proc delete(self: Model) =
self.QAbstractListModel.delete

proc setup(self: Model) =
self.QAbstractListModel.setup

proc newModel*(): Model =
new(result, delete)
result.setup

proc `$`*(self: Model): string =
for i in 0 ..< self.items.len:
result &= fmt"""[{i}]:({$self.items[i]})"""

proc countChanged(self: Model) {.signal.}

proc getCount*(self: Model): int {.slot.} =
self.items.len

QtProperty[int] count:
read = getCount
notify = countChanged

method rowCount(self: Model, index: QModelIndex = nil): int =
return self.items.len

method roleNames(self: Model): Table[int, string] =
{
ModelRole.Address.int:"address",
ModelRole.EnsName.int:"ensName",
ModelRole.Tags.int:"tags",
ModelRole.Name.int:"name",
ModelRole.Avatar.int:"avatar",
}.toTable

method data(self: Model, index: QModelIndex, role: int): QVariant =
if (not index.isValid):
return

if (index.row < 0 or index.row >= self.items.len):
return

let item = self.items[index.row]
let enumRole = role.ModelRole

case enumRole:
of ModelRole.Address:
result = newQVariant(item.getAddress())
of ModelRole.EnsName:
result = newQVariant(item.getEnsName())
of ModelRole.Tags:
result = newQVariant(item.getTags().join(","))
of ModelRole.Name:
result = newQVariant(item.getName())
of ModelRole.Avatar:
result = newQVariant(item.getAvatar())

proc setItems*(self: Model, items: seq[Item]) =
self.beginResetModel()
self.items = items
self.endResetModel()

proc getItemByAddress*(self: Model, address: string): Item =
if address.len == 0:
return
for item in self.items:
if cmpIgnoreCase(item.getAddress(), address) == 0:
return item
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import nimqml, sugar, sequtils, chronicles
import ../io_interface as delegate_interface

import app/global/global_singleton
import app/core/eventemitter
import app_service/service/following_address/service as following_address_service

import io_interface, view, controller, model, item

export io_interface

logScope:
topics = "following-addresses-module"

type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
moduleLoaded: bool
controller: Controller

proc newModule*(
delegate: delegate_interface.AccessInterface,
events: EventEmitter,
followingAddressService: following_address_service.Service,
): Module =
result = Module()
result.delegate = delegate
result.view = newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = newController(result, events, followingAddressService)
result.moduleLoaded = false

method delete*(self: Module) =
self.viewVariant.delete
self.view.delete

method loadFollowingAddresses*(self: Module, userAddress: string) =
let followingAddresses = self.controller.getFollowingAddresses(userAddress)
self.view.setItems(
followingAddresses.map(f => initItem(
f.address,
f.ensName,
f.tags,
f.avatar,
))
)
self.view.totalFollowingCountChanged()
self.view.followingAddressesUpdated(userAddress)

method load*(self: Module) =
try:
singletonInstance.engine.setRootContextProperty("walletSectionFollowingAddresses", self.viewVariant)
self.controller.init()
self.view.load()
except Exception as e:
error "following_addresses load() failed", msg=e.msg

method isLoaded*(self: Module): bool =
return self.moduleLoaded

method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.followingAddressesModuleDidLoad()

method fetchFollowingAddresses*(self: Module, userAddress: string, search: string = "", limit: int = 10, offset: int = 0) =
self.controller.fetchFollowingAddresses(userAddress, search, limit, offset)

method getTotalFollowingCount*(self: Module): int =
return self.controller.getTotalFollowingCount()
Loading
Loading