Outbound images, no echo

This commit is contained in:
Andrew Ferrazzutti 2021-03-28 03:16:07 -04:00
parent 36ba98fda1
commit 00e7226efe
3 changed files with 40 additions and 18 deletions

View File

@ -25,7 +25,8 @@ from mautrix.appservice import AppService, IntentAPI
from mautrix.bridge import BasePortal, NotificationDisabler
from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType,
TextMessageEventContent, MediaMessageEventContent, Membership,
ContentURI, EncryptedFile, ImageInfo)
ContentURI, EncryptedFile, ImageInfo,
RelatesTo, RelationType)
from mautrix.errors import MatrixError
from mautrix.util.simple_lock import SimpleLock
from mautrix.util.network_retry import call_with_net_retry
@ -150,6 +151,10 @@ class Portal(DBPortal, BasePortal):
await self._send_delivery_receipt(event_id)
self.log.debug(f"Handled Matrix message {event_id} -> {message_id}")
else:
await self.main_intent.send_notice(
self.mxid,
"Posting this message to LINE may have failed.",
relates_to=RelatesTo(rel_type=RelationType.REPLY, event_id=event_id))
self.log.warning(f"Handled Matrix message {event_id} -> {message_id}")
async def handle_matrix_leave(self, user: 'u.User') -> None:
@ -514,8 +519,6 @@ class Portal(DBPortal, BasePortal):
self.name = None
self.icon_path = None
self.icon_mxc = None
self.name_set = False
self.icon_set = False
self.encrypted = False
await self.update()

View File

@ -225,16 +225,27 @@ class MautrixController {
let resolve
let reject
const resolveMessage = () => {
observer.disconnect()
observer = null
window.__mautrixReceiveMessageID(msgID)
resolve(msgID)
}
const invisibleTimeCallback = (changes) => {
for (const change of changes) {
for (const addedNode of change.addedNodes) {
if (addedNode.classList.contains("mdRGT07Own")) {
const timeElement = addedNode.querySelector("time.MdNonDisp")
const timeElement = addedNode.querySelector("time")
if (timeElement) {
msgID = +addedNode.getAttribute("data-local-id")
if (timeElement.classList.contains(".MdNonDisp")) {
observer.disconnect()
observer = new MutationObserver(visibleTimeCallback)
observer.observe(timeElement, { attributes: true, attributeFilter: ["class"] })
} else {
resolveMessage()
}
return
}
}
@ -245,9 +256,7 @@ class MautrixController {
const visibleTimeCallback = (changes) => {
for (const change of changes) {
if (!change.target.classList.contains("MdNonDisp")) {
window.__mautrixReceiveMessageID(msgID)
observer.disconnect()
resolve(msgID)
resolveMessage()
return
}
}
@ -262,7 +271,12 @@ class MautrixController {
resolve = realResolve
reject = realReject
// TODO Handle a timeout better than this
setTimeout(() => { observer.disconnect(); reject() }, 10000)
setTimeout(() => {
if (observer) {
observer.disconnect()
reject()
}
}, 5000)
})
}

View File

@ -405,13 +405,18 @@ export default class MessagesPuppeteer {
const promise = this.page.evaluate(
() => window.__mautrixController.promiseOwnMessage())
// TODO Exit when the attach button is unclickable,
// like in chats with a bot
try {
this.log(`About to ask for file chooser in ${chatID}`)
const [fileChooser] = await Promise.all([
this.page.waitForFileChooser(),
this.page.click("#_chat_room_plus_btn")
])
this.log(`About to upload ${filePath}`)
await fileChooser.accept([filePath])
} catch (e) {
this.log(`Failed to upload file to ${chatID}`)
return -1
}
// TODO Commonize with text message sending
try {