fix(@desktop/communities): remove chat_section data if user left the community

This commit is contained in:
mprakhov 2023-03-17 12:29:10 +01:00 committed by Mykhailo Prakhov
parent 8d97203a85
commit 417f206d4d
14 changed files with 70 additions and 32 deletions

View File

@ -32,6 +32,9 @@ proc once*(this:EventEmitter, name:string, handler:Handler): void =
handler(a)
this.events[name].del handlerId
proc onUsingUUID*(this: EventEmitter, handlerId: UUID, name: string, handler: Handler): void =
this.on(name, handlerId, handler)
proc onWithUUID*(this: EventEmitter, name: string, handler: Handler): UUID =
var handlerId = genUUID()
this.on(name, handlerId, handler)
@ -41,7 +44,6 @@ proc disconnect*(this: EventEmitter, handlerId: UUID) =
for k, v in this.events:
if v.hasKey(handlerId):
this.events[k].del handlerId
return
proc emit*(this:EventEmitter, name:string, args:Args): void =
if this.events.hasKey(name):

View File

@ -0,0 +1,23 @@
import eventemitter
import # deps
uuids
type
UniqueUUIDEventEmitter* = ref object
events: EventEmitter
handlerId: UUID
proc initUniqueUUIDEventEmitter*(events: EventEmitter): UniqueUUIDEventEmitter =
result = UniqueUUIDEventEmitter()
result.events = events
result.handlerId = genUUID()
proc on*(self: UniqueUUIDEventEmitter, name: string, handler: Handler): void =
self.events.onUsingUUID(self.handlerId, name, handler)
proc disconnect*(self: UniqueUUIDEventEmitter) =
self.events.disconnect(self.handlerId)
proc eventsEmitter*(self: UniqueUUIDEventEmitter): EventEmitter =
return self.events

View File

@ -14,13 +14,14 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
import ../../../../core/signals/types
import ../../../../core/eventemitter
import ../../../../core/unique_event_emitter
import ../../../shared_models/message_item
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
events: UniqueUUIDEventEmitter
sectionId: string
chatId: string
belongsToCommunity: bool
@ -41,7 +42,7 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
communityService: community_service.Service, messageService: message_service.Service): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.events = initUniqueUUIDEventEmitter(events)
result.sectionId = sectionId
result.chatId = chatId
result.belongsToCommunity = belongsToCommunity
@ -54,7 +55,7 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
result.messageService = messageService
proc delete*(self: Controller) =
discard
self.events.disconnect()
proc init*(self: Controller) =
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):

View File

@ -5,12 +5,13 @@ import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../../app_service/service/gif/service as gif_service
import ../../../../../../app_service/service/gif/dto
import ../../../../../core/eventemitter
import ../../../../../core/unique_event_emitter
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
sectionId: string
events: EventEmitter
events: UniqueUUIDEventEmitter
chatId: string
belongsToCommunity: bool
communityService: community_service.Service
@ -29,7 +30,7 @@ proc newController*(
): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.events = initUniqueUUIDEventEmitter(events)
result.sectionId = chatId
result.chatId = chatId
result.belongsToCommunity = belongsToCommunity
@ -38,7 +39,7 @@ proc newController*(
result.gifService = gifService
proc delete*(self: Controller) =
discard
self.events.disconnect()
proc init*(self: Controller) =
self.events.on(SIGNAL_LOAD_RECENT_GIFS_DONE) do(e:Args):

View File

@ -13,6 +13,7 @@ import ../../../../../../app_service/service/eth/utils as eth_utils
import ../../../../../global/app_signals
import ../../../../../core/signals/types
import ../../../../../core/eventemitter
import ../../../../../core/unique_event_emitter
logScope:
topics = "messages-controller"
@ -20,7 +21,7 @@ logScope:
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
events: UniqueUUIDEventEmitter
sectionId: string
chatId: string
belongsToCommunity: bool
@ -38,7 +39,7 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.events = initUniqueUUIDEventEmitter(events)
result.sectionId = sectionId
result.chatId = chatId
result.loadingMessagesPerPageFactor = 1
@ -50,7 +51,7 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter
result.mailserversService = mailserversService
proc delete*(self: Controller) =
discard
self.events.disconnect()
proc init*(self: Controller) =
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):

View File

@ -51,9 +51,9 @@ proc createFetchMoreMessagesItem(self: Module): Item
proc setChatDetails(self: Module, chatDetails: ChatDto)
method delete*(self: Module) =
self.controller.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*(self: Module) =
self.controller.init()

View File

@ -62,12 +62,13 @@ proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitt
else: communityUsersModule
method delete*(self: Module) =
self.inputAreaModule.delete
self.messagesModule.delete
self.usersModule.delete
self.controller.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
self.inputAreaModule.delete
self.messagesModule.delete
if self.usersModule != nil:
self.usersModule.delete
method load*(self: Module) =
self.controller.init()

View File

@ -7,11 +7,12 @@ import ../../../../../../app_service/service/message/service as message_service
import ../../../../../../app_service/service/chat/service as chat_service
import ../../../../../core/eventemitter
import ../../../../../core/unique_event_emitter
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
events: EventEmitter
events: UniqueUUIDEventEmitter
sectionId: string
chatId: string
belongsToCommunity: bool
@ -32,7 +33,7 @@ proc newController*(
): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.events = initUniqueUUIDEventEmitter(events)
result.sectionId = sectionId
result.chatId = chatId
result.belongsToCommunity = belongsToCommunity
@ -44,7 +45,7 @@ proc newController*(
result.chatService = chatService
proc delete*(self: Controller) =
discard
self.events.disconnect()
proc handleCommunityOnlyConnections(self: Controller) =
self.events.on(SIGNAL_COMMUNITY_MEMBER_APPROVED) do(e: Args):

View File

@ -1,4 +1,4 @@
import NimQml, strutils, sequtils, sugar
import NimQml, strutils, sequtils, sugar, chronicles
import io_interface
import view, controller
import ../../../../shared_models/[member_model, member_item]
@ -40,9 +40,9 @@ proc newModule*(
result.moduleLoaded = false
method delete*(self: Module) =
self.controller.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
method load*(self: Module) =
if not self.moduleLoaded:

View File

@ -18,6 +18,7 @@ import ../../../../app_service/service/visual_identity/service as procs_from_vis
import ../../../core/signals/types
import ../../../global/app_signals
import ../../../core/eventemitter
import ../../../core/unique_event_emitter
type
@ -27,7 +28,7 @@ type
isCommunitySection: bool
activeItemId: string
isCurrentSectionActive: bool
events: EventEmitter
events: UniqueUUIDEventEmitter
settingsService: settings_service.Service
nodeConfigurationService: node_configuration_service.Service
contactService: contact_service.Service
@ -53,7 +54,7 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
result.sectionId = sectionId
result.isCommunitySection = isCommunity
result.isCurrentSectionActive = false
result.events = events
result.events = initUniqueUUIDEventEmitter(events)
result.settingsService = settingsService
result.nodeConfigurationService = nodeConfigurationService
result.contactService = contactService
@ -67,7 +68,7 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
result.communityTokensService = communityTokensService
proc delete*(self: Controller) =
discard
self.events.disconnect()
proc getActiveChatId*(self: Controller): string =
return self.activeItemId

View File

@ -13,6 +13,7 @@ import ../../../../app_service/service/token/service as token_service
import model as chats_model
import ../../../core/eventemitter
import ../../../core/unique_event_emitter
import ../../shared_models/token_list_item
@ -75,7 +76,7 @@ method doesTopLevelChatExist*(self: AccessInterface, chatId: string): bool {.bas
method addChatIfDontExist*(self: AccessInterface,
chat: ChatDto,
belongsToCommunity: bool,
events: EventEmitter,
events: UniqueUUIDEventEmitter,
settingsService: settings_service.Service,
nodeConfigurationService: node_configuration_service.Service,
contactService: contact_service.Service,

View File

@ -20,6 +20,7 @@ import chat_content/users/module as users_module
import ../../../global/app_sections_config as conf
import ../../../global/global_singleton
import ../../../core/eventemitter
import ../../../core/unique_event_emitter
import ../../../core/notifications/details as notification_details
import ../../../../app_service/common/types
import ../../../../app_service/service/settings/service as settings_service
@ -104,12 +105,12 @@ proc newModule*(
contactService, chat_service, communityService, messageService)
method delete*(self: Module) =
self.controller.delete
self.view.delete
self.viewVariant.delete
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
@ -1108,7 +1109,7 @@ method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
method addChatIfDontExist*(self: Module,
chat: ChatDto,
belongsToCommunity: bool,
events: EventEmitter,
events: UniqueUUIDEventEmitter,
settingsService: settings_service.Service,
nodeConfigurationService: node_configuration_service.Service,
contactService: contact_service.Service,
@ -1129,7 +1130,7 @@ method addChatIfDontExist*(self: Module,
elif (chat.chatType != ChatType.OneToOne):
self.onChatRenamed(chat.id, chat.name)
return
self.addNewChat(chat, belongsToCommunity, events, settingsService, nodeConfigurationService,
self.addNewChat(chat, belongsToCommunity, events.eventsEmitter(), settingsService, nodeConfigurationService,
contactService, chatService, communityService, messageService, gifService, mailserversService,
setChatAsActive)

View File

@ -204,6 +204,7 @@ proc newModule*[T](
result.networksModule = networks_module.newModule(result, events, networkService, walletAccountService, settingsService)
method delete*[T](self: Module[T]) =
self.controller.delete
self.profileSectionModule.delete
self.stickersModule.delete
self.activityCenterModule.delete
@ -222,7 +223,6 @@ method delete*[T](self: Module[T]) =
self.keycardSharedModuleKeycardSyncPurpose.delete
self.view.delete
self.viewVariant.delete
self.controller.delete
proc createTokenItem[T](self: Module[T], tokenDto: CommunityTokenDto, networks: seq[NetworkDto]) : TokenItem =
var chainName, chainIcon: string
@ -846,6 +846,11 @@ method communityLeft*[T](self: Module[T], communityId: string) =
let item = self.view.model().getItemById(singletonInstance.userProfile.getPubKey())
self.setActiveSection(item)
var moduleToDelete: chat_section_module.AccessInterface
discard self.channelGroupModules.pop(communityId, moduleToDelete)
moduleToDelete.delete
moduleToDelete = nil
method communityEdited*[T](
self: Module[T],
community: CommunityDto) =

View File

@ -882,11 +882,11 @@ QtObject:
for chat in updatedCommunity.chats:
self.messageService.resetMessageCursor(chat.id)
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: communityId))
# remove related community requests
keepIf(self.myCommunityRequests, request => request.communityId != communityId)
self.events.emit(SIGNAL_COMMUNITY_LEFT, CommunityIdArgs(communityId: communityId))
except Exception as e:
error "Error leaving community", msg = e.msg, communityId