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

Add bridge.filter.users config option to configure filtering of direct chats #892

Merged
merged 7 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# unreleased

### Added
* Added `bridge.filter.users` config option to specify how the bridge should
handle filtering of direct messages in puppeting mode.
* Added `allow_contact_info` config option to specify whether personal names
and avatars for other users should be bridged.
* The option is only safe to enable on single-user instances, using it
Expand Down
4 changes: 4 additions & 0 deletions mautrix_telegram/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def do_update(self, helper: ConfigUpdateHelper) -> None:

copy("bridge.filter.mode")
copy("bridge.filter.list")
if "bridge.filter.users" not in self:
base["bridge.filter.users"] = True
else:
copy("bridge.filter.users")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing fields are already handled by copy

Suggested change
if "bridge.filter.users" not in self:
base["bridge.filter.users"] = True
else:
copy("bridge.filter.users")
copy("bridge.filter.users")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it provide the correct default, though...?

Or does it just set it to None?


copy("bridge.command_prefix")

Expand Down
6 changes: 5 additions & 1 deletion mautrix_telegram/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ bridge:
# Filter rooms that can/can't be bridged. Can also be managed using the `filter` and
# `filter-mode` management commands.
#
# Filters do not affect direct chats.
# An empty blacklist will essentially disable the filter.
filter:
# Filter mode to use. Either "blacklist" or "whitelist".
Expand All @@ -467,6 +466,11 @@ bridge:
mode: blacklist
# The list of group/channel IDs to filter.
list: []
# How to handle direct chats:
# If users is "null", direct chats will follow the previous settings.
# If users is "true", direct chats will always be bridged.
# If users is "false", direct chats will never be bridged.
users: true

# The prefix for commands. Only required in non-management rooms.
command_prefix: "!tg"
Expand Down
5 changes: 3 additions & 2 deletions mautrix_telegram/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ def main_intent(self) -> IntentAPI:
def allow_bridging(self) -> bool:
if self._bridging_blocked_at_runtime:
return False
elif self.peer_type == "user":
return True
elif self.peer_type == "user" and self.filter_users is not None:
return self.filter_users
elif self.filter_mode == "whitelist":
return self.tgid in self.filter_list
elif self.filter_mode == "blacklist":
Expand All @@ -440,6 +440,7 @@ def init_cls(cls, bridge: "TelegramBridge") -> None:
cls.private_chat_portal_meta = cls.config["bridge.private_chat_portal_meta"]
cls.filter_mode = cls.config["bridge.filter.mode"]
cls.filter_list = cls.config["bridge.filter.list"]
cls.filter_users: bool | None = cls.config["bridge.filter.filter_users"]
cls.hs_domain = cls.config["homeserver.domain"]
cls.backfill_msc2716 = cls.config["bridge.backfill.msc2716"]
cls.backfill_enable = cls.config["bridge.backfill.enable"]
Expand Down