aboutsummaryrefslogtreecommitdiff
path: root/vendor/maunium.net/go/gomatrix/reply.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-11-14 00:00:35 +0200
committerTulir Asokan <tulir@maunium.net>2018-11-14 00:00:35 +0200
commitba387764ca1590625d349e74eb8a8a64d1849b67 (patch)
treebc8f02156a63eac99dcddaed38e45b7c312b40c0 /vendor/maunium.net/go/gomatrix/reply.go
parentcfb2cc057c32330be0ca0a68cfbd245cb2b8e31b (diff)
Fix things
Diffstat (limited to 'vendor/maunium.net/go/gomatrix/reply.go')
-rw-r--r--vendor/maunium.net/go/gomatrix/reply.go96
1 files changed, 0 insertions, 96 deletions
diff --git a/vendor/maunium.net/go/gomatrix/reply.go b/vendor/maunium.net/go/gomatrix/reply.go
deleted file mode 100644
index 6985421..0000000
--- a/vendor/maunium.net/go/gomatrix/reply.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package gomatrix
-
-import (
- "fmt"
- "regexp"
- "strings"
-
- "golang.org/x/net/html"
-)
-
-var HTMLReplyFallbackRegex = regexp.MustCompile(`^<mx-reply>[\s\S]+?</mx-reply>`)
-
-func TrimReplyFallbackHTML(html string) string {
- return HTMLReplyFallbackRegex.ReplaceAllString(html, "")
-}
-
-func TrimReplyFallbackText(text string) string {
- if !strings.HasPrefix(text, "> ") || !strings.Contains(text, "\n") {
- return text
- }
-
- lines := strings.Split(text, "\n")
- for len(lines) > 0 && strings.HasPrefix(lines[0], "> ") {
- lines = lines[1:]
- }
- return strings.TrimSpace(strings.Join(lines, "\n"))
-}
-
-func (content *Content) RemoveReplyFallback() {
- if len(content.GetReplyTo()) > 0 {
- if content.Format == FormatHTML {
- content.FormattedBody = TrimReplyFallbackHTML(content.FormattedBody)
- }
- content.Body = TrimReplyFallbackText(content.Body)
- }
-}
-
-func (content *Content) GetReplyTo() string {
- if content.RelatesTo != nil {
- return content.RelatesTo.InReplyTo.EventID
- }
- return ""
-}
-
-const ReplyFormat = `<mx-reply><blockquote>
-<a href="https://matrix.to/#/%s/%s">In reply to</a>
-<a href="https://matrix.to/#/%s">%s</a>
-%s
-</blockquote></mx-reply>
-`
-
-func (evt *Event) GenerateReplyFallbackHTML() string {
- body := evt.Content.FormattedBody
- if len(body) == 0 {
- body = html.EscapeString(evt.Content.Body)
- }
-
- senderDisplayName := evt.Sender
-
- return fmt.Sprintf(ReplyFormat, evt.RoomID, evt.ID, evt.Sender, senderDisplayName, body)
-}
-
-func (evt *Event) GenerateReplyFallbackText() string {
- body := evt.Content.Body
- lines := strings.Split(strings.TrimSpace(body), "\n")
- firstLine, lines := lines[0], lines[1:]
-
- senderDisplayName := evt.Sender
-
- var fallbackText strings.Builder
- fmt.Fprintf(&fallbackText, "> <%s> %s", senderDisplayName, firstLine)
- for _, line := range lines {
- fmt.Fprintf(&fallbackText, "\n> %s", line)
- }
- fallbackText.WriteString("\n\n")
- return fallbackText.String()
-}
-
-func (content *Content) SetReply(inReplyTo *Event) {
- if content.RelatesTo == nil {
- content.RelatesTo = &RelatesTo{}
- }
- content.RelatesTo.InReplyTo = InReplyTo{
- EventID: inReplyTo.ID,
- RoomID: inReplyTo.RoomID,
- }
-
- if content.MsgType == MsgText || content.MsgType == MsgNotice {
- if len(content.FormattedBody) == 0 || content.Format != FormatHTML {
- content.FormattedBody = html.EscapeString(content.Body)
- content.Format = FormatHTML
- }
- content.FormattedBody = inReplyTo.GenerateReplyFallbackHTML() + content.FormattedBody
- content.Body = inReplyTo.GenerateReplyFallbackText() + content.Body
- }
-}