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.bridge import BasePortal, NotificationDisabler
from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType, from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType,
TextMessageEventContent, MediaMessageEventContent, Membership, TextMessageEventContent, MediaMessageEventContent, Membership,
ContentURI, EncryptedFile, ImageInfo) ContentURI, EncryptedFile, ImageInfo,
RelatesTo, RelationType)
from mautrix.errors import MatrixError from mautrix.errors import MatrixError
from mautrix.util.simple_lock import SimpleLock from mautrix.util.simple_lock import SimpleLock
from mautrix.util.network_retry import call_with_net_retry 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) await self._send_delivery_receipt(event_id)
self.log.debug(f"Handled Matrix message {event_id} -> {message_id}") self.log.debug(f"Handled Matrix message {event_id} -> {message_id}")
else: 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}") self.log.warning(f"Handled Matrix message {event_id} -> {message_id}")
async def handle_matrix_leave(self, user: 'u.User') -> None: async def handle_matrix_leave(self, user: 'u.User') -> None:
@ -514,8 +519,6 @@ class Portal(DBPortal, BasePortal):
self.name = None self.name = None
self.icon_path = None self.icon_path = None
self.icon_mxc = None self.icon_mxc = None
self.name_set = False
self.icon_set = False
self.encrypted = False self.encrypted = False
await self.update() await self.update()

View File

@ -225,16 +225,27 @@ class MautrixController {
let resolve let resolve
let reject let reject
const resolveMessage = () => {
observer.disconnect()
observer = null
window.__mautrixReceiveMessageID(msgID)
resolve(msgID)
}
const invisibleTimeCallback = (changes) => { const invisibleTimeCallback = (changes) => {
for (const change of changes) { for (const change of changes) {
for (const addedNode of change.addedNodes) { for (const addedNode of change.addedNodes) {
if (addedNode.classList.contains("mdRGT07Own")) { if (addedNode.classList.contains("mdRGT07Own")) {
const timeElement = addedNode.querySelector("time.MdNonDisp") const timeElement = addedNode.querySelector("time")
if (timeElement) { if (timeElement) {
msgID = +addedNode.getAttribute("data-local-id") msgID = +addedNode.getAttribute("data-local-id")
observer.disconnect() if (timeElement.classList.contains(".MdNonDisp")) {
observer = new MutationObserver(visibleTimeCallback) observer.disconnect()
observer.observe(timeElement, { attributes: true, attributeFilter: ["class"] }) observer = new MutationObserver(visibleTimeCallback)
observer.observe(timeElement, { attributes: true, attributeFilter: ["class"] })
} else {
resolveMessage()
}
return return
} }
} }
@ -245,9 +256,7 @@ class MautrixController {
const visibleTimeCallback = (changes) => { const visibleTimeCallback = (changes) => {
for (const change of changes) { for (const change of changes) {
if (!change.target.classList.contains("MdNonDisp")) { if (!change.target.classList.contains("MdNonDisp")) {
window.__mautrixReceiveMessageID(msgID) resolveMessage()
observer.disconnect()
resolve(msgID)
return return
} }
} }
@ -262,7 +271,12 @@ class MautrixController {
resolve = realResolve resolve = realResolve
reject = realReject reject = realReject
// TODO Handle a timeout better than this // 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( const promise = this.page.evaluate(
() => window.__mautrixController.promiseOwnMessage()) () => window.__mautrixController.promiseOwnMessage())
// TODO Exit when the attach button is unclickable, try {
// like in chats with a bot this.log(`About to ask for file chooser in ${chatID}`)
const [fileChooser] = await Promise.all([ const [fileChooser] = await Promise.all([
this.page.waitForFileChooser(), this.page.waitForFileChooser(),
this.page.click("#_chat_room_plus_btn") this.page.click("#_chat_room_plus_btn")
]) ])
await fileChooser.accept([filePath]) 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 // TODO Commonize with text message sending
try { try {