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

Create private chats with the is_direct flag #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions heisenbridge/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ async def load(self):
async def save(self):
await self.az.intent.set_account_data("irc", self.config)

async def create_room(self, name: str, topic: str, invite: List[str], restricted: str = None) -> str:
async def create_room(self, name: str, topic: str, invite: List[str], restricted: str = None, as_user: str = None, is_direct: bool = False) -> str:
req = {
"visibility": "private",
"name": name,
"topic": topic,
"invite": invite,
"is_direct": False,
"is_direct": is_direct,
"power_level_content_override": {
"users_default": 0,
"invite": 100,
Expand Down Expand Up @@ -70,7 +70,8 @@ async def create_room(self, name: str, topic: str, invite: List[str], restricted
}
]

resp = await self.az.intent.api.request(Method.POST, Path.v3.createRoom, req)
intent = self.az.intent.user(as_user) if as_user else self.az.intent
resp = await intent.api.request(Method.POST, Path.v3.createRoom, req)

return resp["room_id"]

Expand Down
9 changes: 7 additions & 2 deletions heisenbridge/private_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from mautrix.types.event.state import JoinRestrictionType
from mautrix.types.event.state import JoinRule
from mautrix.types.event.state import JoinRulesStateEventContent
from mautrix.types.event.state import PowerLevelStateEventContent
from mautrix.types.event.type import EventType

from heisenbridge.command_parse import CommandManager
Expand Down Expand Up @@ -468,10 +469,14 @@ async def _create_mx(self, displayname) -> None:
self.id = await self.network.serv.create_room(
"{} ({})".format(displayname, self.network.name),
"Private chat with {} on {}".format(displayname, self.network.name),
[self.network.user_id, irc_user_id],
[self.network.user_id, self.network.serv.user_id],
as_user=irc_user_id, is_direct=True,
)
self.serv.register_room(self)
await self.az.intent.user(irc_user_id).ensure_joined(self.id)
await self.az.intent.ensure_joined(self.id)
power_levels = PowerLevelStateEventContent()
power_levels.set_user_level(self.network.serv.user_id, 100)
await self.az.intent.user(irc_user_id).set_power_levels(self.id, power_levels)
await self.save()
# start event queue now that we have an id
self._queue.start()
Expand Down