-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #83 Signed-off-by: Sumner Evans <[email protected]>
- Loading branch information
1 parent
12f42ab
commit ad13888
Showing
6 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .auth import SECTION_AUTH, login | ||
from .spaces import SECTION_SPACES | ||
|
||
__all__ = ("SECTION_AUTH", "login") | ||
__all__ = ("SECTION_AUTH", "SECTION_SPACES", "login") |
This file contains 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,63 @@ | ||
import logging | ||
|
||
from mautrix.bridge.commands import HelpSection, command_handler | ||
from mautrix.types import EventType | ||
|
||
from ..portal import Portal | ||
from ..puppet import Puppet | ||
from .typehint import CommandEvent | ||
|
||
SECTION_SPACES = HelpSection("Miscellaneous", 30, "") | ||
|
||
|
||
@command_handler( | ||
needs_auth=True, | ||
management_only=False, | ||
help_section=SECTION_SPACES, | ||
help_text="Synchronize your personal filtering space", | ||
) | ||
async def sync_space(evt: CommandEvent): | ||
if not evt.bridge.config["bridge.space_support.enable"]: | ||
await evt.reply("Spaces are not enabled on this instance of the bridge") | ||
return | ||
|
||
await evt.sender.create_or_update_space() | ||
|
||
if not evt.sender.space_mxid: | ||
await evt.reply("Failed to create or update space") | ||
return | ||
|
||
async for portal in Portal.all(): | ||
if not portal.mxid: | ||
logging.debug(f"Portal {portal} has no mxid") | ||
continue | ||
if portal.li_receiver_urn != evt.sender.li_member_urn: | ||
logging.debug(f"Portal {portal} does not belong to {evt.sender}") | ||
continue | ||
|
||
logging.debug(f"Adding chat {portal.mxid} to user's space ({evt.sender.space_mxid})") | ||
try: | ||
await evt.bridge.az.intent.send_state_event( | ||
evt.sender.space_mxid, | ||
EventType.SPACE_CHILD, | ||
{"via": [evt.bridge.config["homeserver.domain"]], "suggested": True}, | ||
state_key=str(portal.mxid), | ||
) | ||
except Exception: | ||
logging.warning( | ||
f"Failed to add chat {portal.mxid} to user's space ({evt.sender.space_mxid})" | ||
) | ||
|
||
if not portal.li_is_group_chat: | ||
logging.debug(f"Adding puppet {portal.li_other_user_urn} to user's space") | ||
puppet = await Puppet.get_by_li_member_urn(portal.li_other_user_urn, create=False) | ||
if not puppet: | ||
continue | ||
try: | ||
await puppet.intent.ensure_joined(evt.sender.space_mxid) | ||
except Exception as e: | ||
logging.warning( | ||
f"Failed to join {puppet.mxid} to user's space ({evt.sender.space_mxid}): {e}" | ||
) | ||
|
||
await evt.reply("Synced space") |
This file contains 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 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 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