mirror of
https://github.com/mautrix/telegram.git
synced 2026-05-17 07:25:46 +03:00
Add aliases to public channels/supergroups
This commit is contained in:
@@ -80,7 +80,9 @@ The bridge does not do this automatically.
|
||||
* [x] Inviting puppets
|
||||
* [ ] Inviting Matrix users who have logged in to Telegram
|
||||
* [x] Kicking
|
||||
* [ ] Joining (once room aliases have been implemented)
|
||||
* [ ] Joining
|
||||
* [ ] Chat name as alias
|
||||
* [ ] Chat invite link as alias
|
||||
* [x] Leaving
|
||||
* [x] Room metadata changes (name, topic, avatar)
|
||||
* [x] Initial room metadata
|
||||
@@ -123,9 +125,6 @@ The bridge does not do this automatically.
|
||||
* [x] Private chat creation by inviting Matrix puppet of Telegram user to new room
|
||||
* [ ] Option to use bot to relay messages for unauthenticated Matrix users
|
||||
* [ ] Option to use own Matrix account for messages sent from other Telegram clients
|
||||
* [ ] Joining chats with room aliases
|
||||
* [ ] Name of public channel/supergroup as alias
|
||||
* [ ] (Maybe) Invite link token as alias
|
||||
* Commands
|
||||
* [x] Logging in and out (`login` + code entering, `logout`)
|
||||
* [ ] Registering (`register`)
|
||||
|
||||
@@ -93,8 +93,8 @@ class AppService:
|
||||
self.loop = loop or asyncio.get_event_loop()
|
||||
self.log = log or logging.getLogger("mautrix_appservice")
|
||||
|
||||
self.query_user = query_user or (lambda: None)
|
||||
self.query_alias = query_alias or (lambda: None)
|
||||
self.query_user = query_user or (lambda user: None)
|
||||
self.query_alias = query_alias or (lambda alias: None)
|
||||
|
||||
self.event_handlers = []
|
||||
|
||||
@@ -123,8 +123,9 @@ class AppService:
|
||||
@contextmanager
|
||||
def run(self, host="127.0.0.1", port=8080):
|
||||
self._http_session = aiohttp.ClientSession(loop=self.loop)
|
||||
self._intent = HTTPAPI(base_url=self.server, bot_mxid=self.bot_mxid, token=self.as_token,
|
||||
log=self.log, state_store=self.state_store).bot_intent()
|
||||
self._intent = HTTPAPI(base_url=self.server, domain=self.domain, bot_mxid=self.bot_mxid,
|
||||
token=self.as_token, log=self.log,
|
||||
state_store=self.state_store).bot_intent()
|
||||
|
||||
yield partial(aiohttp.web.run_app, self.app, host=host, port=port)
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@ from matrix_client.errors import MatrixRequestError
|
||||
|
||||
|
||||
class HTTPAPI(MatrixHttpApi):
|
||||
def __init__(self, base_url, bot_mxid=None, token=None, identity=None, log=None,
|
||||
def __init__(self, base_url, domain=None, bot_mxid=None, token=None, identity=None, log=None,
|
||||
state_store=None):
|
||||
self.base_url = base_url
|
||||
self.domain = domain
|
||||
self.token = token
|
||||
self.identity = identity
|
||||
self.txn_id = 0
|
||||
@@ -110,6 +111,7 @@ class ChildHTTPAPI(HTTPAPI):
|
||||
self.base_url = parent.base_url
|
||||
self.validate_cert = parent.validate_cert
|
||||
self.log = parent.log
|
||||
self.domain = parent.domain
|
||||
self.parent = parent
|
||||
|
||||
@property
|
||||
@@ -213,11 +215,11 @@ class IntentAPI:
|
||||
|
||||
def add_room_alias(self, room_id, alias):
|
||||
self._ensure_registered()
|
||||
self.client.set_room_alias(room_id, alias)
|
||||
self.client.set_room_alias(room_id, f"#{alias}:{self.client.domain}")
|
||||
|
||||
def remove_room_alias(self, alias):
|
||||
self._ensure_registered()
|
||||
self.client.remove_room_alias(alias)
|
||||
self.client.remove_room_alias(f"#{alias}:{self.client.domain}")
|
||||
|
||||
def set_room_name(self, room_id, name):
|
||||
self._ensure_joined(room_id)
|
||||
|
||||
@@ -121,25 +121,28 @@ class Portal:
|
||||
self.log.debug(f"Creating room for {self.tgid_log}")
|
||||
|
||||
try:
|
||||
title = entity.title
|
||||
self.title = entity.title
|
||||
except AttributeError:
|
||||
title = None
|
||||
self.title = None
|
||||
|
||||
puppet = p.Puppet.get(self.tgid) if direct else None
|
||||
intent = puppet.intent if direct else self.az.intent
|
||||
|
||||
# TODO fix aliases and enable
|
||||
# if self.peer_type == "channel" and entity.username:
|
||||
# public = True
|
||||
# alias = self._get_room_alias(entity.username)
|
||||
# else:
|
||||
# public = False
|
||||
# # TODO invite link alias?
|
||||
# alias = None
|
||||
if self.peer_type == "channel" and entity.username:
|
||||
# TODO make public once safe
|
||||
public = False
|
||||
alias = self._get_room_alias(entity.username)
|
||||
self.username = entity.username
|
||||
else:
|
||||
public = False
|
||||
# TODO invite link alias?
|
||||
alias = None
|
||||
|
||||
# room = intent.create_room(alias=alias, is_public=public, invitees=invites, name=title,
|
||||
# is_direct=direct)
|
||||
room = intent.create_room(invitees=invites, name=title, is_direct=direct)
|
||||
if alias:
|
||||
# TODO properly handle existing room aliases
|
||||
intent.remove_room_alias(alias)
|
||||
room = intent.create_room(alias=alias, is_public=public, invitees=invites, name=self.title,
|
||||
is_direct=direct)
|
||||
if not room:
|
||||
raise Exception(f"Failed to create room for {self.tgid_log}")
|
||||
|
||||
@@ -216,12 +219,11 @@ class Portal:
|
||||
|
||||
def update_username(self, username):
|
||||
if self.username != username:
|
||||
# TODO fix aliases and enable
|
||||
# if self.username:
|
||||
# self.main_intent.remove_room_alias(self._get_room_alias())
|
||||
if self.username:
|
||||
self.main_intent.remove_room_alias(self._get_room_alias())
|
||||
self.username = username
|
||||
# if self.username:
|
||||
# self.main_intent.add_room_alias(self.mxid, self._get_room_alias())
|
||||
if self.username:
|
||||
self.main_intent.add_room_alias(self.mxid, self._get_room_alias())
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user