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,10 +141,18 @@ 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
if not self.isItemExist(item.id):
self.beginInsertRows(parentModelIndex, self.items.len, self.items.len)
self.items.add(item)
self.endInsertRows()
@ -155,6 +163,7 @@ QtObject:
let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete
if not self.isItemExist(item.id):
self.beginInsertRows(parentModelIndex, index, index)
self.items.insert(item, index)
self.endInsertRows()