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

View File

@ -1,6 +1,5 @@
import NimQml, strutils, sequtils, sugar import NimQml, strutils, sequtils, sugar
import io_interface import io_interface
import ../io_interface as delegate_interface
import view, controller import view, controller
import ../../../../shared_models/[member_model, member_item] import ../../../../shared_models/[member_model, member_item]
import ../../../../../global/global_singleton import ../../../../../global/global_singleton
@ -17,7 +16,6 @@ export io_interface
type type
Module* = ref object of io_interface.AccessInterface Module* = ref object of io_interface.AccessInterface
delegate: delegate_interface.AccessInterface
view: View view: View
viewVariant: QVariant viewVariant: QVariant
controller: Controller controller: Controller
@ -27,13 +25,12 @@ type
method addChatMember*(self: Module, member: ChatMember) method addChatMember*(self: Module, member: ChatMember)
proc newModule*( 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, belongsToCommunity: bool, isUsersListAvailable: bool, contactService: contact_service.Service,
chatService: chat_service.Service, communityService: community_service.Service, chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service, messageService: message_service.Service,
): Module = ): Module =
result = Module() result = Module()
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.controller = controller.newController(
@ -48,6 +45,7 @@ method delete*(self: Module) =
self.controller.delete self.controller.delete
method load*(self: Module) = method load*(self: Module) =
if not self.moduleLoaded:
self.controller.init() self.controller.init()
self.view.load() self.view.load()
@ -60,7 +58,6 @@ method viewDidLoad*(self: Module) =
self.addChatMember(member) self.addChatMember(member)
self.moduleLoaded = true self.moduleLoaded = true
self.delegate.usersDidLoad()
method getModuleAsVariant*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
@ -140,6 +137,9 @@ method addChatMember*(self: Module, member: ChatMember) =
)) ))
method onChatMembersAdded*(self: Module, ids: seq[string]) = method onChatMembersAdded*(self: Module, ids: seq[string]) =
if ids.len() == 0:
return
let members = self.controller.getChatMembers() let members = self.controller.getChatMembers()
for id in ids: for id in ids:
for member in members: 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 ../../shared_models/user_model as user_model
import chat_content/module as chat_content_module 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/app_sections_config as conf
import ../../../global/global_singleton import ../../../global/global_singleton
@ -38,6 +39,7 @@ type
controller: Controller controller: Controller
chatContentModules: OrderedTable[string, chat_content_module.AccessInterface] chatContentModules: OrderedTable[string, chat_content_module.AccessInterface]
moduleLoaded: bool moduleLoaded: bool
usersModule: users_module.AccessInterface
# Forward declaration # Forward declaration
proc buildChatSectionUI(self: Module, proc buildChatSectionUI(self: Module,
@ -77,6 +79,12 @@ proc newModule*(
result.chatContentModules = initOrderedTable[string, chat_content_module.AccessInterface]() 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) = method delete*(self: Module) =
for cModule in self.chatContentModules.values: for cModule in self.chatContentModules.values:
cModule.delete cModule.delete
@ -84,6 +92,8 @@ method delete*(self: Module) =
self.view.delete self.view.delete
self.viewVariant.delete self.viewVariant.delete
self.controller.delete self.controller.delete
if self.usersModule != nil:
self.usersModule.delete
method isCommunity*(self: Module): bool = method isCommunity*(self: Module): bool =
return self.controller.isCommunity() return self.controller.isCommunity()
@ -108,7 +118,7 @@ proc addSubmodule(self: Module, chatId: string, belongToCommunity: bool, isUsers
mailserversService: mailservers_service.Service) = mailserversService: mailservers_service.Service) =
self.chatContentModules[chatId] = chat_content_module.newModule(self, events, self.controller.getMySectionId(), chatId, self.chatContentModules[chatId] = chat_content_module.newModule(self, events, self.controller.getMySectionId(), chatId,
belongToCommunity, isUsersListAvailable, settingsService, nodeConfigurationService, contactService, chatService, communityService, belongToCommunity, isUsersListAvailable, settingsService, nodeConfigurationService, contactService, chatService, communityService,
messageService, gifService, mailserversService) messageService, gifService, mailserversService, self.usersModule)
proc removeSubmodule(self: Module, chatId: string) = proc removeSubmodule(self: Module, chatId: string) =
if(not self.chatContentModules.contains(chatId)): if(not self.chatContentModules.contains(chatId)):
@ -135,7 +145,6 @@ proc buildChatSectionUI(
for chatDto in channelGroup.chats: for chatDto in channelGroup.chats:
if (chatDto.categoryId != ""): if (chatDto.categoryId != ""):
continue continue
let hasNotification = not chatDto.muted and (chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0) let hasNotification = not chatDto.muted and (chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0)
let notificationsCount = chatDto.unviewedMentionsCount let notificationsCount = chatDto.unviewedMentionsCount
@ -186,7 +195,6 @@ proc buildChatSectionUI(
let categoryChats = channelGroup.chats.filter(c => c.categoryId == cat.id) let categoryChats = channelGroup.chats.filter(c => c.categoryId == cat.id)
for chatDto in categoryChats: for chatDto in categoryChats:
let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0 let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0
let notificationsCount = chatDto.unviewedMentionsCount let notificationsCount = chatDto.unviewedMentionsCount
@ -284,6 +292,8 @@ method load*(
if(not self.controller.isCommunity()): if(not self.controller.isCommunity()):
# we do this only in case of chat section (not in case of communities) # we do this only in case of chat section (not in case of communities)
self.initContactRequestsModel() self.initContactRequestsModel()
else:
self.usersModule.load()
let activeChatId = self.controller.getActiveChatId() let activeChatId = self.controller.getActiveChatId()
for chatId, cModule in self.chatContentModules: for chatId, cModule in self.chatContentModules: