Add /me command

This commit is contained in:
miruka 2019-07-19 20:55:52 -04:00
parent 58079a4ac2
commit ecc2c099f1
5 changed files with 30 additions and 5 deletions

View File

@ -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

View File

@ -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:

View File

@ -155,15 +155,27 @@ class MatrixClient(nio.AsyncClient):
async def send_markdown(self, room_id: str, text: str) -> None:
content = {"body": text, "msgtype": "m.text"}
to_html = HTML_FILTER.from_markdown(text)
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)
if to_html not in (text, f"<p>{text}</p>"):
content["format"] = "org.matrix.custom.html"
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,

View File

@ -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 &&

View File

@ -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)
}