mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-20 18:48:47 +00:00
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:
parent
0fa88be513
commit
12f9282a59
@ -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
|
@ -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")
|
@ -1,23 +1,23 @@
|
||||
import controller_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
|
||||
|
||||
type
|
||||
Controller* = ref object of controller_interface.AccessInterface
|
||||
delegate: io_interface.AccessInterface
|
||||
id: string
|
||||
isCommunityModule: bool
|
||||
chatId: string
|
||||
belongsToCommunity: bool
|
||||
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 =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
result.id = id
|
||||
result.isCommunityModule = isCommunity
|
||||
result.chatId = chatId
|
||||
result.belongsToCommunity = belongsToCommunity
|
||||
result.communityService = communityService
|
||||
|
||||
method delete*(self: Controller) =
|
||||
@ -26,8 +26,8 @@ method delete*(self: Controller) =
|
||||
method init*(self: Controller) =
|
||||
discard
|
||||
|
||||
method getId*(self: Controller): string =
|
||||
return self.id
|
||||
method getChatId*(self: Controller): string =
|
||||
return self.chatId
|
||||
|
||||
method isCommunity*(self: Controller): bool =
|
||||
return self.isCommunityModule
|
||||
method belongsToCommunity*(self: Controller): bool =
|
||||
return self.belongsToCommunity
|
@ -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
|
||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
|
||||
method init*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getId*(self: AccessInterface): string {.base.} =
|
||||
method getChatId*(self: AccessInterface): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method isCommunity*(self: AccessInterface): bool {.base.} =
|
||||
method belongsToCommunity*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -2,10 +2,10 @@ import NimQml
|
||||
import io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
import view, controller
|
||||
import ../../../../core/global_singleton
|
||||
import ../../../../../core/global_singleton
|
||||
|
||||
import ../../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../../app_service/service/community/service as community_service
|
||||
import ../../../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../../../app_service/service/community/service as community_service
|
||||
|
||||
export io_interface
|
||||
|
||||
@ -17,14 +17,14 @@ type
|
||||
controller: controller.AccessInterface
|
||||
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):
|
||||
Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.controller = controller.newController(result, id, isCommunity, communityService)
|
||||
result.controller = controller.newController(result, chatId, belongsToCommunity, communityService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
method delete*(self: Module) =
|
||||
@ -43,4 +43,7 @@ method isLoaded*(self: Module): bool =
|
||||
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.moduleLoaded = true
|
||||
self.delegate.inputAreaDidLoad()
|
||||
self.delegate.inputAreaDidLoad()
|
||||
|
||||
method getModuleAsVariant*(self: Module): QVariant =
|
||||
return self.viewVariant
|
@ -1,3 +1,5 @@
|
||||
import NimQml
|
||||
|
||||
method delete*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
|
||||
|
||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -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
|
@ -1,8 +1,8 @@
|
||||
import controller_interface
|
||||
import io_interface
|
||||
|
||||
import ../../../../../app_service/service/community/service as community_service
|
||||
import ../../../../../app_service/service/message/service as message_service
|
||||
import ../../../../../../app_service/service/community/service as community_service
|
||||
import ../../../../../../app_service/service/message/service as message_service
|
||||
|
||||
import eventemitter
|
||||
import status/[signals]
|
||||
@ -13,18 +13,18 @@ type
|
||||
Controller* = ref object of controller_interface.AccessInterface
|
||||
delegate: io_interface.AccessInterface
|
||||
events: EventEmitter
|
||||
id: string
|
||||
isCommunityModule: bool
|
||||
chatId: string
|
||||
belongsToCommunity: bool
|
||||
communityService: community_service.ServiceInterface
|
||||
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 =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
result.events = events
|
||||
result.id = id
|
||||
result.isCommunityModule = isCommunity
|
||||
result.chatId = chatId
|
||||
result.belongsToCommunity = belongsToCommunity
|
||||
result.communityService = communityService
|
||||
result.messageService = messageService
|
||||
|
||||
@ -36,8 +36,8 @@ method init*(self: Controller) =
|
||||
let args = MessagesLoadedArgs(e)
|
||||
echo "RECEIVED MESSAGES ASYNC: ", repr(args)
|
||||
|
||||
method getId*(self: Controller): string =
|
||||
return self.id
|
||||
method getChatId*(self: Controller): string =
|
||||
return self.chatId
|
||||
|
||||
method isCommunity*(self: Controller): bool =
|
||||
return self.isCommunityModule
|
||||
method belongsToCommunity*(self: Controller): bool =
|
||||
return self.belongsToCommunity
|
@ -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
|
||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
|
||||
method init*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getId*(self: AccessInterface): string {.base.} =
|
||||
method getChatId*(self: AccessInterface): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method isCommunity*(self: AccessInterface): bool {.base.} =
|
||||
method belongsToCommunity*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -2,11 +2,11 @@ import NimQml
|
||||
import io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
import view, controller
|
||||
import ../../../../core/global_singleton
|
||||
import ../../../../../core/global_singleton
|
||||
|
||||
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 ../../../../../../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
|
||||
|
||||
@ -20,14 +20,16 @@ type
|
||||
controller: controller.AccessInterface
|
||||
moduleLoaded: bool
|
||||
|
||||
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter, id: string, isCommunity: bool,
|
||||
chatService: chat_service.Service, communityService: community_service.Service, messageService: message_service.Service):
|
||||
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, events, id, isCommunity, communityService, messageService)
|
||||
result.controller = controller.newController(result, events, chatId, belongsToCommunity, communityService,
|
||||
messageService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
method delete*(self: Module) =
|
||||
@ -46,4 +48,7 @@ method isLoaded*(self: Module): bool =
|
||||
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.moduleLoaded = true
|
||||
self.delegate.messagesDidLoad()
|
||||
self.delegate.messagesDidLoad()
|
||||
|
||||
method getModuleAsVariant*(self: Module): QVariant =
|
||||
return self.viewVariant
|
@ -1,3 +1,5 @@
|
||||
import NimQml
|
||||
|
||||
method delete*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
|
||||
|
||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
107
src/app/modules/main/chat_section/chat_content/module.nim
Normal file
107
src/app/modules/main/chat_section/chat_content/module.nim
Normal 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()
|
@ -1,3 +1,5 @@
|
||||
import NimQml
|
||||
|
||||
method delete*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
@ -6,3 +8,6 @@ method load*(self: AccessInterface) {.base.} =
|
||||
|
||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -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")
|
@ -1,23 +1,23 @@
|
||||
import controller_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
|
||||
|
||||
type
|
||||
Controller* = ref object of controller_interface.AccessInterface
|
||||
delegate: io_interface.AccessInterface
|
||||
id: string
|
||||
isCommunityModule: bool
|
||||
chatId: string
|
||||
belongsToCommunity: bool
|
||||
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 =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
result.id = id
|
||||
result.isCommunityModule = isCommunity
|
||||
result.chatId = chatId
|
||||
result.belongsToCommunity = belongsToCommunity
|
||||
result.communityService = communityService
|
||||
|
||||
method delete*(self: Controller) =
|
||||
@ -26,8 +26,8 @@ method delete*(self: Controller) =
|
||||
method init*(self: Controller) =
|
||||
discard
|
||||
|
||||
method getId*(self: Controller): string =
|
||||
return self.id
|
||||
method getChatId*(self: Controller): string =
|
||||
return self.chatId
|
||||
|
||||
method isCommunity*(self: Controller): bool =
|
||||
return self.isCommunityModule
|
||||
method belongsToCommunity*(self: Controller): bool =
|
||||
return self.belongsToCommunity
|
@ -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
|
||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||
@ -10,10 +10,10 @@ method delete*(self: AccessInterface) {.base.} =
|
||||
method init*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getId*(self: AccessInterface): string {.base.} =
|
||||
method getChatId*(self: AccessInterface): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method isCommunity*(self: AccessInterface): bool {.base.} =
|
||||
method belongsToCommunity*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
@ -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
|
@ -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
|
@ -2,10 +2,10 @@ import NimQml
|
||||
import io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
import view, controller
|
||||
import ../../../../core/global_singleton
|
||||
import ../../../../../core/global_singleton
|
||||
|
||||
import ../../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../../app_service/service/community/service as community_service
|
||||
import ../../../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../../../app_service/service/community/service as community_service
|
||||
|
||||
export io_interface
|
||||
|
||||
@ -17,14 +17,14 @@ type
|
||||
controller: controller.AccessInterface
|
||||
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):
|
||||
Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.controller = controller.newController(result, id, isCommunity, communityService)
|
||||
result.controller = controller.newController(result, chatId, belongsToCommunity, communityService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
method delete*(self: Module) =
|
||||
@ -43,4 +43,7 @@ method isLoaded*(self: Module): bool =
|
||||
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.moduleLoaded = true
|
||||
self.delegate.usersDidLoad()
|
||||
self.delegate.usersDidLoad()
|
||||
|
||||
method getModuleAsVariant*(self: Module): QVariant =
|
||||
return self.viewVariant
|
@ -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")
|
@ -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.
|
42
src/app/modules/main/chat_section/chat_content/view.nim
Normal file
42
src/app/modules/main/chat_section/chat_content/view.nim
Normal 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
|
@ -9,6 +9,4 @@ include ./private_interfaces/module_view_delegate_interface
|
||||
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
|
||||
include ./private_interfaces/module_chat_content_delegate_interface
|
@ -1,12 +1,10 @@
|
||||
import NimQml, chronicles
|
||||
import NimQml, Tables, chronicles
|
||||
import io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
import view, controller, item, sub_item, model, sub_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 chat_content/module as chat_content_module
|
||||
|
||||
import ../../../../app_service/service/chat/service as chat_service
|
||||
import ../../../../app_service/service/community/service as community_service
|
||||
@ -25,9 +23,7 @@ type
|
||||
view: View
|
||||
viewVariant: QVariant
|
||||
controller: controller.AccessInterface
|
||||
inputAreaModule: input_area_module.AccessInterface
|
||||
messagesModule: messages_module.AccessInterface
|
||||
usersModule: users_module.AccessInterface
|
||||
chatContentModule: OrderedTable[string, chat_content_module.AccessInterface]
|
||||
moduleLoaded: 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.controller = controller.newController(result, id, isCommunity, chatService, communityService, messageService)
|
||||
result.moduleLoaded = false
|
||||
|
||||
result.inputAreaModule = input_area_module.newModule(result, id, isCommunity, chatService, communityService)
|
||||
result.messagesModule = messages_module.newModule(result, events, id, isCommunity, chatService, communityService,
|
||||
messageService)
|
||||
result.usersModule = users_module.newModule(result, id, isCommunity, chatService, communityService)
|
||||
|
||||
result.chatContentModule = initOrderedTable[string, chat_content_module.AccessInterface]()
|
||||
|
||||
method delete*(self: Module) =
|
||||
for cModule in self.chatContentModule.values:
|
||||
cModule.delete
|
||||
self.chatContentModule.clear
|
||||
self.view.delete
|
||||
self.viewVariant.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 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,
|
||||
c.chatType.int, hasNotification, notificationsCount, c.muted, false)
|
||||
self.view.appendItem(item)
|
||||
self.addSubmodule(c.id, false, events, chatService, communityService, messageService)
|
||||
|
||||
# make the first chat active when load the app
|
||||
if(selectedItemId.len == 0):
|
||||
@ -69,7 +73,8 @@ proc buildChatUI(self: Module) =
|
||||
|
||||
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 selectedSubItemId = ""
|
||||
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.muted, false)
|
||||
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
|
||||
if(selectedItemId.len == 0):
|
||||
@ -111,6 +117,7 @@ proc buildCommunityUI(self: Module) =
|
||||
chatDto.identicon, chatDto.color, chatDto.description, hasNotification, notificationsCount, chatDto.muted,
|
||||
false)
|
||||
categoryChannels.add(channelItem)
|
||||
self.addSubmodule(chatDto.id, true, events, chatService, communityService, messageService)
|
||||
|
||||
# in case there is no channels beyond categories,
|
||||
# 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)
|
||||
|
||||
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.view.load()
|
||||
|
||||
if(self.controller.isCommunity()):
|
||||
self.buildCommunityUI()
|
||||
self.buildCommunityUI(events, chatService, communityService, messageService)
|
||||
else:
|
||||
self.buildChatUI()
|
||||
self.buildChatUI(events, chatService, communityService, messageService)
|
||||
|
||||
self.inputAreaModule.load()
|
||||
self.messagesModule.load()
|
||||
self.usersModule.load()
|
||||
for cModule in self.chatContentModule.values:
|
||||
cModule.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
|
||||
for cModule in self.chatContentModule.values:
|
||||
if(not cModule.isLoaded()):
|
||||
return
|
||||
|
||||
self.moduleLoaded = true
|
||||
if(self.controller.isCommunity()):
|
||||
@ -163,13 +165,7 @@ method isLoaded*(self: Module): bool =
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.checkIfModuleDidLoad()
|
||||
|
||||
method inputAreaDidLoad*(self: Module) =
|
||||
self.checkIfModuleDidLoad()
|
||||
|
||||
method messagesDidLoad*(self: Module) =
|
||||
self.checkIfModuleDidLoad()
|
||||
|
||||
method usersDidLoad*(self: Module) =
|
||||
method chatContentDidLoad*(self: Module) =
|
||||
self.checkIfModuleDidLoad()
|
||||
|
||||
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.activeItemSubItemSet(item, subItem)
|
||||
|
||||
method getChatSection*(self: Module): QVariant =
|
||||
return self.viewVariant
|
||||
method getModuleAsVariant*(self: Module): QVariant =
|
||||
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()
|
@ -1,13 +1,20 @@
|
||||
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.} =
|
||||
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")
|
||||
|
||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getChatSection*(self: AccessInterface): QVariant {.base.} =
|
||||
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -0,0 +1,2 @@
|
||||
method chatContentDidLoad*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
@ -1,5 +1,10 @@
|
||||
import NimQml
|
||||
|
||||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
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")
|
@ -10,6 +10,7 @@ QtObject:
|
||||
modelVariant: QVariant
|
||||
activeItem: ActiveItem
|
||||
activeItemVariant: QVariant
|
||||
tmpChatId: string # shouldn't be used anywhere except in prepareChatContentModuleForChatId/getChatContentModule procs
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.model.delete
|
||||
@ -62,4 +63,19 @@ QtObject:
|
||||
self.activeItemChanged()
|
||||
|
||||
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
|
@ -181,9 +181,9 @@ method load*[T](self: Module[T], events: EventEmitter, chatService: chat_service
|
||||
activeSection = profileSettingsSectionItem
|
||||
|
||||
# Load all sections
|
||||
self.chatSectionModule.load()
|
||||
self.chatSectionModule.load(events, chatService, communityService, messageService)
|
||||
for cModule in self.communitySectionsModule.values:
|
||||
cModule.load()
|
||||
cModule.load(events, chatService, communityService, messageService)
|
||||
self.walletSectionModule.load()
|
||||
# self.walletV2SectionModule.load()
|
||||
self.browserSectionModule.load()
|
||||
@ -276,12 +276,12 @@ method disableSection*[T](self: Module[T], sectionType: SectionType) =
|
||||
method setUserStatus*[T](self: Module[T], status: bool) =
|
||||
self.controller.setUserStatus(status)
|
||||
|
||||
method getChatSection*[T](self: Module[T]): QVariant =
|
||||
return self.chatSectionModule.getChatSection()
|
||||
method getChatSectionModule*[T](self: Module[T]): QVariant =
|
||||
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)):
|
||||
echo "main-module, unexisting community key: ", communityId
|
||||
return
|
||||
|
||||
return self.communitySectionsModule[communityId].getChatSection()
|
||||
return self.communitySectionsModule[communityId].getModuleAsVariant()
|
@ -13,8 +13,8 @@ method setActiveSection*(self: AccessInterface, item: Item) {.base.} =
|
||||
method setUserStatus*(self: AccessInterface, status: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method getChatSection*(self: AccessInterface): QVariant {.base.} =
|
||||
method getChatSectionModule*(self: AccessInterface): QVariant {.base.} =
|
||||
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")
|
@ -10,7 +10,7 @@ QtObject:
|
||||
modelVariant: QVariant
|
||||
activeSection: ActiveSection
|
||||
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) =
|
||||
self.model.delete
|
||||
@ -102,19 +102,19 @@ QtObject:
|
||||
self.delegate.setUserStatus(status)
|
||||
|
||||
# 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
|
||||
# setCommunitySection/getCommunitySection procs
|
||||
proc setCommunitySection*(self: View, communityId: string) {.slot.} =
|
||||
# prepareCommunitySectionModuleForCommunityId/getCommunitySectionModule procs
|
||||
proc prepareCommunitySectionModuleForCommunityId*(self: View, communityId: string) {.slot.} =
|
||||
self.tmpCommunityId = communityId
|
||||
|
||||
proc getCommunitySection*(self: View): QVariant {.slot.} =
|
||||
var communityVariant = self.delegate.getCommunitySection(self.tmpCommunityId)
|
||||
proc getCommunitySectionModule*(self: View): QVariant {.slot.} =
|
||||
var communityVariant = self.delegate.getCommunitySectionModule(self.tmpCommunityId)
|
||||
self.tmpCommunityId = ""
|
||||
if(communityVariant.isNil):
|
||||
return newQVariant()
|
||||
|
||||
return communityVariant
|
||||
|
||||
proc getChatSection*(self: View): QVariant {.slot.} =
|
||||
return self.delegate.getChatSection()
|
||||
proc getChatSectionModule*(self: View): QVariant {.slot.} =
|
||||
return self.delegate.getChatSectionModule()
|
@ -435,7 +435,7 @@ Item {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
chatSectionModule = mainModule.getChatSection()
|
||||
chatSectionModule = mainModule.getChatSectionModule()
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,8 +530,10 @@ Item {
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
mainModule.setCommunitySection(model.id)
|
||||
chatSectionModule = mainModule.getCommunitySection()
|
||||
// we cannot return QVariant if we pass another parameter in a function call
|
||||
// that's why we're using it this way
|
||||
mainModule.prepareCommunitySectionModuleForCommunityId(model.id)
|
||||
chatSectionModule = mainModule.getCommunitySectionModule()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user