Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor contacts' user models to have only one model that is filtered on the UI side #16549

Open
jrainville opened this issue Oct 18, 2024 · 3 comments · May be fixed by #16667
Open

Refactor contacts' user models to have only one model that is filtered on the UI side #16549

jrainville opened this issue Oct 18, 2024 · 3 comments · May be fixed by #16667

Comments

@jrainville
Copy link
Member

Description

Similar to #16433

In the contacts module, there are 5 models for the different types of contacts:

  • contactsModel: all the known users aka contacts
  • myMutualContactsModel: the contacts that we added and were also added
  • blockedContactsModel: people we blocked
  • receivedContactRequestsModel: contacts that sent us contact requests
  • sentContactRequestsModel: contacts to whom we sent a contact request

All those models could be deleted and we only keep contactsModel and then use SortFilterProxyModels on the QML side to filter the right contacts for the different lists.

@jrainville
Copy link
Member Author

Also, the way we update items is very bad. We remove all items from the models and then replace them with new items. That is highly ineffective

proc removeIfExistsAndAddToAppropriateModel(self: Module, publicKey: string) =
  self.removeItemWithPubKeyFromAllModels(publicKey)
  let item = self.createItemFromPublicKey(publicKey)
  self.addItemToAppropriateModel(item)

@jrainville jrainville self-assigned this Oct 23, 2024
jrainville added a commit that referenced this issue Oct 29, 2024
Fixes #16549

Refactors the 5 types of contact models (all, mutuals, banned, received and sent) into only the `allContacts` and use an Adaptor on the QML side to filter into the needed models.
This cleans the Nim side a lot and makes applying updates to the contacts' model way simpler.
jrainville added a commit that referenced this issue Oct 30, 2024
Fixes #16549

We used to update contact items by removing them from the models and re-adding them. This is highly inefficient.
Instead, the proper way is to update only the values that changed.
jrainville added a commit that referenced this issue Oct 31, 2024
Fixes #16549

We used to update contact items by removing them from the models and re-adding them. This is highly inefficient.
Instead, the proper way is to update only the values that changed.
@micieslak
Copy link
Member

Seems to be duplicate of #14966

@jrainville
Copy link
Member Author

Seems to be duplicate of #14966

Indeed. I think maybe we can just close #14966 since I already linked my own issue to the PR?

@alexjba can you check both issues and the PR to see if I indeed covered what you proposed.

jrainville added a commit that referenced this issue Oct 31, 2024
Fixes #16549

Refactors the 5 types of contact models (all, mutuals, banned, received and sent) into only the `allContacts` and use an Adaptor on the QML side to filter into the needed models.
This cleans the Nim side a lot and makes applying updates to the contacts' model way simpler.

rthh
jrainville added a commit that referenced this issue Oct 31, 2024
Fixes #16549

We used to update contact items by removing them from the models and re-adding them. This is highly inefficient.
Instead, the proper way is to update only the values that changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment