refactor(@desktop/channel): refactor members list to only have one list per community

This commit is contained in:
mprakhov 2023-01-23 03:45:09 +02:00 committed by Jonathan Rainville
parent d28bcdb58a
commit 763041dab5
3 changed files with 28 additions and 16 deletions

View File

@ -42,7 +42,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
belongsToCommunity: bool, isUsersListAvailable: bool, settingsService: settings_service.Service,
nodeConfigurationService: node_configuration_service.Service, contactService: contact_service.Service, chatService: chat_service.Service,
communityService: community_service.Service, messageService: message_service.Service, gifService: gif_service.Service,
mailserversService: mailservers_service.Service):
mailserversService: mailservers_service.Service, communityUsersModule: users_module.AccessInterface):
Module =
result = Module()
result.delegate = delegate
@ -55,10 +55,11 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
result.inputAreaModule = input_area_module.newModule(result, sectionId, chatId, belongsToCommunity, chatService, communityService, gifService)
result.messagesModule = messages_module.newModule(result, events, sectionId, chatId, belongsToCommunity,
contactService, communityService, chatService, messageService, mailserversService)
result.usersModule = users_module.newModule(
result, events, sectionId, chatId, belongsToCommunity, isUsersListAvailable,
contactService, chat_service, communityService, messageService
)
result.usersModule =
if communityUsersModule == nil:
users_module.newModule( events, sectionId, chatId, belongsToCommunity,
isUsersListAvailable, contactService, chat_service, communityService, messageService)
else: communityUsersModule
method delete*(self: Module) =
self.inputAreaModule.delete
@ -86,6 +87,8 @@ method load*(self: Module) =
if(contactDto.image.thumbnail.len > 0):
chatImage = contactDto.image.thumbnail
self.usersModule.load()
self.view.load(chatDto.id, chatDto.chatType.int, self.controller.belongsToCommunity(),
self.controller.isUsersListAvailable(), chatName, chatImage,
chatDto.color, chatDto.description, chatDto.emoji, hasNotification, notificationsCount,
@ -94,7 +97,6 @@ method load*(self: Module) =
self.inputAreaModule.load()
self.messagesModule.load()
self.usersModule.load()
proc checkIfModuleDidLoad(self: Module) =
if self.moduleLoaded:

View File

@ -1,6 +1,5 @@
import NimQml, strutils, sequtils, sugar
import io_interface
import ../io_interface as delegate_interface
import view, controller
import ../../../../shared_models/[member_model, member_item]
import ../../../../../global/global_singleton
@ -17,7 +16,6 @@ export io_interface
type
Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View
viewVariant: QVariant
controller: Controller
@ -27,13 +25,12 @@ type
method addChatMember*(self: Module, member: ChatMember)
proc newModule*(
delegate: delegate_interface.AccessInterface, events: EventEmitter, sectionId: string, chatId: string,
events: EventEmitter, sectionId: string, chatId: string,
belongsToCommunity: bool, isUsersListAvailable: bool, contactService: contact_service.Service,
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(
@ -48,6 +45,7 @@ method delete*(self: Module) =
self.controller.delete
method load*(self: Module) =
if not self.moduleLoaded:
self.controller.init()
self.view.load()
@ -60,7 +58,6 @@ method viewDidLoad*(self: Module) =
self.addChatMember(member)
self.moduleLoaded = true
self.delegate.usersDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
@ -140,6 +137,9 @@ method addChatMember*(self: Module, member: ChatMember) =
))
method onChatMembersAdded*(self: Module, ids: seq[string]) =
if ids.len() == 0:
return
let members = self.controller.getChatMembers()
for id in ids:
for member in members:

View File

@ -8,6 +8,7 @@ import ../../shared_models/user_item as user_item
import ../../shared_models/user_model as user_model
import chat_content/module as chat_content_module
import chat_content/users/module as users_module
import ../../../global/app_sections_config as conf
import ../../../global/global_singleton
@ -38,6 +39,7 @@ type
controller: Controller
chatContentModules: OrderedTable[string, chat_content_module.AccessInterface]
moduleLoaded: bool
usersModule: users_module.AccessInterface
# Forward declaration
proc buildChatSectionUI(self: Module,
@ -77,6 +79,12 @@ proc newModule*(
result.chatContentModules = initOrderedTable[string, chat_content_module.AccessInterface]()
# Simple community channels uses comminity usersModule while chats uses their own usersModule
if isCommunity:
result.usersModule = users_module.newModule(
events, sectionId, chatId = "", belongsToCommunity = true, isUsersListAvailable = true,
contactService, chat_service, communityService, messageService)
method delete*(self: Module) =
for cModule in self.chatContentModules.values:
cModule.delete
@ -84,6 +92,8 @@ method delete*(self: Module) =
self.view.delete
self.viewVariant.delete
self.controller.delete
if self.usersModule != nil:
self.usersModule.delete
method isCommunity*(self: Module): bool =
return self.controller.isCommunity()
@ -108,7 +118,7 @@ proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, isUsers
mailserversService: mailservers_service.Service) =
self.chatContentModules[chatId] = chat_content_module.newModule(self, events, self.controller.getMySectionId(), chatId,
belongToCommunity, isUsersListAvailable, settingsService, nodeConfigurationService, contactService, chatService, communityService,
messageService, gifService, mailserversService)
messageService, gifService, mailserversService, self.usersModule)
proc removeSubmodule(self: Module, chatId: string) =
if(not self.chatContentModules.contains(chatId)):
@ -135,7 +145,6 @@ proc buildChatSectionUI(
for chatDto in channelGroup.chats:
if (chatDto.categoryId != ""):
continue
let hasNotification = not chatDto.muted and (chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0)
let notificationsCount = chatDto.unviewedMentionsCount
@ -186,7 +195,6 @@ proc buildChatSectionUI(
let categoryChats = channelGroup.chats.filter(c => c.categoryId == cat.id)
for chatDto in categoryChats:
let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0
let notificationsCount = chatDto.unviewedMentionsCount
@ -284,6 +292,8 @@ method load*(
if(not self.controller.isCommunity()):
# we do this only in case of chat section (not in case of communities)
self.initContactRequestsModel()
else:
self.usersModule.load()
let activeChatId = self.controller.getActiveChatId()
for chatId, cModule in self.chatContentModules: