Community section as an identified module's type is removed since community

section is nothing else but the special kind of chat section module type. The
rest of the code is updated accordingly.
This commit is contained in:
Sale Djenic 2021-10-18 12:07:18 +02:00 committed by Iuri Matias
parent 05705f219d
commit cc20c234e0
28 changed files with 114 additions and 186 deletions

View File

@ -57,10 +57,11 @@ proc newAppController*(status: Status, appService: AppService): AppController =
# Services
result.contactService = contact_service.newService()
result.chatService = chat_service.newService()
result.communityService = community_service.newService()
result.communityService = community_service.newService(result.chatService)
# Modules
result.startupModule = startup_module.newModule[AppController](result)
result.mainModule = main_module.newModule[AppController](result, result.communityService)
result.mainModule = main_module.newModule[AppController](result, result.chatService,
result.communityService)
# Adding status and appService here now is just because of having a controll
# over order of execution while we integrating this refactoring architecture

View File

@ -11,15 +11,17 @@ type
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
id: string
isCommunityModule: bool
communityService: community_service.ServiceInterface
proc newController*(delegate: io_interface.AccessInterface,
id: string,
id: string, isCommunity: bool,
communityService: community_service.ServiceInterface):
Controller =
result = Controller()
result.delegate = delegate
result.id = id
result.isCommunityModule = isCommunity
result.communityService = communityService
method delete*(self: Controller) =
@ -31,5 +33,8 @@ method init*(self: Controller) =
method getId*(self: Controller): string =
return self.id
method getCommunities*(self: Controller): seq[community_service.Dto] =
method isCommunity*(self: Controller): bool =
return self.isCommunityModule
method getCommunities*(self: Controller): seq[community_service.CommunityDto] =
return self.communityService.getCommunities()

View File

@ -13,6 +13,10 @@ method init*(self: AccessInterface) {.base.} =
method getId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunities*(self: AccessInterface): seq[community_service.Dto] {.base.} =
method isCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunities*(self: AccessInterface):
seq[community_service.CommunityDto] {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,6 +1,10 @@
import NimQml
import io_interface
import ../io_interface as delegate_interface
import view
import view, controller
import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/community/service as community_service
export io_interface
@ -8,16 +12,26 @@ type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface): Module =
proc newModule*(delegate: delegate_interface.AccessInterface, id: string,
isCommunity: bool, chatService: chat_service.Service,
communityService: community_service.Service):
Module =
result = Module()
result.delegate = delegate
result.view = newView(result)
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, isCommunity,
communityService)
result.moduleLoaded = false
method delete*(self: Module) =
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*(self: Module) =
self.view.load()
@ -27,4 +41,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.chatSectionDidLoad()
if(self.controller.isCommunity()):
self.delegate.communitySectionDidLoad()
else:
self.delegate.chatSectionDidLoad()

View File

@ -7,7 +7,7 @@ QtObject:
View* = ref object of QObject
delegate: io_interface.AccessInterface
model: Model
proc delete*(self: View) =
self.model.delete
self.QObject.delete

View File

@ -1,12 +0,0 @@
# Defines how parent module accesses this module
include ./private_interfaces/module_base_interface
include ./private_interfaces/module_access_interface
# Defines how this module view communicates with this module
include ./private_interfaces/module_view_delegate_interface
# Defines how this controller communicates with this module
include ./private_interfaces/module_controller_delegate_interface
# Defines how submodules of this module communicate with this module
# will be added if needed

View File

@ -1,21 +0,0 @@
import NimQml
QtObject:
type
Item* = ref object of QObject
proc setup(self: Item) =
self.QObject.setup
proc delete*(self: Item) =
self.QObject.delete
proc newItem*(): Item =
new(result, delete)
result.setup()
proc id*(self: Item): string {.slot.} =
self.id
QtProperty[string] id:
read = id

View File

@ -1,17 +0,0 @@
import NimQml
import item
QtObject:
type
Model* = ref object of QAbstractListModel
sections: seq[Item]
proc setup(self: Model) =
self.QAbstractListModel.setup
proc delete*(self: Model) =
self.QAbstractListModel.delete
proc newModel*(): Model =
new(result, delete)
result.setup

View File

@ -1,41 +0,0 @@
import NimQml
import io_interface
import ../io_interface as delegate_interface
import view, controller
import ../../../../app_service/service/community/service as community_service
export io_interface
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, id: string,
communityService: community_service.Service):
Module =
result = Module()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, communityService)
result.moduleLoaded = false
method delete*(self: Module) =
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*(self: Module) =
self.view.load()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.communitySectionDidLoad()

View File

@ -1,8 +0,0 @@
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")

View File

@ -1,5 +0,0 @@
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
# Since nim doesn't support using concepts in second level nested types we
# define delegate interfaces within access interface.

View File

@ -1,2 +0,0 @@
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,22 +0,0 @@
import NimQml
import model
import io_interface
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
model: Model
proc delete*(self: View) =
self.model.delete
self.QObject.delete
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.QObject.setup
result.delegate = delegate
result.model = newModel()
proc load*(self: View) =
self.delegate.viewDidLoad()

View File

@ -25,5 +25,5 @@ method delete*(self: Controller) =
method init*(self: Controller) =
discard
method getCommunities*(self: Controller): seq[community_service.Dto] =
method getCommunities*(self: Controller): seq[community_service.CommunityDto] =
return self.communityService.getCommunities()

View File

@ -10,5 +10,6 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunities*(self: AccessInterface): seq[community_service.Dto] {.base.} =
method getCommunities*(self: AccessInterface):
seq[community_service.CommunityDto] {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -2,6 +2,7 @@ import json, strformat
type
Item* = object
sectionType: int
id: string
name: string
image: string
@ -10,9 +11,10 @@ type
mentionsCount: int
unviewedMessagesCount: int
proc initItem*(id, name, image, icon, color: string,
proc initItem*(id: string, sectionType: int, name, image, icon, color: string,
mentionsCount, unviewedMessagesCount: int): Item =
result.id = id
result.sectionType = sectionType
result.name = name
result.image = image
result.icon = icon
@ -23,6 +25,7 @@ proc initItem*(id, name, image, icon, color: string,
proc `$`*(self: Item): string =
result = fmt"""MainModuleItem(
id: {self.id},
sectionType: {self.sectionType},
name: {self.name},
image: {self.image},
icon: {self.icon},
@ -34,6 +37,9 @@ proc `$`*(self: Item): string =
proc getId*(self: Item): string =
return self.id
proc getSectionType*(self: Item): int =
return self.sectionType
proc getName*(self: Item): string =
return self.name

View File

@ -5,6 +5,7 @@ import item
type
ModelRole {.pure.} = enum
Id = UserRole + 1
SectionType
Name
Image
Icon
@ -49,6 +50,7 @@ QtObject:
method roleNames(self: Model): Table[int, string] =
{
ModelRole.Id.int:"id",
ModelRole.SectionType.int:"sectionType",
ModelRole.Name.int:"name",
ModelRole.Image.int:"image",
ModelRole.Icon.int:"icon",
@ -70,6 +72,8 @@ QtObject:
case enumRole:
of ModelRole.Id:
result = newQVariant(item.getId())
of ModelRole.SectionType:
result = newQVariant(item.getSectionType())
of ModelRole.Name:
result = newQVariant(item.getName())
of ModelRole.Image:

View File

@ -4,12 +4,22 @@ import io_interface, view, controller, item
import ../../../app/boot/global_singleton
import chat_section/module as chat_section_module
import community_section/module as community_section_module
import ../../../app_service/service/chat/service as chat_service
import ../../../app_service/service/community/service as community_service
export io_interface
type
ChatSectionType* {.pure.} = enum
Chat = 0
Community,
Wallet,
Browser,
Timeline,
NodeManagement,
ProfileSettings
type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
delegate: T
@ -17,9 +27,10 @@ type
viewVariant: QVariant
controller: controller.AccessInterface
chatSectionModule: chat_section_module.AccessInterface
communitySectionsModule: OrderedTable[string, community_section_module.AccessInterface]
communitySectionsModule: OrderedTable[string, chat_section_module.AccessInterface]
proc newModule*[T](delegate: T,
chatService: chat_service.Service,
communityService: community_service.Service):
Module[T] =
result = Module[T]()
@ -31,12 +42,13 @@ proc newModule*[T](delegate: T,
singletonInstance.engine.setRootContextProperty("mainModule", result.viewVariant)
# Submodules
result.chatSectionModule = chat_section_module.newModule(result)
result.communitySectionsModule = initOrderedTable[string, community_section_module.AccessInterface]()
result.chatSectionModule = chat_section_module.newModule(result, "chat",
false, chatService, communityService)
result.communitySectionsModule = initOrderedTable[string, chat_section_module.AccessInterface]()
let communities = result.controller.getCommunities()
for c in communities:
result.communitySectionsModule[c.id] = community_section_module.newModule(result,
c.id, communityService)
result.communitySectionsModule[c.id] = chat_section_module.newModule(result,
c.id, true, chatService, communityService)
method delete*[T](self: Module[T]) =
self.chatSectionModule.delete
@ -50,12 +62,13 @@ method delete*[T](self: Module[T]) =
method load*[T](self: Module[T]) =
self.view.load()
let chatSectionItem = initItem("chat", "Chat", "", "chat", "", 0, 0)
let chatSectionItem = initItem("chat", ChatSectionType.Chat.int, "Chat", "",
"chat", "", 0, 0)
self.view.addItem(chatSectionItem)
let communities = self.controller.getCommunities()
for c in communities:
self.view.addItem(initItem(c.id, c.name,
self.view.addItem(initItem(c.id, ChatSectionType.Community.int, c.name,
if not c.images.isNil: c.images.thumbnail else: "",
"", c.color, 0, 0))

View File

@ -2,7 +2,7 @@
import json, strformat
include ../../common/json_utils
include ../../../common/json_utils
type ChatType* {.pure.}= enum
Unknown = 0,
@ -13,7 +13,7 @@ type ChatType* {.pure.}= enum
Timeline = 5
CommunityChat = 6
type Dto* = ref object
type ChatDto* = ref object
id*: string # ID is the id of the chat, for public chats it is the name e.g. status,
# for one-to-one is the hex encoded public key and for group chats is a random
# uuid appended with the hex encoded pk of the creator of the chat
@ -41,7 +41,7 @@ type Dto* = ref object
syncedTo*: int64
syncedFrom*: int64
proc `$`*(self: Dto): string =
proc `$`*(self: ChatDto): string =
result = fmt"""ChatDto(
id: {self.id},
name: {self.name},
@ -65,8 +65,8 @@ proc `$`*(self: Dto): string =
syncedFrom: {self.syncedFrom}
)"""
proc toDto*(jsonObj: JsonNode): Dto =
result = Dto()
proc toChatDto*(jsonObj: JsonNode): ChatDto =
result = ChatDto()
discard jsonObj.getProp("id", result.id)
discard jsonObj.getProp("name", result.name)
discard jsonObj.getProp("description", result.description)

View File

@ -1,6 +1,6 @@
import Tables, json, sequtils, strformat, chronicles
import service_interface, dto
import service_interface, ./dto/chat
import status/statusgo_backend_new/chat as status_go
export service_interface
@ -10,21 +10,21 @@ logScope:
type
Service* = ref object of ServiceInterface
chats: Table[string, Dto] # [chat_id, Dto]
chats: Table[string, ChatDto] # [chat_id, ChatDto]
method delete*(self: Service) =
discard
proc newService*(): Service =
result = Service()
result.chats = initTable[string, Dto]()
result.chats = initTable[string, ChatDto]()
method init*(self: Service) =
try:
let response = status_go.getChats()
let chats = map(response.result.getElems(),
proc(x: JsonNode): Dto = x.toDto())
proc(x: JsonNode): ChatDto = x.toChatDto())
for chat in chats:
if chat.active and chat.chatType != ChatType.Unknown:

View File

@ -1,6 +1,6 @@
import dto
import ./dto/chat as chat_dto
export dto
export chat_dto
type
ServiceInterface* {.pure inheritable.} = ref object of RootObj

View File

@ -1,8 +1,8 @@
{.used.}
import json, strformat
import json
include ../../common/json_utils
include ../../../common/json_utils
type
Permission* = ref object
@ -34,7 +34,7 @@ type Member* = ref object
id*: string
roles*: seq[int]
type Dto* = ref object
type CommunityDto* = ref object
id*: string
admin*: bool
verified*: bool
@ -100,8 +100,8 @@ proc toMember(jsonObj: JsonNode, memberId: string): Member =
for roleObj in rolesObj:
result.roles.add(roleObj.getInt)
proc toDto*(jsonObj: JsonNode): Dto =
result = Dto()
proc toCommunityDto*(jsonObj: JsonNode): CommunityDto =
result = CommunityDto()
discard jsonObj.getProp("id", result.id)
discard jsonObj.getProp("admin", result.admin)
discard jsonObj.getProp("verified", result.verified)

View File

@ -1,6 +1,9 @@
import Tables, json, sequtils, strformat, chronicles
import service_interface, dto
import service_interface, ./dto/community
import ../chat/service as chat_service
import status/statusgo_backend_new/communities as status_go
export service_interface
@ -9,22 +12,24 @@ logScope:
topics = "community-service"
type
Service* = ref object of ServiceInterface
communities: Table[string, Dto] # [community_id, Dto]
Service* = ref object of service_interface.ServiceInterface
communities: Table[string, CommunityDto] # [community_id, CommunityDto]
chatService: chat_service.Service
method delete*(self: Service) =
discard
proc newService*(): Service =
proc newService*(chatService: chat_service.Service): Service =
result = Service()
result.communities = initTable[string, Dto]()
result.communities = initTable[string, CommunityDto]()
result.chatService = chatService
method init*(self: Service) =
try:
let response = status_go.getJoinedComunities()
let communities = map(response.result.getElems(),
proc(x: JsonNode): Dto = x.toDto())
proc(x: JsonNode): CommunityDto = x.toCommunityDto())
for community in communities:
self.communities[community.id] = community
@ -34,5 +39,5 @@ method init*(self: Service) =
error "error: ", errDesription
return
method getCommunities*(self: Service): seq[Dto] =
method getCommunities*(self: Service): seq[CommunityDto] =
return toSeq(self.communities.values)

View File

@ -1,6 +1,6 @@
import dto
import ./dto/community as community_dto
export dto
export community_dto
type
ServiceInterface* {.pure inheritable.} = ref object of RootObj
@ -12,5 +12,5 @@ method delete*(self: ServiceInterface) {.base.} =
method init*(self: ServiceInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getCommunities*(self: ServiceInterface): seq[Dto] {.base.} =
method getCommunities*(self: ServiceInterface): seq[CommunityDto] {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -2,14 +2,14 @@
import json, strformat
include ../../common/json_utils
include ../../../common/json_utils
type
Images* = ref object
thumbnail*: string
large*: string
type Dto* = ref object
type ContactsDto* = ref object
id*: string
name*: string
ensVerified*: bool
@ -29,7 +29,7 @@ proc `$`(self: Images): string =
large: {self.large},
]"""
proc `$`*(self: Dto): string =
proc `$`*(self: ContactsDto): string =
result = fmt"""ContactDto(
id: {self.id},
name: {self.name},
@ -58,8 +58,8 @@ proc toImages(jsonObj: JsonNode): Images =
if(jsonObj.getProp("thumbnail", thumbnailObj)):
discard jsonObj.getProp("uri", result.thumbnail)
proc toDto*(jsonObj: JsonNode): Dto =
result = Dto()
proc toContactsDto*(jsonObj: JsonNode): ContactsDto =
result = ContactsDto()
discard jsonObj.getProp("id", result.id)
discard jsonObj.getProp("name", result.name)
discard jsonObj.getProp("ensVerified", result.ensVerified)

View File

@ -1,6 +1,6 @@
import Tables, json, sequtils, strformat, chronicles
import service_interface, dto
import service_interface, ./dto/contacts
import status/statusgo_backend_new/contacts as status_go
export service_interface
@ -10,21 +10,21 @@ logScope:
type
Service* = ref object of ServiceInterface
contacts: Table[string, Dto] # [contact_id, Dto]
contacts: Table[string, ContactsDto] # [contact_id, ContactsDto]
method delete*(self: Service) =
discard
proc newService*(): Service =
result = Service()
result.contacts = initTable[string, Dto]()
result.contacts = initTable[string, ContactsDto]()
method init*(self: Service) =
try:
let response = status_go.getContacts()
let contacts = map(response.result.getElems(),
proc(x: JsonNode): Dto = x.toDto())
proc(x: JsonNode): ContactsDto = x.toContactsDto())
for contact in contacts:
self.contacts[contact.id] = contact

View File

@ -1,6 +1,6 @@
import dto
import ./dto/contacts as contacts_dto
export dto
export contacts_dto
type
ServiceInterface* {.pure inheritable.} = ref object of RootObj