fix(@dekstop/chat): dogfooding_3 crash

Fixes #4827
This commit is contained in:
Sale Djenic 2022-02-24 11:23:49 +01:00 committed by saledjenic
parent d47ac2d5f7
commit 0078961a67
3 changed files with 26 additions and 23 deletions

View File

@ -97,26 +97,19 @@ method init*(self: Controller) =
self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args): self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args):
var args = ChatUpdateArgsNew(e) var args = ChatUpdateArgsNew(e)
self.delegate.addChatIfDontExist(args.chats, false, self.events, self.settingsService, self.contactService, self.chatService, for chat in args.chats:
self.communityService, self.messageService, self.gifService, self.mailserversService, setChatAsActive = false) let belongsToCommunity = chat.communityId.len > 0
self.delegate.addChatIfDontExist(chat, belongsToCommunity, self.events, self.settingsService,
self.contactService, self.chatService, self.communityService, self.messageService, self.gifService,
self.mailserversService, setChatAsActive = false)
if (self.isCommunitySection): if (self.isCommunitySection):
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e) let args = CommunityChatArgs(e)
if (args.chat.communityId == self.sectionId): let belongsToCommunity = args.chat.communityId.len > 0
self.delegate.addNewChat( self.delegate.addChatIfDontExist(args.chat, belongsToCommunity, self.events, self.settingsService,
args.chat, self.contactService, self.chatService, self.communityService, self.messageService, self.gifService,
true, self.mailserversService, setChatAsActive = true)
self.events,
self.settingsService,
self.contactService,
self.chatService,
self.communityService,
self.messageService,
self.gifService,
self.mailserversService
)
self.events.on(SIGNAL_COMMUNITY_CHANNEL_DELETED) do(e:Args): self.events.on(SIGNAL_COMMUNITY_CHANNEL_DELETED) do(e:Args):
let args = CommunityChatIdArgs(e) let args = CommunityChatIdArgs(e)

View File

@ -413,7 +413,7 @@ method addNewChat*(
else: else:
amIChatAdmin = self.amIMarkedAsAdminUser(chatDto.members) amIChatAdmin = self.amIMarkedAsAdminUser(chatDto.members)
if chatDto.categoryId == "": if chatDto.categoryId.len == 0:
let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description, let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description,
chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight) blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight)
@ -426,6 +426,10 @@ method addNewChat*(
self.setActiveItemSubItem(item.id, "") self.setActiveItemSubItem(item.id, "")
else: else:
let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId) let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId)
if(categoryItem.isNil):
error "A category you're trying to add channel to doesn't exist", categoryId=chatDto.categoryId
return
let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color, let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color,
chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted, chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
blocked=false, active=false, chatDto.position) blocked=false, active=false, chatDto.position)
@ -730,7 +734,7 @@ method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
self.view.setLoadingHistoryMessagesInProgress(isLoading) self.view.setLoadingHistoryMessagesInProgress(isLoading)
method addChatIfDontExist*(self: Module, method addChatIfDontExist*(self: Module,
chats: seq[ChatDto], chat: ChatDto,
belongsToCommunity: bool, belongsToCommunity: bool,
events: EventEmitter, events: EventEmitter,
settingsService: settings_service.ServiceInterface, settingsService: settings_service.ServiceInterface,
@ -741,7 +745,13 @@ method addChatIfDontExist*(self: Module,
gifService: gif_service.Service, gifService: gif_service.Service,
mailserversService: mailservers_service.Service, mailserversService: mailservers_service.Service,
setChatAsActive: bool = true) = setChatAsActive: bool = true) =
for chatDto in chats:
if not self.doesChatExist(chatDto.id): if(belongsToCommunity and self.controller.getMySectionId() != chat.communityId or
self.addNewChat(chatDto, belongsToCommunity, events, settingsService, contactService, chatService, not belongsToCommunity and self.controller.getMySectionId() != conf.CHAT_SECTION_ID):
communityService, messageService, gifService, mailserversService, setChatAsActive) return
if self.doesChatExist(chat.id):
return
self.addNewChat(chat, belongsToCommunity, events, settingsService, contactService, chatService,
communityService, messageService, gifService, mailserversService, setChatAsActive)

View File

@ -15,7 +15,7 @@ method doesChatExist*(self: AccessInterface, chatId: string): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method addChatIfDontExist*(self: AccessInterface, method addChatIfDontExist*(self: AccessInterface,
chats: seq[ChatDto], chat: ChatDto,
belongsToCommunity: bool, belongsToCommunity: bool,
events: EventEmitter, events: EventEmitter,
settingsService: settings_service.ServiceInterface, settingsService: settings_service.ServiceInterface,