Adjust thread behavior when responding
This commit is contained in:
parent
7156594858
commit
def923d444
1 changed files with 17 additions and 6 deletions
|
@ -24,6 +24,7 @@ import attr
|
||||||
from mautrix.client import Client as MatrixClient, SyncStream
|
from mautrix.client import Client as MatrixClient, SyncStream
|
||||||
from mautrix.errors import DecryptionError
|
from mautrix.errors import DecryptionError
|
||||||
from mautrix.types import (
|
from mautrix.types import (
|
||||||
|
BaseMessageEventContentFuncs,
|
||||||
EncryptedEvent,
|
EncryptedEvent,
|
||||||
Event,
|
Event,
|
||||||
EventID,
|
EventID,
|
||||||
|
@ -82,7 +83,7 @@ class MaubotMessageEvent(MessageEvent):
|
||||||
markdown: bool = True,
|
markdown: bool = True,
|
||||||
allow_html: bool = False,
|
allow_html: bool = False,
|
||||||
reply: bool | str = False,
|
reply: bool | str = False,
|
||||||
reply_in_thread: bool = False,
|
in_thread: bool | None = None,
|
||||||
edits: EventID | MessageEvent | None = None,
|
edits: EventID | MessageEvent | None = None,
|
||||||
) -> EventID:
|
) -> EventID:
|
||||||
if isinstance(content, str):
|
if isinstance(content, str):
|
||||||
|
@ -94,7 +95,19 @@ class MaubotMessageEvent(MessageEvent):
|
||||||
)
|
)
|
||||||
if edits:
|
if edits:
|
||||||
content.set_edit(edits)
|
content.set_edit(edits)
|
||||||
elif reply:
|
if (
|
||||||
|
not edits
|
||||||
|
and in_thread is not False
|
||||||
|
and (
|
||||||
|
in_thread
|
||||||
|
or (
|
||||||
|
isinstance(self.content, BaseMessageEventContentFuncs)
|
||||||
|
and self.content.get_thread_parent()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
content.set_thread_parent(self)
|
||||||
|
if reply and not edits:
|
||||||
if reply != "force" and self.disable_reply:
|
if reply != "force" and self.disable_reply:
|
||||||
content.body = f"{self.sender}: {content.body}"
|
content.body = f"{self.sender}: {content.body}"
|
||||||
fmt_body = content.formatted_body or escape(content.body).replace("\n", "<br>")
|
fmt_body = content.formatted_body or escape(content.body).replace("\n", "<br>")
|
||||||
|
@ -103,8 +116,6 @@ class MaubotMessageEvent(MessageEvent):
|
||||||
f"{self.sender}"
|
f"{self.sender}"
|
||||||
f"</a>: {fmt_body}"
|
f"</a>: {fmt_body}"
|
||||||
)
|
)
|
||||||
elif reply_in_thread:
|
|
||||||
content.set_thread_parent(self)
|
|
||||||
else:
|
else:
|
||||||
content.set_reply(self)
|
content.set_reply(self)
|
||||||
return await self.client.send_message_event(self.room_id, event_type, content)
|
return await self.client.send_message_event(self.room_id, event_type, content)
|
||||||
|
@ -115,14 +126,14 @@ class MaubotMessageEvent(MessageEvent):
|
||||||
event_type: EventType = EventType.ROOM_MESSAGE,
|
event_type: EventType = EventType.ROOM_MESSAGE,
|
||||||
markdown: bool = True,
|
markdown: bool = True,
|
||||||
allow_html: bool = False,
|
allow_html: bool = False,
|
||||||
thread: bool = False,
|
in_thread: bool | None = None,
|
||||||
) -> Awaitable[EventID]:
|
) -> Awaitable[EventID]:
|
||||||
return self.respond(
|
return self.respond(
|
||||||
content,
|
content,
|
||||||
event_type,
|
event_type,
|
||||||
markdown=markdown,
|
markdown=markdown,
|
||||||
reply=True,
|
reply=True,
|
||||||
reply_in_thread=thread,
|
in_thread=in_thread,
|
||||||
allow_html=allow_html,
|
allow_html=allow_html,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue