Add missing checks and fix file bridging with latest Telegram API layer
Fixes #260
This commit is contained in:
@@ -89,7 +89,9 @@ def matrix_to_telegram(html: str) -> ParsedMessage:
|
|||||||
def matrix_reply_to_telegram(content: Dict[str, Any], tg_space: TelegramID,
|
def matrix_reply_to_telegram(content: Dict[str, Any], tg_space: TelegramID,
|
||||||
room_id: Optional[MatrixRoomID] = None) -> Optional[TelegramID]:
|
room_id: Optional[MatrixRoomID] = None) -> Optional[TelegramID]:
|
||||||
try:
|
try:
|
||||||
reply = content["m.relates_to"]["m.in_reply_to"]
|
reply = content.get("m.relates_to", {}).get("m.in_reply_to", {})
|
||||||
|
if not reply:
|
||||||
|
return None
|
||||||
room_id = room_id or reply["room_id"]
|
room_id = room_id or reply["room_id"]
|
||||||
event_id = reply["event_id"]
|
event_id = reply["event_id"]
|
||||||
|
|
||||||
|
|||||||
@@ -994,6 +994,10 @@ class Portal:
|
|||||||
|
|
||||||
async def handle_matrix_message(self, sender: 'u.User', message: Dict[str, Any],
|
async def handle_matrix_message(self, sender: 'u.User', message: Dict[str, Any],
|
||||||
event_id: MatrixEventID) -> None:
|
event_id: MatrixEventID) -> None:
|
||||||
|
if "body" not in message or "msgtype" not in message:
|
||||||
|
self.log.debug(f"Ignoring message {event_id} in {self.mxid} without body or msgtype")
|
||||||
|
return
|
||||||
|
|
||||||
puppet = p.Puppet.get_by_custom_mxid(sender.mxid)
|
puppet = p.Puppet.get_by_custom_mxid(sender.mxid)
|
||||||
if puppet and message.get("net.maunium.telegram.puppet", False):
|
if puppet and message.get("net.maunium.telegram.puppet", False):
|
||||||
self.log.debug("Ignoring puppet-sent message by confirmed puppet user %s", sender.mxid)
|
self.log.debug("Ignoring puppet-sent message by confirmed puppet user %s", sender.mxid)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def _read_video_thumbnail(data: bytes, video_ext: str = "mp4", frame_ext: str =
|
|||||||
|
|
||||||
def _location_to_id(location: TypeLocation) -> str:
|
def _location_to_id(location: TypeLocation) -> str:
|
||||||
if isinstance(location, (Document, InputDocumentFileLocation)):
|
if isinstance(location, (Document, InputDocumentFileLocation)):
|
||||||
return f"{location.id}-{location.version}"
|
return f"{location.id}-{location.access_hash}"
|
||||||
elif isinstance(location, (FileLocation, InputFileLocation)):
|
elif isinstance(location, (FileLocation, InputFileLocation)):
|
||||||
return f"{location.volume_id}-{location.local_id}"
|
return f"{location.volume_id}-{location.local_id}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user