Skip to content

Commit cd23618

Browse files
committed
Send MSS events for commands
1 parent fda258a commit cd23618

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

mautrix/bridge/matrix.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,28 @@ def is_command(self, message: MessageEventContent) -> tuple[bool, str]:
557557
text = text[len(prefix) + 1 :].lstrip()
558558
return is_command, text
559559

560+
async def _send_mss(
561+
self,
562+
evt: Event,
563+
status: MessageStatus,
564+
reason: MessageStatusReason | None = None,
565+
error: str | None = None,
566+
message: str | None = None,
567+
) -> None:
568+
if not self.config.get("bridge.message_status_events", False):
569+
return
570+
status_content = BeeperMessageStatusEventContent(
571+
network="", # TODO set network properly
572+
relates_to=RelatesTo(rel_type=RelationType.REFERENCE, event_id=evt.event_id),
573+
status=status,
574+
reason=reason,
575+
error=error,
576+
message=message,
577+
)
578+
await self.az.intent.send_message_event(
579+
evt.room_id, EventType.BEEPER_MESSAGE_STATUS, status_content
580+
)
581+
560582
async def _send_crypto_status_error(
561583
self,
562584
evt: Event,
@@ -594,18 +616,13 @@ async def _send_crypto_status_error(
594616
"it by default on the bridge (bridge -> encryption -> default)."
595617
)
596618

597-
if self.config.get("bridge.message_status_events", False):
598-
status_content = BeeperMessageStatusEventContent(
599-
network="", # TODO set network properly
600-
relates_to=RelatesTo(rel_type=RelationType.REFERENCE, event_id=evt.event_id),
601-
status=MessageStatus.RETRIABLE if is_final else MessageStatus.PENDING,
602-
reason=MessageStatusReason.UNDECRYPTABLE,
603-
error=msg,
604-
message=err.human_message if err else None,
605-
)
606-
await self.az.intent.send_message_event(
607-
evt.room_id, EventType.BEEPER_MESSAGE_STATUS, status_content
608-
)
619+
await self._send_mss(
620+
evt,
621+
status=MessageStatus.RETRIABLE if is_final else MessageStatus.PENDING,
622+
reason=MessageStatusReason.UNDECRYPTABLE,
623+
error=msg,
624+
message=err.human_message if err else None,
625+
)
609626

610627
return event_id
611628

@@ -697,6 +714,13 @@ async def handle_message(self, evt: MessageEvent, was_encrypted: bool = False) -
697714
except Exception as e:
698715
self.log.debug(f"Error handling command {command} from {sender}: {e}")
699716
self._send_message_checkpoint(evt, MessageSendCheckpointStep.COMMAND, e)
717+
await self._send_mss(
718+
evt,
719+
status=MessageStatus.FAIL,
720+
reason=MessageStatusReason.GENERIC_ERROR,
721+
error="",
722+
message="Command execution failed",
723+
)
700724
else:
701725
await MessageSendCheckpoint(
702726
event_id=event_id,
@@ -712,6 +736,7 @@ async def handle_message(self, evt: MessageEvent, was_encrypted: bool = False) -
712736
self.az.as_token,
713737
self.log,
714738
)
739+
await self._send_mss(evt, status=MessageStatus.SUCCESS)
715740
else:
716741
self.log.debug(
717742
f"Ignoring event {event_id} from {sender.mxid}:"
@@ -720,6 +745,13 @@ async def handle_message(self, evt: MessageEvent, was_encrypted: bool = False) -
720745
self._send_message_checkpoint(
721746
evt, MessageSendCheckpointStep.COMMAND, "not a command and not a portal room"
722747
)
748+
await self._send_mss(
749+
evt,
750+
status=MessageStatus.FAIL,
751+
reason=MessageStatusReason.UNSUPPORTED,
752+
error="Unknown room",
753+
message="Unknown room",
754+
)
723755

724756
async def _is_direct_chat(self, room_id: RoomID) -> tuple[bool, bool]:
725757
try:

0 commit comments

Comments
 (0)