refactor(@desktop/general): added modules `InputArea`, `Messages`, `Users`

Each `ChatSection` module contains as many `ChatContent` submodules as many chats
the section contains (a chat maybe either from the Chat section or Community section or
from the category of the Community section).

`ChatContent` consists of 3 submodules `InputArea`, `Messages`, `Users`, so far.
This commit is contained in:
Sale Djenic 2021-11-03 11:55:51 +01:00
parent 0fa88be513
commit 12f9282a59
57 changed files with 474 additions and 122 deletions

View File

@ -0,0 +1,43 @@
import Tables
import controller_interface
import io_interface
import ../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service
export controller_interface
type
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
chatId: string
belongsToCommunity: bool
chatService: chat_service.ServiceInterface
communityService: community_service.ServiceInterface
messageService: message_service.Service
proc newController*(delegate: io_interface.AccessInterface, chatId: string, belongsToCommunity: bool,
chatService: chat_service.ServiceInterface,
communityService: community_service.ServiceInterface,
messageService: message_service.Service): Controller =
result = Controller()
result.delegate = delegate
result.chatId = chatId
result.belongsToCommunity = belongsToCommunity
result.chatService = chatService
result.communityService = communityService
result.messageService = messageService
method delete*(self: Controller) =
discard
method init*(self: Controller) =
discard
method getChatId*(self: Controller): string =
return self.chatId
method belongsToCommunity*(self: Controller): bool =
return self.belongsToCommunity

View File

@ -0,0 +1,18 @@
import ../../../../../app_service/service/chat/service_interface as chat_service
import ../../../../../app_service/service/community/service_interface as community_service
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 init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")
method belongsToCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,23 +1,23 @@
import controller_interface import controller_interface
import io_interface import io_interface
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
export controller_interface export controller_interface
type type
Controller* = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
id: string chatId: string
isCommunityModule: bool belongsToCommunity: bool
communityService: community_service.ServiceInterface communityService: community_service.ServiceInterface
proc newController*(delegate: io_interface.AccessInterface, id: string, isCommunity: bool, proc newController*(delegate: io_interface.AccessInterface, chatId: string, belongsToCommunity: bool,
communityService: community_service.ServiceInterface): Controller = communityService: community_service.ServiceInterface): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.id = id result.chatId = chatId
result.isCommunityModule = isCommunity result.belongsToCommunity = belongsToCommunity
result.communityService = communityService result.communityService = communityService
method delete*(self: Controller) = method delete*(self: Controller) =
@ -26,8 +26,8 @@ method delete*(self: Controller) =
method init*(self: Controller) = method init*(self: Controller) =
discard discard
method getId*(self: Controller): string = method getChatId*(self: Controller): string =
return self.id return self.chatId
method isCommunity*(self: Controller): bool = method belongsToCommunity*(self: Controller): bool =
return self.isCommunityModule return self.belongsToCommunity

View File

@ -1,4 +1,4 @@
import ../../../../../app_service/service/community/service_interface as community_service import ../../../../../../app_service/service/community/service_interface as community_service
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} = method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getId*(self: AccessInterface): string {.base.} = method getChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isCommunity*(self: AccessInterface): bool {.base.} = method belongsToCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -2,10 +2,10 @@ import NimQml
import io_interface import io_interface
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import view, controller import view, controller
import ../../../../core/global_singleton import ../../../../../core/global_singleton
import ../../../../../app_service/service/chat/service as chat_service import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
export io_interface export io_interface
@ -17,14 +17,14 @@ type
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, id: string, isCommunity: bool, proc newModule*(delegate: delegate_interface.AccessInterface, chatId: string, belongsToCommunity: bool,
chatService: chat_service.Service, communityService: community_service.Service): chatService: chat_service.Service, communityService: community_service.Service):
Module = Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, isCommunity, communityService) result.controller = controller.newController(result, chatId, belongsToCommunity, communityService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*(self: Module) = method delete*(self: Module) =
@ -43,4 +43,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.inputAreaDidLoad() self.delegate.inputAreaDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant

View File

@ -1,3 +1,5 @@
import NimQml
method delete*(self: AccessInterface) {.base.} = method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,14 @@
# 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
include ./private_interfaces/module_input_area_delegate_interface
include ./private_interfaces/module_messages_delegate_interface
include ./private_interfaces/module_users_delegate_interface

View File

@ -1,8 +1,8 @@
import controller_interface import controller_interface
import io_interface import io_interface
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service import ../../../../../../app_service/service/message/service as message_service
import eventemitter import eventemitter
import status/[signals] import status/[signals]
@ -13,18 +13,18 @@ type
Controller* = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
events: EventEmitter events: EventEmitter
id: string chatId: string
isCommunityModule: bool belongsToCommunity: bool
communityService: community_service.ServiceInterface communityService: community_service.ServiceInterface
messageService: message_service.Service messageService: message_service.Service
proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool, proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter, chatId: string, belongsToCommunity: bool,
communityService: community_service.ServiceInterface, messageService: message_service.Service): Controller = communityService: community_service.ServiceInterface, messageService: message_service.Service): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.events = events result.events = events
result.id = id result.chatId = chatId
result.isCommunityModule = isCommunity result.belongsToCommunity = belongsToCommunity
result.communityService = communityService result.communityService = communityService
result.messageService = messageService result.messageService = messageService
@ -36,8 +36,8 @@ method init*(self: Controller) =
let args = MessagesLoadedArgs(e) let args = MessagesLoadedArgs(e)
echo "RECEIVED MESSAGES ASYNC: ", repr(args) echo "RECEIVED MESSAGES ASYNC: ", repr(args)
method getId*(self: Controller): string = method getChatId*(self: Controller): string =
return self.id return self.chatId
method isCommunity*(self: Controller): bool = method belongsToCommunity*(self: Controller): bool =
return self.isCommunityModule return self.belongsToCommunity

View File

@ -1,4 +1,4 @@
import ../../../../../app_service/service/community/service_interface as community_service import ../../../../../../app_service/service/community/service_interface as community_service
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} = method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getId*(self: AccessInterface): string {.base.} = method getChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isCommunity*(self: AccessInterface): bool {.base.} = method belongsToCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -2,11 +2,11 @@ import NimQml
import io_interface import io_interface
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import view, controller import view, controller
import ../../../../core/global_singleton import ../../../../../core/global_singleton
import ../../../../../app_service/service/chat/service as chat_service import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service import ../../../../../../app_service/service/message/service as message_service
import eventemitter import eventemitter
@ -20,14 +20,16 @@ type
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool, proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, chatId: string,
chatService: chat_service.Service, communityService: community_service.Service, messageService: message_service.Service): belongsToCommunity: bool, chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service):
Module = Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, events, id, isCommunity, communityService, messageService) result.controller = controller.newController(result, events, chatId, belongsToCommunity, communityService,
messageService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*(self: Module) = method delete*(self: Module) =
@ -46,4 +48,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.messagesDidLoad() self.delegate.messagesDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant

View File

@ -1,3 +1,5 @@
import NimQml
method delete*(self: AccessInterface) {.base.} = method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,107 @@
import NimQml, chronicles
import io_interface
import ../io_interface as delegate_interface
import view, controller, item, model
import ../../../../core/global_singleton
import input_area/module as input_area_module
import messages/module as messages_module
import users/module as users_module
import ../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service
import eventemitter
export io_interface
logScope:
topics = "chat-section-module"
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
controller: controller.AccessInterface
inputAreaModule: input_area_module.AccessInterface
messagesModule: messages_module.AccessInterface
usersModule: users_module.AccessInterface
moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, chatId: string, belongsToCommunity: bool,
chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service):
Module =
result = Module()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, chatId, belongsToCommunity, chatService, communityService,
messageService)
result.moduleLoaded = false
result.inputAreaModule = input_area_module.newModule(result, chatId, belongsToCommunity, chatService, communityService)
result.messagesModule = messages_module.newModule(result, events, chatId, belongsToCommunity, chatService,
communityService, messageService)
result.usersModule = users_module.newModule(result, chatId, belongsToCommunity, chatService, communityService)
method delete*(self: Module) =
self.inputAreaModule.delete
self.messagesModule.delete
self.usersModule.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*(self: Module) =
self.controller.init()
self.view.load()
self.inputAreaModule.load()
self.messagesModule.load()
self.usersModule.load()
proc checkIfModuleDidLoad(self: Module) =
if self.moduleLoaded:
return
if(not self.inputAreaModule.isLoaded()):
return
if (not self.messagesModule.isLoaded()):
return
if (not self.usersModule.isLoaded()):
return
self.moduleLoaded = true
self.delegate.chatContentDidLoad()
method isLoaded*(self: Module): bool =
return self.moduleLoaded
method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method inputAreaDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method messagesDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method usersDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method getInputAreaModule*(self: Module): QVariant =
return self.inputAreaModule.getModuleAsVariant()
method getMessagesModule*(self: Module): QVariant =
return self.messagesModule.getModuleAsVariant()
method getUsersModule*(self: Module): QVariant =
return self.usersModule.getModuleAsVariant()

View File

@ -1,3 +1,5 @@
import NimQml
method delete*(self: AccessInterface) {.base.} = method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,13 @@
import NimQml
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getInputAreaModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getMessagesModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method getUsersModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,23 +1,23 @@
import controller_interface import controller_interface
import io_interface import io_interface
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
export controller_interface export controller_interface
type type
Controller* = ref object of controller_interface.AccessInterface Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface delegate: io_interface.AccessInterface
id: string chatId: string
isCommunityModule: bool belongsToCommunity: bool
communityService: community_service.ServiceInterface communityService: community_service.ServiceInterface
proc newController*(delegate: io_interface.AccessInterface, id: string, isCommunity: bool, proc newController*(delegate: io_interface.AccessInterface, chatId: string, belongsToCommunity: bool,
communityService: community_service.ServiceInterface): Controller = communityService: community_service.ServiceInterface): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
result.id = id result.chatId = chatId
result.isCommunityModule = isCommunity result.belongsToCommunity = belongsToCommunity
result.communityService = communityService result.communityService = communityService
method delete*(self: Controller) = method delete*(self: Controller) =
@ -26,8 +26,8 @@ method delete*(self: Controller) =
method init*(self: Controller) = method init*(self: Controller) =
discard discard
method getId*(self: Controller): string = method getChatId*(self: Controller): string =
return self.id return self.chatId
method isCommunity*(self: Controller): bool = method belongsToCommunity*(self: Controller): bool =
return self.isCommunityModule return self.belongsToCommunity

View File

@ -1,4 +1,4 @@
import ../../../../../app_service/service/community/service_interface as community_service import ../../../../../../app_service/service/community/service_interface as community_service
type type
AccessInterface* {.pure inheritable.} = ref object of RootObj AccessInterface* {.pure inheritable.} = ref object of RootObj
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} = method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getId*(self: AccessInterface): string {.base.} = method getChatId*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isCommunity*(self: AccessInterface): bool {.base.} = method belongsToCommunity*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,21 @@
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

@ -0,0 +1,17 @@
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

@ -2,10 +2,10 @@ import NimQml
import io_interface import io_interface
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import view, controller import view, controller
import ../../../../core/global_singleton import ../../../../../core/global_singleton
import ../../../../../app_service/service/chat/service as chat_service import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service import ../../../../../../app_service/service/community/service as community_service
export io_interface export io_interface
@ -17,14 +17,14 @@ type
controller: controller.AccessInterface controller: controller.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, id: string, isCommunity: bool, proc newModule*(delegate: delegate_interface.AccessInterface, chatId: string, belongsToCommunity: bool,
chatService: chat_service.Service, communityService: community_service.Service): chatService: chat_service.Service, communityService: community_service.Service):
Module = Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
result.view = view.newView(result) result.view = view.newView(result)
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, isCommunity, communityService) result.controller = controller.newController(result, chatId, belongsToCommunity, communityService)
result.moduleLoaded = false result.moduleLoaded = false
method delete*(self: Module) = method delete*(self: Module) =
@ -43,4 +43,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.usersDidLoad() self.delegate.usersDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant

View File

@ -0,0 +1,13 @@
import NimQml
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 getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -0,0 +1,5 @@
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

@ -0,0 +1,42 @@
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()
proc getInputAreaModule(self: View): QVariant {.slot.} =
return self.delegate.getInputAreaModule()
QtProperty[QVariant] inputAreaModule:
read = getInputAreaModule
proc getMessagesModule(self: View): QVariant {.slot.} =
return self.delegate.getMessagesModule()
QtProperty[QVariant] messagesModule:
read = getMessagesModule
proc getUsersModule(self: View): QVariant {.slot.} =
return self.delegate.getUsersModule()
QtProperty[QVariant] usersModule:
read = getUsersModule

View File

@ -9,6 +9,4 @@ include ./private_interfaces/module_view_delegate_interface
include ./private_interfaces/module_controller_delegate_interface include ./private_interfaces/module_controller_delegate_interface
# Defines how submodules of this module communicate with this module # Defines how submodules of this module communicate with this module
include ./private_interfaces/module_input_area_delegate_interface include ./private_interfaces/module_chat_content_delegate_interface
include ./private_interfaces/module_messages_delegate_interface
include ./private_interfaces/module_users_delegate_interface

View File

@ -1,12 +1,10 @@
import NimQml, chronicles import NimQml, Tables, chronicles
import io_interface import io_interface
import ../io_interface as delegate_interface import ../io_interface as delegate_interface
import view, controller, item, sub_item, model, sub_model import view, controller, item, sub_item, model, sub_model
import ../../../core/global_singleton import ../../../core/global_singleton
import input_area/module as input_area_module import chat_content/module as chat_content_module
import messages/module as messages_module
import users/module as users_module
import ../../../../app_service/service/chat/service as chat_service import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/community/service as community_service import ../../../../app_service/service/community/service as community_service
@ -25,9 +23,7 @@ type
view: View view: View
viewVariant: QVariant viewVariant: QVariant
controller: controller.AccessInterface controller: controller.AccessInterface
inputAreaModule: input_area_module.AccessInterface chatContentModule: OrderedTable[string, chat_content_module.AccessInterface]
messagesModule: messages_module.AccessInterface
usersModule: users_module.AccessInterface
moduleLoaded: bool moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool, proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool,
@ -40,18 +36,25 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
result.viewVariant = newQVariant(result.view) result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, id, isCommunity, chatService, communityService, messageService) result.controller = controller.newController(result, id, isCommunity, chatService, communityService, messageService)
result.moduleLoaded = false result.moduleLoaded = false
result.inputAreaModule = input_area_module.newModule(result, id, isCommunity, chatService, communityService) result.chatContentModule = initOrderedTable[string, chat_content_module.AccessInterface]()
result.messagesModule = messages_module.newModule(result, events, id, isCommunity, chatService, communityService,
messageService)
result.usersModule = users_module.newModule(result, id, isCommunity, chatService, communityService)
method delete*(self: Module) = method delete*(self: Module) =
for cModule in self.chatContentModule.values:
cModule.delete
self.chatContentModule.clear
self.view.delete self.view.delete
self.viewVariant.delete self.viewVariant.delete
self.controller.delete self.controller.delete
proc buildChatUI(self: Module) = proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, events: EventEmitter,
chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service) =
self.chatContentModule[chatId] = chat_content_module.newModule(self, events, chatId, belongToCommunity, chatService,
communityService, messageService)
proc buildChatUI(self: Module, events: EventEmitter, chatService: chat_service.Service,
communityService: community_service.Service, messageService: message_service.Service) =
let types = @[ChatType.OneToOne, ChatType.Public, ChatType.PrivateGroupChat, ChatType.Profile] let types = @[ChatType.OneToOne, ChatType.Public, ChatType.PrivateGroupChat, ChatType.Profile]
let chats = self.controller.getChatDetailsForChatTypes(types) let chats = self.controller.getChatDetailsForChatTypes(types)
@ -62,6 +65,7 @@ proc buildChatUI(self: Module) =
let item = initItem(c.id, if c.alias.len > 0: c.alias else: c.name, c.identicon, c.color, c.description, let item = initItem(c.id, if c.alias.len > 0: c.alias else: c.name, c.identicon, c.color, c.description,
c.chatType.int, hasNotification, notificationsCount, c.muted, false) c.chatType.int, hasNotification, notificationsCount, c.muted, false)
self.view.appendItem(item) self.view.appendItem(item)
self.addSubmodule(c.id, false, events, chatService, communityService, messageService)
# make the first chat active when load the app # make the first chat active when load the app
if(selectedItemId.len == 0): if(selectedItemId.len == 0):
@ -69,7 +73,8 @@ proc buildChatUI(self: Module) =
self.setActiveItemSubItem(selectedItemId, "") self.setActiveItemSubItem(selectedItemId, "")
proc buildCommunityUI(self: Module) = proc buildCommunityUI(self: Module, events: EventEmitter, chatService: chat_service.Service,
communityService: community_service.Service, messageService: message_service.Service) =
var selectedItemId = "" var selectedItemId = ""
var selectedSubItemId = "" var selectedSubItemId = ""
let communityIds = self.controller.getCommunityIds() let communityIds = self.controller.getCommunityIds()
@ -85,6 +90,7 @@ proc buildCommunityUI(self: Module) =
chatDto.identicon, chatDto.color, chatDto.description, chatDto.chatType.int, hasNotification, notificationsCount, chatDto.identicon, chatDto.color, chatDto.description, chatDto.chatType.int, hasNotification, notificationsCount,
chatDto.muted, false) chatDto.muted, false)
self.view.appendItem(channelItem) self.view.appendItem(channelItem)
self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
# make the first channel which doesn't belong to any category active when load the app # make the first channel which doesn't belong to any category active when load the app
if(selectedItemId.len == 0): if(selectedItemId.len == 0):
@ -111,6 +117,7 @@ proc buildCommunityUI(self: Module) =
chatDto.identicon, chatDto.color, chatDto.description, hasNotification, notificationsCount, chatDto.muted, chatDto.identicon, chatDto.color, chatDto.description, hasNotification, notificationsCount, chatDto.muted,
false) false)
categoryChannels.add(channelItem) categoryChannels.add(channelItem)
self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
# in case there is no channels beyond categories, # in case there is no channels beyond categories,
# make the first channel of the first category active when load the app # make the first channel of the first category active when load the app
@ -125,31 +132,26 @@ proc buildCommunityUI(self: Module) =
self.setActiveItemSubItem(selectedItemId, selectedSubItemId) self.setActiveItemSubItem(selectedItemId, selectedSubItemId)
method load*(self: Module) = method load*(self: Module, events: EventEmitter, chatService: chat_service.Service,
communityService: community_service.Service, messageService: message_service.Service) =
self.controller.init() self.controller.init()
self.view.load() self.view.load()
if(self.controller.isCommunity()): if(self.controller.isCommunity()):
self.buildCommunityUI() self.buildCommunityUI(events, chatService, communityService, messageService)
else: else:
self.buildChatUI() self.buildChatUI(events, chatService, communityService, messageService)
self.inputAreaModule.load() for cModule in self.chatContentModule.values:
self.messagesModule.load() cModule.load()
self.usersModule.load()
proc checkIfModuleDidLoad(self: Module) = proc checkIfModuleDidLoad(self: Module) =
if self.moduleLoaded: if self.moduleLoaded:
return return
if(not self.inputAreaModule.isLoaded()): for cModule in self.chatContentModule.values:
return if(not cModule.isLoaded()):
return
if (not self.messagesModule.isLoaded()):
return
if (not self.usersModule.isLoaded()):
return
self.moduleLoaded = true self.moduleLoaded = true
if(self.controller.isCommunity()): if(self.controller.isCommunity()):
@ -163,13 +165,7 @@ method isLoaded*(self: Module): bool =
method viewDidLoad*(self: Module) = method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()
method inputAreaDidLoad*(self: Module) = method chatContentDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method messagesDidLoad*(self: Module) =
self.checkIfModuleDidLoad()
method usersDidLoad*(self: Module) =
self.checkIfModuleDidLoad() self.checkIfModuleDidLoad()
method setActiveItemSubItem*(self: Module, itemId: string, subItemId: string) = method setActiveItemSubItem*(self: Module, itemId: string, subItemId: string) =
@ -189,5 +185,12 @@ method activeItemSubItemSet*(self: Module, itemId: string, subItemId: string) =
self.view.model().setActiveItemSubItem(itemId, subItemId) self.view.model().setActiveItemSubItem(itemId, subItemId)
self.view.activeItemSubItemSet(item, subItem) self.view.activeItemSubItemSet(item, subItem)
method getChatSection*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
method getChatContentModule*(self: Module, chatId: string): QVariant =
if(not self.chatContentModule.contains(chatId)):
error "unexisting chat key: ", chatId
return
return self.chatContentModule[chatId].getModuleAsVariant()

View File

@ -1,13 +1,20 @@
import NimQml import NimQml
import ../../../../../app_service/service/chat/service as chat_service
import ../../../../../app_service/service/community/service as community_service
import ../../../../../app_service/service/message/service as message_service
import eventemitter
method delete*(self: AccessInterface) {.base.} = method delete*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method load*(self: AccessInterface) {.base.} = method load*(self: AccessInterface, events: EventEmitter, chatService: chat_service.Service,
communityService: community_service.Service, messageService: message_service.Service) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method isLoaded*(self: AccessInterface): bool {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getChatSection*(self: AccessInterface): QVariant {.base.} = method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

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

View File

@ -1,5 +1,10 @@
import NimQml
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: string) {.base.} = method setActiveItemSubItem*(self: AccessInterface, itemId: string, subItemId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method getChatContentModule*(self: AccessInterface, chatId: string): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -10,6 +10,7 @@ QtObject:
modelVariant: QVariant modelVariant: QVariant
activeItem: ActiveItem activeItem: ActiveItem
activeItemVariant: QVariant activeItemVariant: QVariant
tmpChatId: string # shouldn't be used anywhere except in prepareChatContentModuleForChatId/getChatContentModule procs
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
@ -62,4 +63,19 @@ QtObject:
self.activeItemChanged() self.activeItemChanged()
proc setActiveItem*(self: View, itemId: string, subItemId: string = "") {.slot.} = proc setActiveItem*(self: View, itemId: string, subItemId: string = "") {.slot.} =
self.delegate.setActiveItemSubItem(itemId, subItemId) self.delegate.setActiveItemSubItem(itemId, subItemId)
# Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this:
# prepareChatContentModuleForChatId(self: View, chatId: string): QVariant {.slot.}
# we're using combinaiton of
# prepareChatContentModuleForChatId/getChatContentModule procs
proc prepareChatContentModuleForChatId*(self: View, chatId: string) {.slot.} =
self.tmpChatId = chatId
proc getChatContentModule*(self: View): QVariant {.slot.} =
var chatContentVariant = self.delegate.getChatContentModule(self.tmpChatId)
self.tmpChatId = ""
if(chatContentVariant.isNil):
return newQVariant()
return chatContentVariant

View File

@ -181,9 +181,9 @@ method load*[T](self: Module[T], events: EventEmitter, chatService: chat_service
activeSection = profileSettingsSectionItem activeSection = profileSettingsSectionItem
# Load all sections # Load all sections
self.chatSectionModule.load() self.chatSectionModule.load(events, chatService, communityService, messageService)
for cModule in self.communitySectionsModule.values: for cModule in self.communitySectionsModule.values:
cModule.load() cModule.load(events, chatService, communityService, messageService)
self.walletSectionModule.load() self.walletSectionModule.load()
# self.walletV2SectionModule.load() # self.walletV2SectionModule.load()
self.browserSectionModule.load() self.browserSectionModule.load()
@ -276,12 +276,12 @@ method disableSection*[T](self: Module[T], sectionType: SectionType) =
method setUserStatus*[T](self: Module[T], status: bool) = method setUserStatus*[T](self: Module[T], status: bool) =
self.controller.setUserStatus(status) self.controller.setUserStatus(status)
method getChatSection*[T](self: Module[T]): QVariant = method getChatSectionModule*[T](self: Module[T]): QVariant =
return self.chatSectionModule.getChatSection() return self.chatSectionModule.getModuleAsVariant()
method getCommunitySection*[T](self: Module[T], communityId: string): QVariant = method getCommunitySectionModule*[T](self: Module[T], communityId: string): QVariant =
if(not self.communitySectionsModule.contains(communityId)): if(not self.communitySectionsModule.contains(communityId)):
echo "main-module, unexisting community key: ", communityId echo "main-module, unexisting community key: ", communityId
return return
return self.communitySectionsModule[communityId].getChatSection() return self.communitySectionsModule[communityId].getModuleAsVariant()

View File

@ -13,8 +13,8 @@ method setActiveSection*(self: AccessInterface, item: Item) {.base.} =
method setUserStatus*(self: AccessInterface, status: bool) {.base.} = method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getChatSection*(self: AccessInterface): QVariant {.base.} = method getChatSectionModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method getCommunitySection*(self: AccessInterface, communityId: string): QVariant {.base.} = method getCommunitySectionModule*(self: AccessInterface, communityId: string): QVariant {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -10,7 +10,7 @@ QtObject:
modelVariant: QVariant modelVariant: QVariant
activeSection: ActiveSection activeSection: ActiveSection
activeSectionVariant: QVariant activeSectionVariant: QVariant
tmpCommunityId: string # shouldn't be used anywhere except in setCommunitySection/getCommunitySection procs tmpCommunityId: string # shouldn't be used anywhere except in prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs
proc delete*(self: View) = proc delete*(self: View) =
self.model.delete self.model.delete
@ -102,19 +102,19 @@ QtObject:
self.delegate.setUserStatus(status) self.delegate.setUserStatus(status)
# Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this: # Since we cannot return QVariant from the proc which has arguments, so cannot have proc like this:
# getCommunitySection(self: View, communityId: string): QVariant {.slot.} # prepareCommunitySectionModuleForCommunityId(self: View, communityId: string): QVariant {.slot.}
# we're using combinaiton of # we're using combinaiton of
# setCommunitySection/getCommunitySection procs # prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs
proc setCommunitySection*(self: View, communityId: string) {.slot.} = proc prepareCommunitySectionModuleForCommunityId*(self: View, communityId: string) {.slot.} =
self.tmpCommunityId = communityId self.tmpCommunityId = communityId
proc getCommunitySection*(self: View): QVariant {.slot.} = proc getCommunitySectionModule*(self: View): QVariant {.slot.} =
var communityVariant = self.delegate.getCommunitySection(self.tmpCommunityId) var communityVariant = self.delegate.getCommunitySectionModule(self.tmpCommunityId)
self.tmpCommunityId = "" self.tmpCommunityId = ""
if(communityVariant.isNil): if(communityVariant.isNil):
return newQVariant() return newQVariant()
return communityVariant return communityVariant
proc getChatSection*(self: View): QVariant {.slot.} = proc getChatSectionModule*(self: View): QVariant {.slot.} =
return self.delegate.getChatSection() return self.delegate.getChatSectionModule()

View File

@ -435,7 +435,7 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
chatSectionModule = mainModule.getChatSection() chatSectionModule = mainModule.getChatSectionModule()
} }
} }
@ -530,8 +530,10 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
mainModule.setCommunitySection(model.id) // we cannot return QVariant if we pass another parameter in a function call
chatSectionModule = mainModule.getCommunitySection() // that's why we're using it this way
mainModule.prepareCommunitySectionModuleForCommunityId(model.id)
chatSectionModule = mainModule.getCommunitySectionModule()
} }
} }
} }