Closed RealRaven2000 closed 1 year ago
The code that inserted the search term at the top position had to be removed because the function insertElementAt(term, 0) had been removed by Mozilla.
https://github.com/RealRaven2000/quickFilters/blob/ESR102/chrome/content/qFilters-worker.js#L789
In Thunderbird 102 an exception is thrown and the search term is appended to the end.
try {
// [Bug 26664] add condition on top instead of appending at bottom
let ts = target.searchTerms; // returns nsIMutableArray
ts.insertElementAt(term, 0);
}
catch (ex) {
util.logException("Could not insert term at top - appending to end instead.", ex);
target.appendTerm(term);
}
Fixing it is not quite as trivial as it seems...
Apparently we need to clone the array, then we can do all the modifications - later on we write back across the XPCOM boundaries. The attribute itself is not readonly:
attribute Array<nsIMsgSearchTerm> searchTerms;
my first attempt is based on this core code:
let terms = target.searchTerms.Clone();
if (bGrouping) {
term.beginsGrouping = bGrouping;
terms[0].beginsGrouping =
(typeof term.beginsGrouping == "number") ? 0 : false; // Betterbird stores number of parentheses
}
term.booleanAnd = terms[0].booleanAnd;
terms.splice(0,0,term);
target.searchTerms = terms; // write back!
...but unfortunately this doesn't work because termList.Clone()
only exists in C++ (beyond the XPCOM barrier)
Looks like the call to Clone()
wasn't necessary (or possible) - the getter (called when we are reading searchTerms
) automatically returns a cloned array. So the new code is simply:
let terms = target.searchTerms;
if (bGrouping) {
term.beginsGrouping = bGrouping;
terms[0].beginsGrouping =
(typeof term.beginsGrouping == "number") ? 0 : false; // Betterbird stores number of parentheses
}
term.booleanAnd = terms[0].booleanAnd;
terms.splice(0,0,term);
target.searchTerms = terms; // write back!
.. with a bit of a speed penalty.
Here is a version with a fix. I also added change log and translated into the 19 other languages, as I intend to publish soon this week.
To test the version above, download the zip file and drag it into Thunderbird Add-ons manager (without extracting the contents!). Github does not allow attaching xpi files but zip files work just as well.
Fixed in v5.9 - Published 28/03/2023
The option to add new filter rules to the top of the list when merging, which is in the section Merge Rules, doesn't work anymore. New rules are always appended to the end of the list: