Add /me command
This commit is contained in:
parent
58079a4ac2
commit
ecc2c099f1
1
TODO.md
1
TODO.md
|
@ -18,6 +18,7 @@
|
|||
- Horrible performance for big rooms
|
||||
|
||||
- UI
|
||||
- Need to make events and messages avatars the same size
|
||||
- Show error box if uploading avatar fails
|
||||
- EditAccount page:
|
||||
- Device settings
|
||||
|
|
|
@ -36,8 +36,12 @@ class HtmlFilter:
|
|||
return self.filter(self._markdown_to_html(text))
|
||||
|
||||
|
||||
def from_markdown_inline(self, text: str) -> str:
|
||||
return self.filter_inline(self._markdown_to_html(text))
|
||||
|
||||
|
||||
def filter_inline(self, html: str) -> str:
|
||||
return self._inline_sanitizer.sanitize(html)
|
||||
return self._inline_sanitizer.sanitize(html).strip("\n")
|
||||
|
||||
|
||||
def filter(self, html: str) -> str:
|
||||
|
|
|
@ -155,6 +155,18 @@ class MatrixClient(nio.AsyncClient):
|
|||
|
||||
|
||||
async def send_markdown(self, room_id: str, text: str) -> None:
|
||||
escape = False
|
||||
if text.startswith("//") or text.startswith(r"\/"):
|
||||
escape = True
|
||||
text = text[1:]
|
||||
|
||||
if text.startswith("/me ") and not escape:
|
||||
event_type = nio.RoomMessageEmote
|
||||
text = text[len("/me "): ]
|
||||
content = {"body": text, "msgtype": "m.emote"}
|
||||
to_html = HTML_FILTER.from_markdown_inline(text)
|
||||
else:
|
||||
event_type = nio.RoomMessageText
|
||||
content = {"body": text, "msgtype": "m.text"}
|
||||
to_html = HTML_FILTER.from_markdown(text)
|
||||
|
||||
|
@ -163,7 +175,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
content["formatted_body"] = to_html
|
||||
|
||||
TimelineMessageReceived(
|
||||
event_type = nio.RoomMessageText,
|
||||
event_type = event_type,
|
||||
room_id = room_id,
|
||||
event_id = f"local_echo.{uuid4()}",
|
||||
sender_id = self.user_id,
|
||||
|
|
|
@ -36,6 +36,13 @@ Column {
|
|||
model.date &&
|
||||
previousItem && previousItem.eventType && previousItem.date &&
|
||||
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
|
||||
|
||||
// RoomMessageEmote are shown inline-style
|
||||
! (previousItem.eventType == "RoomMessageEmote" &&
|
||||
model.eventType != "RoomMessageEmote") &&
|
||||
! (previousItem.eventType != "RoomMessageEmote" &&
|
||||
model.eventType == "RoomMessageEmote") &&
|
||||
|
||||
! talkBreak &&
|
||||
! dayBreak &&
|
||||
previousItem.senderId === model.senderId &&
|
||||
|
|
|
@ -51,7 +51,8 @@ HInteractiveRectangle {
|
|||
function getText(ev) {
|
||||
if (! ev) { return "" }
|
||||
|
||||
if (! Utils.eventIsMessage(ev)) {
|
||||
if (ev.eventType == "RoomMessageEmote" ||
|
||||
! Utils.eventIsMessage(ev)) {
|
||||
return Utils.translatedEventContent(ev)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user