Mishiranu / Dashchan

Imageboards client for Android
GNU General Public License v3.0
396 stars 50 forks source link

Feature request - inverse filters #316

Open ghost opened 3 years ago

ghost commented 3 years ago

This is probably a niche feature and IDK how feasible it is but some boards I only go to for a couple of threads, with the rest of the threads being things I either don't care about or actively don't like. I think it would be cool to be able to filter everything except threads that match a topic. I can currently somewhat do it with

^(?!(.|\n)*(test1|test2|test3))

however this is very slow and only allows filtering one field at once, otherwise it just filters everything because even if it matches in the subject it gets filtered out in the comment or vice versa.

ghost commented 3 years ago

https://github.com/Mishiranu/Dashchan/blob/b78d82bd1db802ba2e0f6f4c6ebf89485d6ed3c5/src/com/mishiranu/dashchan/content/HidePerformer.java#L127-L176

I'm sure this solution isn't optimised, but changing this snippet to

String result;
String finalSearch = "";
String reason = "";
// OR selection (hide if subject, comment, or name match the rule)
if (autohideItem.optionSubject) {
    if (subject == null) {
        subject = postItem.getSubject();
        finalSearch += subject + "\n";
    }
    if ((result = autohideItem.find(subject)) != null) {
        reason = autohideItem.getReason(AutohideStorage.AutohideItem
                .ReasonSource.SUBJECT, comment, result);
    }
}
if (autohideItem.optionComment) {
    if (comment == null) {
        comment = postItem.getComment(chan).toString();
        finalSearch += comment + "\n";
    }
    if ((result = autohideItem.find(comment)) != null) {
        reason = autohideItem.getReason(AutohideStorage.AutohideItem
                .ReasonSource.COMMENT, comment, result);
    }
}
if (autohideItem.optionName) {
    if (names == null) {
        String name = postItem.getFullName(chan).toString();
        List<Post.Icon> icons = postItem.getIcons();
        if (!icons.isEmpty()) {
            names = new ArrayList<>(1 + icons.size());
            names.add(name);
            for (Post.Icon icon : icons) {
                names.add(icon.title);
            }
        } else {
            names = Collections.singletonList(name);
        }
    }
    for (String name : names) {
        finalSearch += name + "\n";
        if ((result = autohideItem.find(name)) != null) {
            reason = autohideItem.getReason(AutohideStorage.AutohideItem
                    .ReasonSource.NAME, name, result);
        }
    }
}
if (autohideItem.optionFileName && postItem.hasAttachments()) {
    for (AttachmentItem attachmentItem : postItem.getAttachmentItems()) {
        String originalName = StringUtils.emptyIfNull(attachmentItem.getOriginalName());
        originalName += subject + "\n";
        if ((result = autohideItem.find(originalName)) != null) {
            reason = autohideItem.getReason(AutohideStorage.AutohideItem
                    .ReasonSource.FILE, originalName, result);
        }
    }
}
if (autohideItem.find(finalSearch) != null) {
    return reason;
}

allows the filter to work across multiple fields however is so slow it effectively crashes when actually loading a board where the majority of posts are filtered (although this behaviour happens even when using the filter on just one field currently as well).