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 ActivityListModel population mechanisms #4736

Merged
merged 1 commit into from
Sep 13, 2022

Conversation

claucambra
Copy link
Collaborator

@claucambra claucambra commented Jul 14, 2022

Signed-off-by: Claudio Cambra claudio.cambra@gmail.com

As it stands, the ActivityListModel has two issues:

  1. It updates coarsely, bulldozing all prior data and replacing with newly-acquired data
  2. It has duplicated and messy code relating to inserting and removing rows from the model

This refactoring eliminates these issues, which in turn also prevents the activity list view resetting every time something changes (i.e. receiving new activities, dismissing notifications, etc.) by updating the core data list granularly rather than coarsely. This addresses a point in #4432

NOTE: this PR depends on #4735 as it removes the clearNotifications method which goes unused after the internal refactoring of ActivityListModel and the removal of clearNotifications from the UserModel in #4735

Fixes #4724

@claucambra claucambra self-assigned this Jul 14, 2022
@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch 7 times, most recently from 1e65268 to bdbf5c4 Compare July 15, 2022 00:18
@codecov
Copy link

codecov bot commented Jul 15, 2022

Codecov Report

Merging #4736 (20c5f8e) into master (20c5f8e) will not change coverage.
The diff coverage is n/a.

❗ Current head 20c5f8e differs from pull request most recent head 1a5fa50. Consider uploading reports for the commit 1a5fa50 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4736   +/-   ##
=======================================
  Coverage   57.20%   57.20%           
=======================================
  Files         138      138           
  Lines       17138    17138           
=======================================
  Hits         9804     9804           
  Misses       7334     7334           

@claucambra
Copy link
Collaborator Author

/backport to stable-3.5

@claucambra claucambra mentioned this pull request Jul 15, 2022
3 tasks
@claucambra claucambra changed the title Refactor ActivityListModel Refactor ActivityListModel population mechanisms Jul 18, 2022
@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch from bdbf5c4 to ad4809f Compare July 18, 2022 16:19
@mgallien
Copy link
Collaborator

/backport to stable-3.5

I would prefer not to backport in case that would induce regressions

Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please handle the automated comments from sonarcloud has many of them provide feedback that would need to be addressed

src/gui/tray/activitylistmodel.h Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch 8 times, most recently from f65e80c to 57a5fc8 Compare July 26, 2022 14:20
@sonarcloud
Copy link

sonarcloud bot commented Jul 26, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

91.5% 91.5% Coverage
0.0% 0.0% Duplication

@claucambra claucambra requested a review from mgallien July 26, 2022 17:57
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved
src/gui/tray/activitylistmodel.cpp Outdated Show resolved Hide resolved

const auto index = model.index(0, 0);
QVERIFY(index.isValid());
testActivityAdd(&TestingALM::addSyncFileItemToActivityList, testSyncFileItemActivity);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test and the few next ones would be better written as data driven tests with different data instead of doing an utility method and calling it manually several time
see https://doc.qt.io/qt-5/qttestlib-tutorial2-example.html

Copy link
Collaborator Author

@claucambra claucambra Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, what we want to test here is that the activity is added to the activity list correctly, and that it returns the right data, right? For the latter we have the data testing function, in the test slots that take these methods we are testing if the activity is actually added properly

I am not sure what benefit using the QTest data table would bring, in our case it seems it would add more complexity as we would still need to create the activity objects and keep them around, add the activity data we want to test to the QTest table, and then test the table rows vs. just testing the data we get from the table with the data in the activity we are retaining directly

Am I misunderstanding the purpose of the QTest data table?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that the data driven tests are the thing you have to use when you want to run teh same code multiple time with different input values
so sounded to me like the solution here

Copy link
Collaborator Author

@claucambra claucambra Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a lot of reason for the table as we need to keep the activity objects around and these are never changed. We can just compare these directly, at least as I see it -- we instantiate the activities once in the constructor and that is it, we don't need to re-create new activities in each test

The polymorphic way of testing the methods is just there to remove the need for repeating the same lines of code checking for things over and over (which we would have to do with data driven tests anyway)

@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch from 57a5fc8 to 4fdc78d Compare August 2, 2022 15:42
@jancborchardt
Copy link
Member

It updates coarsely, bulldozing all prior data and replacing with newly-acquired data

Ahh nice, so this also fixes the issue of old Talk notifications which were already seen via other apps still showing up? :)

@claucambra
Copy link
Collaborator Author

It updates coarsely, bulldozing all prior data and replacing with newly-acquired data

Ahh nice, so this also fixes the issue of old Talk notifications which were already seen via other apps still showing up? :)

Not really; as I know we do not receive a list of completed notifications from the server which would let us filter out notifications from our presently-shown notifications. But this should prevent showing duplicates

@claucambra claucambra requested a review from mgallien August 26, 2022 18:22
Copy link
Contributor

@allexzander allexzander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😴 Would be great to have the PR contain multiple small self-explanatory commits, in the future, when possible, to ease the review with so many changes.

@allexzander
Copy link
Contributor

@claucambra Just, please don't forget to fix the build

@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch 2 times, most recently from 6baa5ff to cc7721e Compare September 13, 2022 17:02
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
@claucambra claucambra force-pushed the bugfix/refactor-activity-list-model branch from cc7721e to 1a5fa50 Compare September 13, 2022 17:34
@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

91.5% 91.5% Coverage
0.0% 0.0% Duplication

@nextcloud-desktop-bot
Copy link

AppImage file: nextcloud-PR-4736-1a5fa50fbbfb006232fcc9d92733cdf2e9573056-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Marking a notification as read in the client makes the list jump to the top
5 participants