async def handle_matrix_message(self, sender: 'u.User', message: MessageEventContent, event_id: EventID) -> None: if ((message.get(self.bridge.real_user_content_key, False) and await p.Puppet.get_by_custom_mxid(sender.mxid))): self.log.debug( f"Ignoring puppet-sent message by confirmed puppet user {sender.mxid}" ) return request_id = int(time.time() * 1000) self._msgts_dedup.appendleft((sender.uuid, request_id)) quote = None if message.get_reply_to(): reply = await DBMessage.get_by_mxid(message.get_reply_to(), self.mxid) # TODO include actual text? either store in db or fetch event from homeserver quote = Quote(id=reply.timestamp, author=Address(uuid=reply.sender), text="") text = message.body attachments: Optional[List[Attachment]] = None attachment_path: Optional[str] = None if message.msgtype == MessageType.EMOTE: text = f"/me {text}" elif message.msgtype.is_media: attachment_path = await self._download_matrix_media(message) attachment = self._make_attachment(message, attachment_path) attachments = [attachment] text = None self.log.trace("Formed outgoing attachment %s", attachment) await self.signal.send(username=sender.username, recipient=self.recipient, body=text, quote=quote, attachments=attachments, timestamp=request_id) msg = DBMessage(mxid=event_id, mx_room=self.mxid, sender=sender.uuid, timestamp=request_id, signal_chat_id=self.chat_id, signal_receiver=self.receiver) await msg.insert() await self._send_delivery_receipt(event_id) self.log.debug(f"Handled Matrix message {event_id} -> {request_id}") if attachment_path and self.config["signal.remove_file_after_handling"]: try: os.remove(attachment_path) except FileNotFoundError: pass
async def matrix_reply_to_telegram( content: MessageEventContent, tg_space: TelegramID, room_id: RoomID | None = None) -> TelegramID | None: event_id = content.get_reply_to() if not event_id: return content.trim_reply_fallback() message = await DBMessage.get_by_mxid(event_id, room_id, tg_space) if message: return message.tgid return None
def matrix_reply_to_telegram( content: MessageEventContent, tg_space: TelegramID, room_id: Optional[RoomID] = None) -> Optional[TelegramID]: event_id = content.get_reply_to() if not event_id: return content.trim_reply_fallback() message = DBMessage.get_by_mxid(event_id, room_id, tg_space) if message: return message.tgid return None