Repository navigation
Hide Spam and unknown-sender chats via bridge.conf #49
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env python3 | ||
| """chat.is_filtered: 0 inbox, 1 unknown senders, 2 Spam. | ||
|
|
||
| The iPhone badge ignores 1 and 2. Blip counted them until --hide-spam / | ||
| --hide-unknown. The predicate is the whole feature; the queries AND it in. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| import unittest | ||
| from importlib.machinery import SourceFileLoader | ||
| from importlib.util import module_from_spec, spec_from_loader | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
|
|
||
| IMSG = Path(__file__).with_name("imsg") | ||
|
|
||
|
|
||
| def load_imsg(): | ||
| loader = SourceFileLoader("blip_imsg_filtered", str(IMSG)) | ||
| spec = spec_from_loader(loader.name, loader) | ||
| assert spec is not None | ||
| mod = module_from_spec(spec) | ||
| sys.modules[loader.name] = mod | ||
| loader.exec_module(mod) | ||
| return mod | ||
|
|
||
|
|
||
| class Predicate(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| self.fn = load_imsg().filtered_chat_predicate | ||
|
|
||
| def test_off_is_empty(self) -> None: | ||
| self.assertEqual(self.fn(False, False, True), "") | ||
|
|
||
| def test_no_column_is_empty_even_when_asked(self) -> None: | ||
| self.assertEqual(self.fn(True, True, False), "") | ||
|
|
||
| def test_spam_skips_2(self) -> None: | ||
| sql = self.fn(True, False, True) | ||
| self.assertIn("NOT IN (2)", sql) | ||
| self.assertNotIn("1", sql) | ||
| self.assertIn("c.ROWID IS NULL", sql) | ||
|
|
||
| def test_unknown_skips_1(self) -> None: | ||
| sql = self.fn(False, True, True) | ||
| self.assertIn("NOT IN (1)", sql) | ||
| self.assertNotIn("2", sql) | ||
|
|
||
| def test_both_skip_1_and_2(self) -> None: | ||
| sql = self.fn(True, True, True) | ||
| self.assertIn("NOT IN (1, 2)", sql) | ||
|
|
||
|
|
||
| class ClauseGlue(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| self.mod = load_imsg() | ||
|
|
||
| def test_no_flags_no_sql(self) -> None: | ||
| args = SimpleNamespace(hide_spam=False, hide_unknown=False) | ||
| self.mod._CHAT_COLS = {"guid"} # schema without is_filtered | ||
| self.assertEqual(self.mod.chat_filter_sql(None, args, already_where=False), "") | ||
|
|
||
| def test_where_vs_and(self) -> None: | ||
| args = SimpleNamespace(hide_spam=True, hide_unknown=False) | ||
| self.mod._CHAT_COLS = {"is_filtered"} | ||
| where = self.mod.chat_filter_sql(None, args, already_where=False) | ||
| anda = self.mod.chat_filter_sql(None, args, already_where=True) | ||
| self.assertTrue(where.startswith(" WHERE ")) | ||
| self.assertTrue(anda.startswith(" AND ")) | ||
| self.assertIn("NOT IN (2)", where) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented alternative does not enable this feature for an existing installation: copying only
bridge/mac/imsgadds support for the flags, but the old Linux shim never readshide_spamorhide_unknownand therefore never supplies those flags. Users following this parenthetical will see no filtering; instruct them to update bothbridge/mac/imsgandbridge/linux/blip-shim, as the commit message already does.Useful? React with 👍 / 👎.