Implement kicking and fix invites
This commit is contained in:
@@ -95,9 +95,9 @@ does not do this automatically.
|
|||||||
* [x] Typing notifications
|
* [x] Typing notifications
|
||||||
* [ ] Pinning messages
|
* [ ] Pinning messages
|
||||||
* [ ] Admin status
|
* [ ] Admin status
|
||||||
* [ ] Membership actions
|
* [x] Membership actions
|
||||||
* [ ] Inviting
|
* [x] Inviting
|
||||||
* [ ] Kicking (currently shown as leaving)
|
* [x] Kicking
|
||||||
* [x] Joining/leaving
|
* [x] Joining/leaving
|
||||||
* [x] Chat metadata changes
|
* [x] Chat metadata changes
|
||||||
* [ ] Public channel username changes
|
* [ ] Public channel username changes
|
||||||
@@ -105,7 +105,7 @@ does not do this automatically.
|
|||||||
* [x] Supergroup upgrade
|
* [x] Supergroup upgrade
|
||||||
* Initiating chats
|
* Initiating chats
|
||||||
* [x] Automatic portal creation for groups/channels at startup
|
* [x] Automatic portal creation for groups/channels at startup
|
||||||
* [ ] Automatic portal creation for groups/channels when receiving invite/message
|
* [x] Automatic portal creation for groups/channels when receiving invite/message
|
||||||
* [ ] Private chat creation by inviting Telegram user to new room
|
* [ ] Private chat creation by inviting Telegram user to new room
|
||||||
* [ ] Joining public channels/supergroups using room aliases
|
* [ ] Joining public channels/supergroups using room aliases
|
||||||
* [ ] Searching for Telegram users using management commands
|
* [ ] Searching for Telegram users using management commands
|
||||||
|
|||||||
@@ -245,6 +245,10 @@ class IntentAPI:
|
|||||||
def send_message(self, room_id, body):
|
def send_message(self, room_id, body):
|
||||||
return self.send_event(room_id, "m.room.message", body)
|
return self.send_event(room_id, "m.room.message", body)
|
||||||
|
|
||||||
|
def kick(self, room_id, user_id, message):
|
||||||
|
self._ensure_joined(room_id)
|
||||||
|
self.client.kick_user(room_id, user_id, message)
|
||||||
|
|
||||||
def send_event(self, room_id, type, body, txn_id=None, timestamp=None):
|
def send_event(self, room_id, type, body, txn_id=None, timestamp=None):
|
||||||
self._ensure_joined(room_id)
|
self._ensure_joined(room_id)
|
||||||
self._ensure_has_power_level_for(room_id, type)
|
self._ensure_has_power_level_for(room_id, type)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from telethon.tl.types import *
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import magic
|
import magic
|
||||||
from .db import Portal as DBPortal, Message as DBMessage
|
from .db import Portal as DBPortal, Message as DBMessage
|
||||||
from . import puppet as p, formatter
|
from . import puppet as p, user as u, formatter
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
@@ -124,9 +124,18 @@ class Portal:
|
|||||||
puppet.update_info(source, entity)
|
puppet.update_info(source, entity)
|
||||||
puppet.intent.join_room(self.mxid)
|
puppet.intent.join_room(self.mxid)
|
||||||
|
|
||||||
def delete_telegram_user(self, user_id):
|
user = u.User.get_by_tgid(user_id)
|
||||||
|
if user:
|
||||||
|
self.main_intent.invite(self.mxid, user.mxid)
|
||||||
|
|
||||||
|
def delete_telegram_user(self, user_id, kick_message=None):
|
||||||
puppet = p.Puppet.get(user_id)
|
puppet = p.Puppet.get(user_id)
|
||||||
puppet.intent.leave_room(self.mxid)
|
user = u.User.get_by_tgid(user_id)
|
||||||
|
if kick_message:
|
||||||
|
self.main_intent.kick(self.mxid, puppet.mxid, kick_message)
|
||||||
|
else:
|
||||||
|
puppet.intent.leave_room(self.mxid)
|
||||||
|
self.main_intent.kick(self.mxid, user.mxid, kick_message or "Left Telegram chat")
|
||||||
|
|
||||||
def update_info(self, user, entity=None):
|
def update_info(self, user, entity=None):
|
||||||
if self.peer_type == "user":
|
if self.peer_type == "user":
|
||||||
@@ -333,9 +342,12 @@ class Portal:
|
|||||||
|
|
||||||
def handle_telegram_action(self, source, sender, action):
|
def handle_telegram_action(self, source, sender, action):
|
||||||
if not self.mxid:
|
if not self.mxid:
|
||||||
if isinstance(action, (MessageActionChatCreate, MessageActionChannelCreate)):
|
create_and_exit = [MessageActionChatCreate, MessageActionChannelCreate]
|
||||||
|
create_and_continue = [MessageActionChatAddUser, MessageActionChatJoinedByLink]
|
||||||
|
if isinstance(action, create_and_exit + create_and_continue):
|
||||||
self.create_room(source, invites=[source.mxid])
|
self.create_room(source, invites=[source.mxid])
|
||||||
return
|
if isinstance(action, create_and_exit):
|
||||||
|
return
|
||||||
|
|
||||||
if isinstance(action, MessageActionChatEditTitle):
|
if isinstance(action, MessageActionChatEditTitle):
|
||||||
if self.update_title(action.title, self.main_intent):
|
if self.update_title(action.title, self.main_intent):
|
||||||
@@ -350,8 +362,10 @@ class Portal:
|
|||||||
elif isinstance(action, MessageActionChatJoinedByLink):
|
elif isinstance(action, MessageActionChatJoinedByLink):
|
||||||
self.add_telegram_user(sender.id, source)
|
self.add_telegram_user(sender.id, source)
|
||||||
elif isinstance(action, MessageActionChatDeleteUser):
|
elif isinstance(action, MessageActionChatDeleteUser):
|
||||||
# TODO show kick message if user was kicked
|
kick_message = None
|
||||||
self.delete_telegram_user(action.user_id)
|
if sender.id != action.user_id:
|
||||||
|
kick_message = f"Kicked by {sender.displayname}"
|
||||||
|
self.delete_telegram_user(action.user_id, kick_message)
|
||||||
elif isinstance(action, MessageActionChatMigrateTo):
|
elif isinstance(action, MessageActionChatMigrateTo):
|
||||||
self.peer_type = "channel"
|
self.peer_type = "channel"
|
||||||
self.migrate_and_save(action.channel_id)
|
self.migrate_and_save(action.channel_id)
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ class User:
|
|||||||
dialogs = self.client.get_dialogs(limit=30)
|
dialogs = self.client.get_dialogs(limit=30)
|
||||||
for dialog in dialogs:
|
for dialog in dialogs:
|
||||||
entity = dialog.entity
|
entity = dialog.entity
|
||||||
if isinstance(entity, User) \
|
if (isinstance(entity, User)
|
||||||
or (isinstance(entity, Chat) and entity.deactivated) \
|
or (isinstance(entity, Chat) and entity.deactivated)
|
||||||
or isinstance(entity, ChannelForbidden):
|
or isinstance(entity, (ChannelForbidden, ChatForbidden))):
|
||||||
continue
|
continue
|
||||||
portal = po.Portal.get_by_entity(entity)
|
portal = po.Portal.get_by_entity(entity)
|
||||||
portal.create_room(self, entity, invites=[self.mxid])
|
portal.create_room(self, entity, invites=[self.mxid])
|
||||||
|
|||||||
Reference in New Issue
Block a user