ViennaRSS / vienna-rss

Vienna is a free and open-source RSS/Atom newsreader for macOS.
https://www.vienna-rss.com
Apache License 2.0
1.84k stars 228 forks source link

Layered customization with "ALL/ANY" of Smart Folders #1458

Closed sherlock440 closed 1 year ago

sherlock440 commented 3 years ago

I love Vienna as one of the few counted RSS clients that allow you to create customizable Smart Folders. But this option isn't exactly handy - the paid program ReadKit does it better (there it's done with Alt pressed while pressing the "+").

It's all about the ability to create multiple "layers" for the "All" and "Any" option. This is best illustrated by the example on the screenshot: the "All" rule is in the outer "layer", but there is another "Any" rule inside it. IMG_396BAFE60AC0-1 In this example, it is done so that Smart Folder will display news that either contains the word "Durov" in its title or text (and not both at once), but will also save only unread news.

When this "layered" option is not available, I have to create many folders:

Smart Folder #1 ALL: -- Read = No -- Title = contains "Durov"

Smart Folder #2 ALL: -- Read = No -- Content = contains "Durov"

When there are only 2 rules, it's not so depressing. But if you have a lot of rules, then creating a separate Smart Folder for each of them is unrealistic - it's much easier to create a universal one:

Smart Folder | Telegram ALL: -- Read = No -- ANY: ---- Title = contains "Durov" ---- Content = contains "Durov" ---- ... = ...

xanoni commented 3 years ago

I came here to submit exactly this. I'm new to Vienna and saw that by default there's a shortcut for "New Smart Folder", but not for "New Group Folder". Thus, I assumed that I'm supposed to use Smart Folders and that Group Folders are considered legacy.

Alright, I felt ready for some change, but I failed at a very basic task. How can I create a folder that has all unread and undeleted messages that contain at least one of the following words in the subject OR body: privacy, osint.

image

Apparently not possible. Back to Dumb Folders for now.

xanoni commented 3 years ago

By the way, it would be great if we could just use some scripting language to write filters. Like in ProtonMail, where you can either use the UI to create filters, or if you have more advanced needs, then you can use the Sieve scripting language to create/update/extend your rules.

TAKeanice commented 3 years ago

I must say I really hate not being able to use full logic in Smart Folders, filters etc.. I am angry every time I try to filter my emails and can only select "all" (everything AND) or "any" of the conditions (everything OR). Guess I will make this the next project to work on in Vienna.

If any of you feel like some programming on their favorite news reader in their spare time, we're glad about any help!

Eitot commented 3 years ago

Apple has a native API for this filter UI called NSPredicateEditor. You can see it in action in Finder smart folders. Unfortunately, it is one of those older, obscure APIs for which there is little documentation by Apple. I think it supports this behaviour where you can create sub-filters by holding down the option key too, just like you can do in Finder.

It is not straightforward to adopt, since NSPredicateEditor is based upon the SQL-based NSPredicate syntax to combine the filters into a query. Vienna instead uses a custom XML-format to store the query in the database. It then converts that XML query into instances of Criteria and builds a CriteriaTree collection for the database queries. To maintain backwards compatibility, those XML-based queries would have to be translated/converted into the SQL-based NSPredicate format that Apple uses and the Criteria and CriteriaTree classes would have to replaced or rewritten as well.

TAKeanice commented 2 years ago

I had a look at this some time ago but didn't find enough time to implement the change, but I still feel committed to doing it.

I am not sure if we should transfer existing smart folders to the new system though, since it would make the implementation more difficult. I'd rather reimplement the whole predicate system

Eitot commented 2 years ago

I think we should drop the custom XML-based format and use NSPredicate where possible. NSPredicate and the cluster classes NSComparisonPredicate and NSCompoundPredicate all conform to NSSecureCoding, so they can be archived in a text format. Vienna already has code that converts the XML-format into a SQL-formatted string, which could be repurposed for a database migration.

I have a WIP progress branch as well which mostly focusses on the NSPredicateEditorRowTemplate side. The challenges I am currently facing is that not all of Vienna’s operators are supported in the same way by NSPredicate, e.g. the NOT LIKE operator does not exist for NSComparisonPredicate, instead you have to embed it in an NSCompoundPredicate (with a NSNotPredicateType), which looks weird in the UI. Another thing I noticed is that NSPredicate is not a 100% match for SQL syntax, so it might still be necessary to process the NSPredicate before it is used on the database.

TAKeanice commented 2 years ago

Isn't it possible to introduce custom operators by subclassing NSPredicateEditorRowTemplate? As far as I understand, it only has to return a high value in match(for:) to be chosen to display the compound not(like) predicate

Eitot commented 2 years ago

I suppose you could make it so that input predicate and output predicate is an NSCompoundPredicate, but visually it is shown like a simple comparison template.

TAKeanice commented 2 years ago

but visually it is shown like a simple comparison template.

Exactly that. Simplifying the representation is enough, having it as a compound predicate in the model space is cleaner.

Eitot commented 2 years ago

This is as far as I got UI-wise (basically a subclass of NSPredicateEditorRowTemplate). It still needs some logic for the folder/feed names and the above-mentioned workaround. I have not started on the implementation in SearchFolder (or Database) yet.

Screenshot 2022-06-19 at 18 12 47 Screenshot 2022-06-19 at 18 12 55

Another shortcoming is that the pop-up buttons sadly cannot have any images. I could not find a way to do this. This is why I made separate entries for feeds and folders here.

TAKeanice commented 2 years ago

I cannot see your feature branch, is it only local?

Eitot commented 2 years ago

That's right, I have not published it yet. I will go over it this weekend and clean up all the test code I added.

TAKeanice commented 2 years ago

Don't worry about test code, you can still force-push everything later! I would really like to look at it tonight (currently in Indonesia, so tonight starts in about 4h ;) )