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

Re-order widgets in the SourceList on update. #1013

Conversation

ntoll
Copy link
Contributor

@ntoll ntoll commented Mar 26, 2020

Description

Fixes #914.

Ensure the widgets are ordered by timestamp on update in the source list. Screenie of the behaviour:

reorder

Implementation of this was interesting. I was quite a way through doing something in the update method since the sources list passed into the method is in the correct order. However, I took a detour and wondered if Qt had some way to order widgets in a QListWidget. Turns out that it does and so I went for this far simpler code. Also, this will be a faster ordering since the ordering is being done in the Qt (C++) level rather than in pure Python.

Test Plan

Updated the unit tests to patch the new SourceListWidgetItem class. Eyeball Mk.1 to ensure the order is correct (see screenie). 👀

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

If these changes add or remove files other than client code, packaging logic (e.g., the AppArmor profile) may need to be updated. Please check as applicable:

  • I have submitted a separate PR to the packaging repo
  • No update to the packaging logic (e.g., AppArmor profile) is required for these changes
  • I don't know and would appreciate guidance

my_ts = arrow.get(me.source.last_updated)
other_ts = arrow.get(them.source.last_updated)
return my_ts < other_ts
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

nice implementation!

cc @creviera for your awareness this impacts #967 - I think merging this and then as part of #967 modifying SourceWidget.update to also update a last_updated field makes sense. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

that sounds good to me @redshiftzero

@sssoleileraaa
Copy link
Contributor

For some reason I thought this was merged already which is why I opened #1020. I think #914 covers #1020 so I will close it.

@sssoleileraaa sssoleileraaa force-pushed the reorder-sources-on-update-by-timestamp branch from 5c3bb65 to 807783f Compare March 27, 2020 17:25
Copy link
Contributor

@sssoleileraaa sssoleileraaa left a comment

Choose a reason for hiding this comment

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

I like this minimal approach. It looks like sources are moved to the top for new files and messages but not for replies. I didn't see any mention of this, so maybe my assumption is wrong that if you reply to a source it should bring that source up to the top. I think after a reply successfully makes it to the server and we move it from draft to the replies table, we should update the source list (actually surprised this isn't happening already so I'll need to investigate). Also, I'll test this on qubes with 400 and 1000 sources.

Update

After discussing with @ninavizz and @eloquence and recalling a similar previous conversation I see why successful replies are not moved to the top, but once they are considered "last activity" of a source, then they will be. This also means that the timestamp we display in the preview will be correct except for replies, since the last_updated timestamp will not take into account replies. We will need to open an issue to make this really clear since it's easy to forget this detail.

self.insertItem(0, list_item)
list_item.setSizeHint(new_source.sizeHint())
self.setItemWidget(list_item, new_source)

# Sort..!
self.sortItems(Qt.DescendingOrder)
Copy link
Contributor

Choose a reason for hiding this comment

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

since we're resorting the entire source list for every sync, we'll need to test this against 400 and 1000 sources to make sure things don't freeze up

Copy link
Contributor

@sssoleileraaa sssoleileraaa left a comment

Choose a reason for hiding this comment

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

lgtm, i kept running into this issue so I could not test with 1000 sources in qubes. I was able to test with 20 sources and things worked as expected. Since we have separate issues for improving scalability, we can address performance bottlenecks there.

@sssoleileraaa sssoleileraaa merged commit 1b51b4b into freedomofpress:master Mar 27, 2020
@eloquence eloquence mentioned this pull request Apr 4, 2020
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.

When source conversation is updated, it does not float to the top of the source list
3 participants