From 9d132d328bbf3cdcb66d34538583a96268b6dd09 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 1 Mar 2020 00:33:37 +0200 Subject: Add support for replying and reacting to messages --- matrix/matrix.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'matrix/matrix.go') 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 -- cgit v1.2.3