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.notificationsCount = result.notificationsCount + self.items[i].BaseItem.notificationsCount
proc reorder*(self: Model, chatOrCategoryId: string, position: int) =
let index = self.getItemIdxById(chatOrCategoryId)
if(index == -1):
return
let idx = self.createIndex(index, 0, nil)
self.items[index].BaseItem.position = position
self.dataChanged(idx, idx, @[ModelRole.Position.int])
let tempItem = self.items[position]
self.beginResetModel()
self.items[position] = self.items[index]
self.items[index] = tempItem
self.items.sort(sortChats)
self.endResetModel()
proc clearItems*(self: Model) =

View File

@ -498,8 +498,19 @@ method onCommunityCategoryDeleted*(self: Module, cat: Category) =
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) =
self.view.chatsModel().reorder(chatOrCatId, position)
self.setFirstChannelAsActive()
method onCategoryNameChanged*(self: Module, category: Category) =
self.view.chatsModel().renameItem(category.id, category.name)
@ -536,16 +547,7 @@ method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) =
self.view.chatsModel().removeItemById(chatId)
self.removeSubmodule(chatId)
if(self.view.chatsModel().getCount() == 0):
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)
self.setFirstChannelAsActive()
method onCommunityChannelEdited*(self: Module, chat: ChatDto) =
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.} =
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:
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:
error "Error deleting community channel", msg = e.msg, communityId, chatId, methodName="deleteCommunityChat"