fix(Communities): Fix community duplications in model

Closes: #5002
This commit is contained in:
Boris Melnik 2022-03-14 14:23:06 +03:00 committed by Iuri Matias
parent e130953634
commit d4c4fe1f41
1 changed files with 17 additions and 8 deletions

View File

@ -141,25 +141,34 @@ QtObject:
of ModelRole.PendingRequestsToJoinModel:
result = newQVariant(item.pendingRequestsToJoin)
proc isItemExist(self: SectionModel, id: string): bool =
for it in self.items:
if(it.id == id):
return true
return false
proc addItem*(self: SectionModel, item: SectionItem) =
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
self.beginInsertRows(parentModelIndex, self.items.len, self.items.len)
self.items.add(item)
self.endInsertRows()
if not self.isItemExist(item.id):
self.beginInsertRows(parentModelIndex, self.items.len, self.items.len)
self.items.add(item)
self.endInsertRows()
self.countChanged()
self.countChanged()
proc addItem*(self: SectionModel, item: SectionItem, index: int) =
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
self.beginInsertRows(parentModelIndex, index, index)
self.items.insert(item, index)
self.endInsertRows()
if not self.isItemExist(item.id):
self.beginInsertRows(parentModelIndex, index, index)
self.items.insert(item, index)
self.endInsertRows()
self.countChanged()
self.countChanged()
proc getItemIndex*(self: SectionModel, id: string): int =
var i = 0