Add option to only bridge mute status and tags when creating portal
This commit is contained in:
@@ -135,6 +135,7 @@ class Config(BaseBridgeConfig):
|
|||||||
copy("bridge.mute_bridging")
|
copy("bridge.mute_bridging")
|
||||||
copy("bridge.pinned_tag")
|
copy("bridge.pinned_tag")
|
||||||
copy("bridge.archive_tag")
|
copy("bridge.archive_tag")
|
||||||
|
copy("bridge.tag_only_on_create")
|
||||||
copy("bridge.backfill.invite_own_puppet")
|
copy("bridge.backfill.invite_own_puppet")
|
||||||
copy("bridge.backfill.takeout_limit")
|
copy("bridge.backfill.takeout_limit")
|
||||||
copy("bridge.backfill.initial_limit")
|
copy("bridge.backfill.initial_limit")
|
||||||
|
|||||||
@@ -280,6 +280,8 @@ bridge:
|
|||||||
pinned_tag: null
|
pinned_tag: null
|
||||||
# Same as above for archived chats, the low priority tag is `m.lowpriority`.
|
# Same as above for archived chats, the low priority tag is `m.lowpriority`.
|
||||||
archive_tag: null
|
archive_tag: null
|
||||||
|
# Whether or not mute status and tags should only be bridged when the portal room is created.
|
||||||
|
tag_only_on_create: true
|
||||||
# Settings for backfilling messages from Telegram.
|
# Settings for backfilling messages from Telegram.
|
||||||
backfill:
|
backfill:
|
||||||
# Whether or not the Telegram ghosts of logged in Matrix users should be
|
# Whether or not the Telegram ghosts of logged in Matrix users should be
|
||||||
|
|||||||
@@ -406,6 +406,8 @@ class User(AbstractUser, BaseUser):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def update_folder_peers(self, update: UpdateFolderPeers) -> None:
|
async def update_folder_peers(self, update: UpdateFolderPeers) -> None:
|
||||||
|
if config["bridge.tag_only_on_create"]:
|
||||||
|
return
|
||||||
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
||||||
if not puppet or not puppet.is_real_user:
|
if not puppet or not puppet.is_real_user:
|
||||||
return
|
return
|
||||||
@@ -415,6 +417,8 @@ class User(AbstractUser, BaseUser):
|
|||||||
peer.folder_id == 1)
|
peer.folder_id == 1)
|
||||||
|
|
||||||
async def update_pinned_dialogs(self, update: UpdatePinnedDialogs) -> None:
|
async def update_pinned_dialogs(self, update: UpdatePinnedDialogs) -> None:
|
||||||
|
if config["bridge.tag_only_on_create"]:
|
||||||
|
return
|
||||||
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
||||||
if not puppet or not puppet.is_real_user:
|
if not puppet or not puppet.is_real_user:
|
||||||
return
|
return
|
||||||
@@ -424,7 +428,9 @@ class User(AbstractUser, BaseUser):
|
|||||||
await self._tag_room(puppet, portal, config["bridge.pinned_tag"], True)
|
await self._tag_room(puppet, portal, config["bridge.pinned_tag"], True)
|
||||||
|
|
||||||
async def update_notify_settings(self, update: UpdateNotifySettings) -> None:
|
async def update_notify_settings(self, update: UpdateNotifySettings) -> None:
|
||||||
if not isinstance(update.peer, NotifyPeer):
|
if config["bridge.tag_only_on_create"]:
|
||||||
|
return
|
||||||
|
elif not isinstance(update.peer, NotifyPeer):
|
||||||
# TODO handle global notification setting changes?
|
# TODO handle global notification setting changes?
|
||||||
return
|
return
|
||||||
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
|
||||||
@@ -435,6 +441,7 @@ class User(AbstractUser, BaseUser):
|
|||||||
|
|
||||||
async def _sync_dialog(self, portal: po.Portal, dialog: Dialog, should_create: bool,
|
async def _sync_dialog(self, portal: po.Portal, dialog: Dialog, should_create: bool,
|
||||||
puppet: Optional[pu.Puppet]) -> None:
|
puppet: Optional[pu.Puppet]) -> None:
|
||||||
|
was_created = False
|
||||||
if portal.mxid:
|
if portal.mxid:
|
||||||
try:
|
try:
|
||||||
await portal.backfill(self, last_id=dialog.message.id)
|
await portal.backfill(self, last_id=dialog.message.id)
|
||||||
@@ -447,6 +454,7 @@ class User(AbstractUser, BaseUser):
|
|||||||
elif should_create:
|
elif should_create:
|
||||||
try:
|
try:
|
||||||
await portal.create_matrix_room(self, dialog.entity, invites=[self.mxid])
|
await portal.create_matrix_room(self, dialog.entity, invites=[self.mxid])
|
||||||
|
was_created = True
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception(f"Error while creating {portal.tgid_log}")
|
self.log.exception(f"Error while creating {portal.tgid_log}")
|
||||||
if portal.mxid and puppet and puppet.is_real_user:
|
if portal.mxid and puppet and puppet.is_real_user:
|
||||||
@@ -460,9 +468,10 @@ class User(AbstractUser, BaseUser):
|
|||||||
dialog.dialog.read_inbox_max_id)
|
dialog.dialog.read_inbox_max_id)
|
||||||
if last_read:
|
if last_read:
|
||||||
await puppet.intent.mark_read(last_read.mx_room, last_read.mxid)
|
await puppet.intent.mark_read(last_read.mx_room, last_read.mxid)
|
||||||
await self._mute_room(puppet, portal, dialog.dialog.notify_settings.mute_until)
|
if was_created or not config["bridge.tag_only_on_create"]:
|
||||||
await self._tag_room(puppet, portal, config["bridge.pinned_tag"], dialog.pinned)
|
await self._mute_room(puppet, portal, dialog.dialog.notify_settings.mute_until)
|
||||||
await self._tag_room(puppet, portal, config["bridge.archive_tag"], dialog.archived)
|
await self._tag_room(puppet, portal, config["bridge.pinned_tag"], dialog.pinned)
|
||||||
|
await self._tag_room(puppet, portal, config["bridge.archive_tag"], dialog.archived)
|
||||||
|
|
||||||
async def sync_dialogs(self) -> None:
|
async def sync_dialogs(self) -> None:
|
||||||
if self.is_bot:
|
if self.is_bot:
|
||||||
|
|||||||
Reference in New Issue
Block a user