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
|
- Horrible performance for big rooms
|
||||||
|
|
||||||
- UI
|
- UI
|
||||||
|
- Need to make events and messages avatars the same size
|
||||||
- Show error box if uploading avatar fails
|
- Show error box if uploading avatar fails
|
||||||
- EditAccount page:
|
- EditAccount page:
|
||||||
- Device settings
|
- Device settings
|
||||||
|
|
|
@ -36,8 +36,12 @@ class HtmlFilter:
|
||||||
return self.filter(self._markdown_to_html(text))
|
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:
|
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:
|
def filter(self, html: str) -> str:
|
||||||
|
|
|
@ -155,15 +155,27 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def send_markdown(self, room_id: str, text: str) -> None:
|
async def send_markdown(self, room_id: str, text: str) -> None:
|
||||||
content = {"body": text, "msgtype": "m.text"}
|
escape = False
|
||||||
to_html = HTML_FILTER.from_markdown(text)
|
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>"):
|
if to_html not in (text, f"<p>{text}</p>"):
|
||||||
content["format"] = "org.matrix.custom.html"
|
content["format"] = "org.matrix.custom.html"
|
||||||
content["formatted_body"] = to_html
|
content["formatted_body"] = to_html
|
||||||
|
|
||||||
TimelineMessageReceived(
|
TimelineMessageReceived(
|
||||||
event_type = nio.RoomMessageText,
|
event_type = event_type,
|
||||||
room_id = room_id,
|
room_id = room_id,
|
||||||
event_id = f"local_echo.{uuid4()}",
|
event_id = f"local_echo.{uuid4()}",
|
||||||
sender_id = self.user_id,
|
sender_id = self.user_id,
|
||||||
|
|
|
@ -36,6 +36,13 @@ Column {
|
||||||
model.date &&
|
model.date &&
|
||||||
previousItem && previousItem.eventType && previousItem.date &&
|
previousItem && previousItem.eventType && previousItem.date &&
|
||||||
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
|
Utils.eventIsMessage(previousItem) == Utils.eventIsMessage(model) &&
|
||||||
|
|
||||||
|
// RoomMessageEmote are shown inline-style
|
||||||
|
! (previousItem.eventType == "RoomMessageEmote" &&
|
||||||
|
model.eventType != "RoomMessageEmote") &&
|
||||||
|
! (previousItem.eventType != "RoomMessageEmote" &&
|
||||||
|
model.eventType == "RoomMessageEmote") &&
|
||||||
|
|
||||||
! talkBreak &&
|
! talkBreak &&
|
||||||
! dayBreak &&
|
! dayBreak &&
|
||||||
previousItem.senderId === model.senderId &&
|
previousItem.senderId === model.senderId &&
|
||||||
|
|
|
@ -51,7 +51,8 @@ HInteractiveRectangle {
|
||||||
function getText(ev) {
|
function getText(ev) {
|
||||||
if (! ev) { return "" }
|
if (! ev) { return "" }
|
||||||
|
|
||||||
if (! Utils.eventIsMessage(ev)) {
|
if (ev.eventType == "RoomMessageEmote" ||
|
||||||
|
! Utils.eventIsMessage(ev)) {
|
||||||
return Utils.translatedEventContent(ev)
|
return Utils.translatedEventContent(ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user