Add better stringification for UI message types for debugging
This commit is contained in:
		@@ -197,7 +197,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if start == -1 {
 | 
			
		||||
		debug.Print("Called replaceBuffer() with message that was not in the buffer:", original.ID())
 | 
			
		||||
		debug.Print("Called replaceBuffer() with message that was not in the buffer:", original)
 | 
			
		||||
		debug.PrintStack()
 | 
			
		||||
		view.appendBuffer(new)
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ package messages
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"maunium.net/go/gomuks/config"
 | 
			
		||||
@@ -286,3 +287,17 @@ func (msg *BaseMessage) DrawReply(screen mauview.Screen) mauview.Screen {
 | 
			
		||||
	msg.ReplyTo.Draw(replyScreen)
 | 
			
		||||
	return mauview.NewProxyScreen(screen, 0, replyHeight+2, width, height-replyHeight-2)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (msg *BaseMessage) String() string {
 | 
			
		||||
	return fmt.Sprintf(`&messages.BaseMessage{
 | 
			
		||||
    ID="%s", TxnID="%s",
 | 
			
		||||
    Type="%s", Timestamp=%s,
 | 
			
		||||
    Sender={ID="%s", Name="%s", Color=#%X},
 | 
			
		||||
    IsService=%t, IsHighlight=%t,
 | 
			
		||||
}`,
 | 
			
		||||
		msg.MsgID, msg.MsgTxnID,
 | 
			
		||||
		msg.MsgType, msg.MsgTimestamp.String(),
 | 
			
		||||
		msg.MsgSenderID, msg.MsgSender, msg.MsgSenderColor.Hex(),
 | 
			
		||||
		msg.MsgIsService, msg.MsgIsHighlight,
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -78,7 +78,7 @@ func (be *BaseEntity) PlainText() string {
 | 
			
		||||
 | 
			
		||||
// String returns a textual representation of this BaseEntity struct.
 | 
			
		||||
func (be *BaseEntity) String() string {
 | 
			
		||||
	return fmt.Sprintf(`&html.BaseEntity{Tag="%s", Style=%d, Block=%t, startX=%d, height=%d},`,
 | 
			
		||||
	return fmt.Sprintf(`&html.BaseEntity{Tag="%s", Style=%d, Block=%t, startX=%d, height=%d}`,
 | 
			
		||||
		be.Tag, be.Style, be.Block, be.startX, be.height)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -84,12 +84,13 @@ func (ce *ContainerEntity) String() string {
 | 
			
		||||
		return fmt.Sprintf(`&html.ContainerEntity{Base=%s, Indent=%d, Children=[]}`, ce.BaseEntity, ce.Indent)
 | 
			
		||||
	}
 | 
			
		||||
	var buf strings.Builder
 | 
			
		||||
	_, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s, Indent=%d, Children=[`, ce.BaseEntity, ce.Indent)
 | 
			
		||||
	_, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s,
 | 
			
		||||
                      Indent=%d, Children=[`, ce.BaseEntity, ce.Indent)
 | 
			
		||||
	for _, child := range ce.Children {
 | 
			
		||||
		buf.WriteString("\n    ")
 | 
			
		||||
		buf.WriteString(strings.Join(strings.Split(strings.TrimRight(child.String(), "\n"), "\n"), "\n    "))
 | 
			
		||||
	}
 | 
			
		||||
	buf.WriteString("\n]}\n,")
 | 
			
		||||
	buf.WriteString("\n]},")
 | 
			
		||||
	return buf.String()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,9 @@
 | 
			
		||||
package messages
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"maunium.net/go/mautrix"
 | 
			
		||||
	"maunium.net/go/mauview"
 | 
			
		||||
	"maunium.net/go/tcell"
 | 
			
		||||
@@ -98,3 +101,10 @@ func (hw *HTMLMessage) PlainText() string {
 | 
			
		||||
func (hw *HTMLMessage) NotificationContent() string {
 | 
			
		||||
	return hw.Root.PlainText()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (hw *HTMLMessage) String() string {
 | 
			
		||||
	return fmt.Sprintf("&messages.HTMLMessage{\n" +
 | 
			
		||||
		"    Base=%s,\n" +
 | 
			
		||||
		"    Root=||\n%s\n" +
 | 
			
		||||
		"}", strings.ReplaceAll(hw.BaseMessage.String(), "\n", "\n    "), hw.Root.String())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user