aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 85c4a46..8cf2e96 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -729,18 +729,11 @@ func (c *Container) MarkRead(roomID, eventID string) {
_, _ = c.client.MakeRequest("POST", urlPath, struct{}{}, nil)
}
-var mentionRegex = regexp.MustCompile("\\[(.+?)]\\(https://matrix.to/#/@.+?:.+?\\)")
-var roomRegex = regexp.MustCompile("\\[.+?]\\(https://matrix.to/#/(#.+?:[^/]+?)\\)")
-
-func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.MessageType, text string, edit *event.Event) *event.Event {
+func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.MessageType, text string, rel *ifc.Relation) *event.Event {
content := format.RenderMarkdown(text)
content.MsgType = msgtype
- // Remove markdown link stuff from plaintext mentions and room links
- content.Body = mentionRegex.ReplaceAllString(content.Body, "$1")
- content.Body = roomRegex.ReplaceAllString(content.Body, "$1")
-
- if edit != nil {
+ if rel != nil && rel.Type == mautrix.RelReplace {
contentCopy := content
content.NewContent = &contentCopy
content.Body = "* " + content.Body
@@ -749,8 +742,10 @@ func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.Messag
}
content.RelatesTo = &mautrix.RelatesTo{
Type: mautrix.RelReplace,
- EventID: edit.ID,
+ EventID: rel.Event.ID,
}
+ } else if rel != nil && rel.Type == mautrix.RelReference {
+ content.SetReply(rel.Event.Event)
}
txnID := c.client.TxnID()
@@ -766,8 +761,8 @@ func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.Messag
},
})
localEcho.Gomuks.OutgoingState = event.StateLocalEcho
- if edit != nil {
- localEcho.ID = edit.ID
+ if rel != nil && rel.Type == mautrix.RelReplace {
+ localEcho.ID = rel.Event.ID
localEcho.Gomuks.Edits = []*event.Event{localEcho}
}
return localEcho