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):
var args = ChatUpdateArgsNew(e)
self.delegate.addChatIfDontExist(args.chats, false, self.events, self.settingsService, self.contactService, self.chatService,
self.communityService, self.messageService, self.gifService, self.mailserversService, setChatAsActive = false)
for chat in args.chats:
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):
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e)
if (args.chat.communityId == self.sectionId):
self.delegate.addNewChat(
args.chat,
true,
self.events,
self.settingsService,
self.contactService,
self.chatService,
self.communityService,
self.messageService,
self.gifService,
self.mailserversService
)
let belongsToCommunity = args.chat.communityId.len > 0
self.delegate.addChatIfDontExist(args.chat, belongsToCommunity, self.events, self.settingsService,
self.contactService, self.chatService, self.communityService, self.messageService, self.gifService,
self.mailserversService, setChatAsActive = true)
self.events.on(SIGNAL_COMMUNITY_CHANNEL_DELETED) do(e:Args):
let args = CommunityChatIdArgs(e)

View File

@ -413,7 +413,7 @@ method addNewChat*(
else:
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,
chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight)
@ -426,6 +426,10 @@ method addNewChat*(
self.setActiveItemSubItem(item.id, "")
else:
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,
chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
blocked=false, active=false, chatDto.position)
@ -730,7 +734,7 @@ method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
self.view.setLoadingHistoryMessagesInProgress(isLoading)
method addChatIfDontExist*(self: Module,
chats: seq[ChatDto],
chat: ChatDto,
belongsToCommunity: bool,
events: EventEmitter,
settingsService: settings_service.ServiceInterface,
@ -741,7 +745,13 @@ method addChatIfDontExist*(self: Module,
gifService: gif_service.Service,
mailserversService: mailservers_service.Service,
setChatAsActive: bool = true) =
for chatDto in chats:
if not self.doesChatExist(chatDto.id):
self.addNewChat(chatDto, belongsToCommunity, events, settingsService, contactService, chatService,
communityService, messageService, gifService, mailserversService, setChatAsActive)
if(belongsToCommunity and self.controller.getMySectionId() != chat.communityId or
not belongsToCommunity and self.controller.getMySectionId() != conf.CHAT_SECTION_ID):
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")
method addChatIfDontExist*(self: AccessInterface,
chats: seq[ChatDto],
chat: ChatDto,
belongsToCommunity: bool,
events: EventEmitter,
settingsService: settings_service.ServiceInterface,