From 8aa134b8b23cf945f5a18e21e5fa4855e188d3c0 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 26 Mar 2019 00:37:35 +0200 Subject: Start moving to mauview --- ui/messages/imagemessage.go | 2 +- ui/messages/parser/parser.go | 24 +++++++++++++++++------- ui/messages/tstring/cell.go | 3 ++- ui/messages/tstring/string.go | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) (limited to 'ui/messages') diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go index 0efe676..cad76a4 100644 --- a/ui/messages/imagemessage.go +++ b/ui/messages/imagemessage.go @@ -80,7 +80,7 @@ func (msg *ImageMessage) updateData() { debug.Print("Loading image:", msg.Homeserver, msg.FileID) data, _, _, err := msg.matrix.Download(fmt.Sprintf("mxc://%s/%s", msg.Homeserver, msg.FileID)) if err != nil { - debug.Print("Failed to download image %s/%s: %v", msg.Homeserver, msg.FileID, err) + debug.Printf("Failed to download image %s/%s: %v", msg.Homeserver, msg.FileID, err) return } debug.Print("Image", msg.Homeserver, msg.FileID, "loaded.") diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go index 94ab5b6..b36fde0 100644 --- a/ui/messages/parser/parser.go +++ b/ui/messages/parser/parser.go @@ -102,14 +102,24 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Eve } if len(evt.Content.GetReplyTo()) > 0 { evt.Content.RemoveReplyFallback() - replyToEvt, _ := matrix.Client().GetEvent(room.ID, evt.Content.GetReplyTo()) - replyToEvt.Content.RemoveReplyFallback() - if len(replyToEvt.Content.FormattedBody) == 0 { - replyToEvt.Content.FormattedBody = html.EscapeString(replyToEvt.Content.Body) + roomID := evt.Content.RelatesTo.InReplyTo.RoomID + if len(roomID) == 0 { + roomID = room.ID + } + replyToEvt, _ := matrix.Client().GetEvent(roomID, evt.Content.GetReplyTo()) + if replyToEvt != nil { + replyToEvt.Content.RemoveReplyFallback() + if len(replyToEvt.Content.FormattedBody) == 0 { + replyToEvt.Content.FormattedBody = html.EscapeString(replyToEvt.Content.Body) + } + evt.Content.FormattedBody = fmt.Sprintf( + "In reply to %[1]s
%[2]s

%[3]s", + replyToEvt.Sender, replyToEvt.Content.FormattedBody, evt.Content.FormattedBody) + } else { + evt.Content.FormattedBody = fmt.Sprintf( + "In reply to unknown event https://matrix.to/#/%[1]s/%[2]s
%[3]s", + roomID, evt.Content.GetReplyTo(), evt.Content.FormattedBody) } - evt.Content.FormattedBody = fmt.Sprintf( - "In reply to %[1]s
%[2]s

%[3]s", - replyToEvt.Sender, replyToEvt.Content.FormattedBody, evt.Content.FormattedBody) } ts := unixToTime(evt.Timestamp) switch evt.Content.MsgType { diff --git a/ui/messages/tstring/cell.go b/ui/messages/tstring/cell.go index aee1716..3ea7b5a 100644 --- a/ui/messages/tstring/cell.go +++ b/ui/messages/tstring/cell.go @@ -18,6 +18,7 @@ package tstring import ( "github.com/mattn/go-runewidth" + "maunium.net/go/mauview" "maunium.net/go/tcell" ) @@ -43,7 +44,7 @@ func (cell Cell) RuneWidth() int { return runewidth.RuneWidth(cell.Char) } -func (cell Cell) Draw(screen tcell.Screen, x, y int) (chWidth int) { +func (cell Cell) Draw(screen mauview.Screen, x, y int) (chWidth int) { chWidth = cell.RuneWidth() for runeWidthOffset := 0; runeWidthOffset < chWidth; runeWidthOffset++ { screen.SetContent(x+runeWidthOffset, y, cell.Char, nil, cell.Style) diff --git a/ui/messages/tstring/string.go b/ui/messages/tstring/string.go index 7feeda0..b14dc8e 100644 --- a/ui/messages/tstring/string.go +++ b/ui/messages/tstring/string.go @@ -21,6 +21,7 @@ import ( "unicode" "github.com/mattn/go-runewidth" + "maunium.net/go/mauview" "maunium.net/go/tcell" ) @@ -181,7 +182,7 @@ func (str TString) AdjustStyleFull(fn func(tcell.Style) tcell.Style) { str.AdjustStyle(0, len(str), fn) } -func (str TString) Draw(screen tcell.Screen, x, y int) { +func (str TString) Draw(screen mauview.Screen, x, y int) { offsetX := 0 for _, cell := range str { offsetX += cell.Draw(screen, x+offsetX, y) -- cgit v1.2.3