Skip to content

Commit

Permalink
refactor(@desktop/channel): refactor members list to only have one li…
Browse files Browse the repository at this point in the history
…st per community
  • Loading branch information
mprakhov authored and jrainville committed Jan 25, 2023
1 parent d28bcdb commit 763041d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
14 changes: 8 additions & 6 deletions src/app/modules/main/chat_section/chat_content/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -94,7 +97,6 @@ method load*(self: Module) =

self.inputAreaModule.load()
self.messagesModule.load()
self.usersModule.load()

proc checkIfModuleDidLoad(self: Module) =
if self.moduleLoaded:
Expand Down
14 changes: 7 additions & 7 deletions src/app/modules/main/chat_section/chat_content/users/module.nim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -48,8 +45,9 @@ method delete*(self: Module) =
self.controller.delete

method load*(self: Module) =
self.controller.init()
self.view.load()
if not self.moduleLoaded:
self.controller.init()
self.view.load()

method isLoaded*(self: Module): bool =
return self.moduleLoaded
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -77,13 +79,21 @@ 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
self.chatContentModules.clear
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()
Expand All @@ -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)):
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 763041d

Please sign in to comment.