aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/messages/base.go39
-rw-r--r--ui/messages/expandedtextmessage.go1
-rw-r--r--ui/messages/htmlmessage.go8
-rw-r--r--ui/messages/imagemessage.go1
-rw-r--r--ui/messages/message.go1
-rw-r--r--ui/messages/parser.go15
-rw-r--r--ui/messages/textmessage.go1
7 files changed, 57 insertions, 9 deletions
diff --git a/ui/messages/base.go b/ui/messages/base.go
index f54c2cd..32e1865 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -20,6 +20,7 @@ import (
"encoding/json"
"time"
+ "maunium.net/go/gomuks/config"
"maunium.net/go/mautrix"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -41,6 +42,7 @@ type BaseMessage struct {
MsgIsHighlight bool
MsgIsService bool
MsgSource json.RawMessage
+ ReplyTo UIMessage
buffer []tstring.TString
plainBuffer []tstring.TString
}
@@ -171,9 +173,16 @@ func (msg *BaseMessage) TimestampColor() tcell.Color {
return msg.getStateSpecificColor()
}
+func (msg *BaseMessage) ReplyHeight() int {
+ if msg.ReplyTo != nil {
+ return 2 + msg.ReplyTo.Height()
+ }
+ return 0
+}
+
// Height returns the number of rows in the computed buffer (see Buffer()).
func (msg *BaseMessage) Height() int {
- return len(msg.buffer)
+ return msg.ReplyHeight() + len(msg.buffer)
}
// Timestamp returns the full timestamp when the message was sent.
@@ -236,8 +245,36 @@ func (msg *BaseMessage) Source() json.RawMessage {
return msg.MsgSource
}
+func (msg *BaseMessage) SetReplyTo(event UIMessage) {
+ msg.ReplyTo = event
+}
+
func (msg *BaseMessage) Draw(screen mauview.Screen) {
+ screen = msg.DrawReply(screen)
for y, line := range msg.buffer {
line.Draw(screen, 0, y)
}
}
+
+func (msg *BaseMessage) CalculateReplyBuffer(preferences config.UserPreferences, width int) {
+ if msg.ReplyTo == nil {
+ return
+ }
+ msg.ReplyTo.CalculateBuffer(preferences, width-1)
+}
+
+func (msg *BaseMessage) DrawReply(screen mauview.Screen) mauview.Screen {
+ if msg.ReplyTo == nil {
+ return screen
+ }
+ width, height := screen.Size()
+ replyHeight := msg.ReplyTo.Height()
+ widget.WriteLineSimpleColor(screen, "In reply to", 0, 0, tcell.ColorGreen)
+ widget.WriteLineSimpleColor(screen, msg.ReplyTo.RealSender(), len("In reply to "), 0, msg.ReplyTo.SenderColor())
+ for y := 1; y < 1+replyHeight; y++ {
+ screen.SetCell(0, y, tcell.StyleDefault, '▋')
+ }
+ replyScreen := mauview.NewProxyScreen(screen, 1, 1, width-1, replyHeight)
+ msg.ReplyTo.Draw(replyScreen)
+ return mauview.NewProxyScreen(screen, 0, replyHeight+2, width, height-replyHeight-2)
+}
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index b2005b9..5e07901 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -70,5 +70,6 @@ func (msg *ExpandedTextMessage) PlainText() string {
}
func (msg *ExpandedTextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
+ msg.CalculateReplyBuffer(prefs, width)
msg.calculateBufferWithText(prefs, msg.MsgText, width)
}
diff --git a/ui/messages/htmlmessage.go b/ui/messages/htmlmessage.go
index ceee305..577a33d 100644
--- a/ui/messages/htmlmessage.go
+++ b/ui/messages/htmlmessage.go
@@ -41,6 +41,7 @@ func NewHTMLMessage(event *mautrix.Event, displayname string, root html.Entity)
}
func (hw *HTMLMessage) Draw(screen mauview.Screen) {
+ screen = hw.DrawReply(screen)
if hw.focused {
screen.SetStyle(tcell.StyleDefault.Background(hw.FocusedBg))
}
@@ -69,16 +70,17 @@ func (hw *HTMLMessage) OnPasteEvent(event mauview.PasteEvent) bool {
}
func (hw *HTMLMessage) CalculateBuffer(preferences config.UserPreferences, width int) {
- if width <= 0 {
- panic("Negative width in CalculateBuffer")
+ if width < 2 {
+ return
}
+ hw.CalculateReplyBuffer(preferences, width)
// TODO account for bare messages in initial startX
startX := 0
hw.Root.CalculateBuffer(width, startX, preferences.BareMessageView)
}
func (hw *HTMLMessage) Height() int {
- return hw.Root.Height()
+ return hw.ReplyHeight() + hw.Root.Height()
}
func (hw *HTMLMessage) PlainText() string {
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index 9ce1a8e..9bebc11 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -92,6 +92,7 @@ func (msg *ImageMessage) CalculateBuffer(prefs config.UserPreferences, width int
if width < 2 {
return
}
+ msg.CalculateReplyBuffer(prefs, width)
if prefs.BareMessageView || prefs.DisableImages {
msg.calculateBufferWithText(prefs, tstring.NewTString(msg.PlainText()), width)
diff --git a/ui/messages/message.go b/ui/messages/message.go
index c1f2014..44aaec1 100644
--- a/ui/messages/message.go
+++ b/ui/messages/message.go
@@ -37,6 +37,7 @@ type UIMessage interface {
FormatDate() string
SameDate(message UIMessage) bool
+ SetReplyTo(message UIMessage)
CalculateBuffer(preferences config.UserPreferences, width int)
Draw(screen mauview.Screen)
Height() int
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index 7b76a69..097c9d0 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -37,13 +37,18 @@ func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Event
return nil
}
if len(evt.Content.GetReplyTo()) > 0 {
- roomID := evt.Content.RelatesTo.InReplyTo.RoomID
- if len(roomID) == 0 {
- roomID = room.ID
+ replyToRoom := room
+ if len(evt.Content.RelatesTo.InReplyTo.RoomID) > 0 {
+ replyToRoom = matrix.GetRoom(evt.Content.RelatesTo.InReplyTo.RoomID)
}
- replyToEvt, _ := matrix.GetEvent(room, evt.Content.GetReplyTo())
+ replyToEvt, _ := matrix.GetEvent(replyToRoom, evt.Content.GetReplyTo())
if replyToEvt != nil {
- // TODO add reply header
+ replyToMsg := directParseEvent(matrix, replyToRoom, replyToEvt)
+ if replyToMsg != nil {
+ msg.SetReplyTo(replyToMsg)
+ } else {
+ // TODO add unrenderable reply header
+ }
} else {
// TODO add unknown reply header
}
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 588dee4..355a90e 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -79,5 +79,6 @@ func (msg *TextMessage) PlainText() string {
}
func (msg *TextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
+ msg.CalculateReplyBuffer(prefs, width)
msg.calculateBufferWithText(prefs, msg.getCache(), width)
}