Various fixes and cleanups

This commit is contained in:
Andrew Ferrazzutti 2021-06-05 23:41:05 -04:00
parent 2fb9be2037
commit 94788a21dd
3 changed files with 13 additions and 18 deletions

View File

@ -29,14 +29,14 @@ from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, Mess
TextMessageEventContent, MediaMessageEventContent, Membership, Format,
ContentURI, EncryptedFile, ImageInfo,
RelatesTo, RelationType)
from mautrix.errors import IntentError, MatrixError
from mautrix.errors import IntentError
from mautrix.util.simple_lock import SimpleLock
from .db import Portal as DBPortal, Message as DBMessage, ReceiptReaction as DBReceiptReaction, Media as DBMedia
from .config import Config
from .rpc import ChatInfo, Participant, Message, Receipt, Client, PathImage
from .rpc.types import RPCError
from . import user as u, puppet as p, matrix as m
from . import user as u, puppet as p
if TYPE_CHECKING:
from .__main__ import MessagesBridge
@ -170,7 +170,7 @@ class Portal(DBPortal, BasePortal):
self.log.debug(f"Handled Matrix message {event_id} -> {message_id}")
except UniqueViolationError as e:
self.log.warning(f"Failed to handle Matrix message {event_id} -> {message_id}: {e}")
if not msg:
if not msg and self.config["bridge.delivery_error_reports"]:
await self.main_intent.send_notice(
self.mxid,
"Posting this message to LINE may have failed.",
@ -179,12 +179,6 @@ class Portal(DBPortal, BasePortal):
async def handle_matrix_leave(self, user: 'u.User') -> None:
self.log.info(f"{user.mxid} left portal to {self.chat_id}, "
f"cleaning up and deleting...")
if self.invite_own_puppet_to_pm:
# TODO Use own puppet instead of bridge bot. Then cleanup_and_delete will handle it
try:
await self.az.intent.leave_room(self.mxid)
except MatrixError:
pass
await self.cleanup_and_delete()
async def _bridge_own_message_pm(self, source: 'u.User', sender: Optional['p.Puppet'], mid: str,

View File

@ -64,8 +64,9 @@ class User(DBUser, BaseUser):
cls.loop = bridge.loop
Client.config = bridge.config
async def send_notice(self, text) -> None:
async def send_bridge_notice(self, text) -> None:
if self.notice_room:
self.log.debug(f"Sending bridge notice: {text}")
await self.az.intent.send_notice(self.notice_room, text)
async def is_logged_in(self) -> bool:
@ -96,17 +97,17 @@ class User(DBUser, BaseUser):
self.loop.create_task(self.connect_double_puppet())
self.client = Client(self.mxid)
self.log.debug("Starting client")
await self.send_notice("Starting up...")
await self.send_bridge_notice("Starting up...")
state = await self.client.start()
await self.client.on_message(self.handle_message)
await self.client.on_receipt(self.handle_receipt)
if state.is_connected:
self._track_metric(METRIC_CONNECTED, True)
if state.is_logged_in:
await self.send_notice("Already logged in to LINE")
await self.send_bridge_notice("Already logged in to LINE")
self.loop.create_task(self._try_sync())
else:
await self.send_notice("Ready to log in to LINE")
await self.send_bridge_notice("Ready to log in to LINE")
async def _try_sync(self) -> None:
try:

View File

@ -34,13 +34,13 @@ window.__mautrixReceiveChanges = function (changes) {}
*/
window.__mautrixReceiveMessages = function (chatID, messages) {}
/**
* @param {str} chatID - The ID of the chat whose receipts are being processed.
* @param {str} receipt_id - The ID of the most recently-read message for the current chat.
* @param {string} chatID - The ID of the chat whose receipts are being processed.
* @param {string} receipt_id - The ID of the most recently-read message for the current chat.
* @return {Promise<void>}
*/
window.__mautrixReceiveReceiptDirectLatest = function (chat_id, receipt_id) {}
window.__mautrixReceiveReceiptDirectLatest = function (chatID, receipt_id) {}
/**
* @param {str} chatID - The ID of the chat whose receipts are being processed.
* @param {string} chatID - The ID of the chat whose receipts are being processed.
* @param {[Receipt]} receipts - All newly-seen receipts for the current chat.
* @return {Promise<void>}
*/
@ -162,7 +162,7 @@ class MautrixController {
* Try to match a user against an entry in the friends list to get their ID.
*
* @param {Element} element - The display name of the user to find the ID for.
* @return {?str} - The user's ID if found.
* @return {?string} - The user's ID if found.
*/
getUserIdFromFriendsList(senderName) {
return document.querySelector(`#contact_wrap_friends > ul > li[title='${senderName}']`)?.getAttribute("data-mid")