fix(community): fix deleting community chat more reliable

Fixes #4913

The problem was that we relied only on the status-go signals, so there was a delay, and also they are not as reliable as deleting them ourselves from the array and calling the event
This commit is contained in:
Jonathan Rainville 2022-03-07 12:04:22 -05:00
parent 9821e160c1
commit f0d9eb9b04
4 changed files with 23 additions and 16 deletions

View File

@ -309,20 +309,15 @@ QtObject:
result.hasNotifications = result.hasNotifications or self.items[i].BaseItem.hasUnreadMessages result.hasNotifications = result.hasNotifications or self.items[i].BaseItem.hasUnreadMessages
result.notificationsCount = result.notificationsCount + self.items[i].BaseItem.notificationsCount result.notificationsCount = result.notificationsCount + self.items[i].BaseItem.notificationsCount
proc reorder*(self: Model, chatOrCategoryId: string, position: int) = proc reorder*(self: Model, chatOrCategoryId: string, position: int) =
let index = self.getItemIdxById(chatOrCategoryId) let index = self.getItemIdxById(chatOrCategoryId)
if(index == -1): if(index == -1):
return return
let idx = self.createIndex(index, 0, nil)
self.items[index].BaseItem.position = position self.items[index].BaseItem.position = position
self.dataChanged(idx, idx, @[ModelRole.Position.int])
let tempItem = self.items[position]
self.beginResetModel() self.beginResetModel()
self.items[position] = self.items[index] self.items.sort(sortChats)
self.items[index] = tempItem
self.endResetModel() self.endResetModel()
proc clearItems*(self: Model) = proc clearItems*(self: Model) =

View File

@ -498,8 +498,19 @@ method onCommunityCategoryDeleted*(self: Module, cat: Category) =
self.view.chatsModel().removeItemById(cat.id) self.view.chatsModel().removeItemById(cat.id)
method setFirstChannelAsActive*(self: Module) =
if(self.view.chatsModel().getCount() == 0):
return
let item = self.view.chatsModel().getItemAtIndex(0)
if(item.subItems.getCount() == 0):
self.setActiveItemSubItem(item.id, "")
else:
let subItem = item.subItems.getItemAtIndex(0)
self.setActiveItemSubItem(item.id, subItem.id)
method onReorderChatOrCategory*(self: Module, chatOrCatId: string, position: int) = method onReorderChatOrCategory*(self: Module, chatOrCatId: string, position: int) =
self.view.chatsModel().reorder(chatOrCatId, position) self.view.chatsModel().reorder(chatOrCatId, position)
self.setFirstChannelAsActive()
method onCategoryNameChanged*(self: Module, category: Category) = method onCategoryNameChanged*(self: Module, category: Category) =
self.view.chatsModel().renameItem(category.id, category.name) self.view.chatsModel().renameItem(category.id, category.name)
@ -536,16 +547,7 @@ method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) =
self.view.chatsModel().removeItemById(chatId) self.view.chatsModel().removeItemById(chatId)
self.removeSubmodule(chatId) self.removeSubmodule(chatId)
if(self.view.chatsModel().getCount() == 0): self.setFirstChannelAsActive()
return
# set first channel as the active one in model
let item = self.view.chatsModel().getItemAtIndex(0)
if(item.subItems.getCount() == 0):
self.setActiveItemSubItem(item.id, "")
else:
let subItem = item.subItems.getItemAtIndex(0)
self.setActiveItemSubItem(item.id, subItem.id)
method onCommunityChannelEdited*(self: Module, chat: ChatDto) = method onCommunityChannelEdited*(self: Module, chat: ChatDto) =
if(not self.chatContentModules.contains(chat.id)): if(not self.chatContentModules.contains(chat.id)):

View File

@ -36,3 +36,6 @@ method onActiveSectionChange*(self: AccessInterface, sectionId: string) {.base.}
method chatsModel*(self: AccessInterface): chats_model.Model {.base.} = method chatsModel*(self: AccessInterface): chats_model.Model {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method setFirstChannelAsActive*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -693,6 +693,13 @@ QtObject:
if response.result.isNil or response.result.kind == JNull: if response.result.isNil or response.result.kind == JNull:
error "response is invalid", methodName="deleteCommunityChat" error "response is invalid", methodName="deleteCommunityChat"
var shortChatId = chatId.replace(communityId, "")
let idx = findIndexById(shortChatId, self.joinedCommunities[communityId].chats)
if (idx != -1):
self.joinedCommunities[communityId].chats.delete(idx)
self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(
communityId: communityId, chatId: chatId))
except Exception as e: except Exception as e:
error "Error deleting community channel", msg = e.msg, communityId, chatId, methodName="deleteCommunityChat" error "Error deleting community channel", msg = e.msg, communityId, chatId, methodName="deleteCommunityChat"