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

Feature request - inverse filters #316

Open
ghost opened this issue Oct 7, 2021 · 1 comment
Open

Feature request - inverse filters #316

ghost opened this issue Oct 7, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 7, 2021

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
Copy link
Author

ghost commented Oct 8, 2021

String result;
// OR selection (hide if subject, comment, or name match the rule)
if (autohideItem.optionSubject) {
if (subject == null) {
subject = postItem.getSubject();
}
if ((result = autohideItem.find(subject)) != null) {
return autohideItem.getReason(AutohideStorage.AutohideItem
.ReasonSource.SUBJECT, comment, result);
}
}
if (autohideItem.optionComment) {
if (comment == null) {
comment = postItem.getComment(chan).toString();
}
if ((result = autohideItem.find(comment)) != null) {
return 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) {
if ((result = autohideItem.find(name)) != null) {
return autohideItem.getReason(AutohideStorage.AutohideItem
.ReasonSource.NAME, name, result);
}
}
}
if (autohideItem.optionFileName && postItem.hasAttachments()) {
for (AttachmentItem attachmentItem : postItem.getAttachmentItems()) {
String originalName = StringUtils.emptyIfNull(attachmentItem.getOriginalName());
if ((result = autohideItem.find(originalName)) != null) {
return autohideItem.getReason(AutohideStorage.AutohideItem
.ReasonSource.FILE, originalName, result);
}
}
}

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

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

No branches or pull requests

0 participants