vienna-rss icon indicating copy to clipboard operation
vienna-rss copied to clipboard

Layered customization with "ALL/ANY" of Smart Folders

Open sherlock440 opened this issue 3 years ago • 13 comments

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" ---- ... = ...

sherlock440 avatar May 17 '21 22:05 sherlock440

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 avatar Jun 13 '21 18:06 xanoni

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.

xanoni avatar Jun 13 '21 19:06 xanoni

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!

TAKeanice avatar Jun 14 '21 05:06 TAKeanice

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.

Eitot avatar Jun 17 '21 05:06 Eitot

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

TAKeanice avatar Jun 19 '22 14:06 TAKeanice

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.

Eitot avatar Jun 19 '22 14:06 Eitot

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

TAKeanice avatar Jun 19 '22 15:06 TAKeanice

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.

Eitot avatar Jun 19 '22 15:06 Eitot

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.

TAKeanice avatar Jun 19 '22 15:06 TAKeanice

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.

Eitot avatar Jun 19 '22 16:06 Eitot

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

TAKeanice avatar Jun 20 '22 01:06 TAKeanice

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.

Eitot avatar Jun 21 '22 07:06 Eitot

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 ;) )

TAKeanice avatar Jun 21 '22 09:06 TAKeanice