aboutsummaryrefslogtreecommitdiff
path: root/matrix
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-03-01 00:33:37 +0200
committerTulir Asokan <tulir@maunium.net>2020-03-01 00:33:37 +0200
commit9d132d328bbf3cdcb66d34538583a96268b6dd09 (patch)
treee13d1da87abaa3fc6c9a5e1b5056897c9b659b46 /matrix
parent699d0ea4e0f5a2d48a5e41c647cbbfa793983b48 (diff)
Add support for replying and reacting to messages
Diffstat (limited to 'matrix')
-rw-r--r--matrix/matrix.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 85c4a46..940a519 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -732,7 +732,7 @@ func (c *Container) MarkRead(roomID, eventID string) {
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
@@ -740,7 +740,7 @@ func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.Messag
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 +749,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 +768,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