Add support for sending Markdown messages
This commit is contained in:
@ -61,25 +61,6 @@ func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time
|
||||
|
||||
func (msg *BaseMessage) RegisterGomuks(gmx ifc.Gomuks) {}
|
||||
|
||||
// CopyFrom replaces the content of this message object with the content of the given object.
|
||||
func (msg *BaseMessage) CopyFrom(from ifc.MessageMeta) {
|
||||
msg.MsgSender = from.Sender()
|
||||
msg.MsgSenderColor = from.SenderColor()
|
||||
|
||||
fromMsg, ok := from.(UIMessage)
|
||||
if ok {
|
||||
msg.MsgSenderID = fromMsg.SenderID()
|
||||
msg.MsgSender = fromMsg.RealSender()
|
||||
msg.MsgID = fromMsg.ID()
|
||||
msg.MsgType = fromMsg.Type()
|
||||
msg.MsgTimestamp = fromMsg.Timestamp()
|
||||
msg.MsgState = fromMsg.State()
|
||||
msg.MsgIsService = fromMsg.IsService()
|
||||
msg.MsgIsHighlight = fromMsg.IsHighlight()
|
||||
msg.buffer = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Sender gets the string that should be displayed as the sender of this message.
|
||||
//
|
||||
// If the message is being sent, the sender is "Sending...".
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"encoding/gob"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/gomuks/interface"
|
||||
"maunium.net/go/gomuks/ui/messages/tstring"
|
||||
)
|
||||
|
||||
@ -37,7 +36,7 @@ type ExpandedTextMessage struct {
|
||||
func NewExpandedTextMessage(id, sender, displayname, msgtype string, text tstring.TString, timestamp time.Time) UIMessage {
|
||||
return &ExpandedTextMessage{
|
||||
BaseTextMessage: newBaseTextMessage(id, sender, displayname, msgtype, timestamp),
|
||||
MsgText: text,
|
||||
MsgText: text,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,18 +44,6 @@ func (msg *ExpandedTextMessage) GenerateText() tstring.TString {
|
||||
return msg.MsgText
|
||||
}
|
||||
|
||||
// CopyFrom replaces the content of this message object with the content of the given object.
|
||||
func (msg *ExpandedTextMessage) CopyFrom(from ifc.MessageMeta) {
|
||||
msg.BaseTextMessage.CopyFrom(from)
|
||||
|
||||
fromExpandedMsg, ok := from.(*ExpandedTextMessage)
|
||||
if ok {
|
||||
msg.MsgText = fromExpandedMsg.MsgText
|
||||
}
|
||||
|
||||
msg.RecalculateBuffer()
|
||||
}
|
||||
|
||||
func (msg *ExpandedTextMessage) NotificationContent() string {
|
||||
return msg.MsgText.String()
|
||||
}
|
||||
|
@ -85,18 +85,6 @@ func (msg *ImageMessage) Path() string {
|
||||
return msg.gmx.Matrix().GetCachePath(msg.Homeserver, msg.FileID)
|
||||
}
|
||||
|
||||
// CopyFrom replaces the content of this message object with the content of the given object.
|
||||
func (msg *ImageMessage) CopyFrom(from ifc.MessageMeta) {
|
||||
msg.BaseMessage.CopyFrom(from)
|
||||
|
||||
fromImgMsg, ok := from.(*ImageMessage)
|
||||
if ok {
|
||||
msg.data = fromImgMsg.data
|
||||
}
|
||||
|
||||
msg.RecalculateBuffer()
|
||||
}
|
||||
|
||||
// CalculateBuffer generates the internal buffer for this message that consists
|
||||
// of the text of this message split into lines at most as wide as the width
|
||||
// parameter.
|
||||
|
@ -20,13 +20,12 @@ import (
|
||||
"time"
|
||||
|
||||
"maunium.net/go/tcell"
|
||||
"maunium.net/go/gomuks/interface"
|
||||
)
|
||||
|
||||
// BasicMeta is a simple variable store implementation of MessageMeta.
|
||||
type BasicMeta struct {
|
||||
BSender string
|
||||
BTimestamp time.Time
|
||||
BSender string
|
||||
BTimestamp time.Time
|
||||
BSenderColor, BTextColor, BTimestampColor tcell.Color
|
||||
}
|
||||
|
||||
@ -66,12 +65,3 @@ func (meta *BasicMeta) TextColor() tcell.Color {
|
||||
func (meta *BasicMeta) TimestampColor() tcell.Color {
|
||||
return meta.BTimestampColor
|
||||
}
|
||||
|
||||
// CopyFrom replaces the content of this meta object with the content of the given object.
|
||||
func (meta *BasicMeta) CopyFrom(from ifc.MessageMeta) {
|
||||
meta.BSender = from.Sender()
|
||||
meta.BTimestamp = from.Timestamp()
|
||||
meta.BSenderColor = from.SenderColor()
|
||||
meta.BTextColor = from.TextColor()
|
||||
meta.BTimestampColor = from.TimestampColor()
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([
|
||||
type MatrixHTMLProcessor struct {
|
||||
text tstring.TString
|
||||
|
||||
sender string
|
||||
msgtype string
|
||||
|
||||
indent string
|
||||
listType string
|
||||
lineIsNew bool
|
||||
@ -52,7 +55,11 @@ func (parser *MatrixHTMLProcessor) newline() {
|
||||
}
|
||||
}
|
||||
|
||||
func (parser *MatrixHTMLProcessor) Preprocess() {}
|
||||
func (parser *MatrixHTMLProcessor) Preprocess() {
|
||||
if parser.msgtype == "m.emote" {
|
||||
parser.text = tstring.NewColorTString(fmt.Sprintf("* %s ", parser.sender), widget.GetHashColor(parser.sender))
|
||||
}
|
||||
}
|
||||
|
||||
func (parser *MatrixHTMLProcessor) HandleText(text string) {
|
||||
style := tcell.StyleDefault
|
||||
@ -170,12 +177,15 @@ func (parser *MatrixHTMLProcessor) Postprocess() {
|
||||
}
|
||||
|
||||
// ParseHTMLMessage parses a HTML-formatted Matrix event into a UIMessage.
|
||||
func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event) tstring.TString {
|
||||
func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event, senderDisplayname string) tstring.TString {
|
||||
htmlData, _ := evt.Content["formatted_body"].(string)
|
||||
msgtype, _ := evt.Content["msgtype"].(string)
|
||||
|
||||
processor := &MatrixHTMLProcessor{
|
||||
room: room,
|
||||
text: tstring.NewBlankTString(),
|
||||
msgtype: msgtype,
|
||||
sender: senderDisplayname,
|
||||
indent: "",
|
||||
listType: "",
|
||||
lineIsNew: true,
|
||||
|
@ -60,7 +60,7 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) message
|
||||
case "m.text", "m.notice", "m.emote":
|
||||
format, hasFormat := evt.Content["format"].(string)
|
||||
if hasFormat && format == "org.matrix.custom.html" {
|
||||
text := ParseHTMLMessage(room, evt)
|
||||
text := ParseHTMLMessage(room, evt, displayname)
|
||||
return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, msgtype, text, ts)
|
||||
} else {
|
||||
text, _ := evt.Content["body"].(string)
|
||||
|
@ -56,18 +56,6 @@ func (msg *TextMessage) getCache() tstring.TString {
|
||||
return msg.cache
|
||||
}
|
||||
|
||||
// CopyFrom replaces the content of this message object with the content of the given object.
|
||||
func (msg *TextMessage) CopyFrom(from ifc.MessageMeta) {
|
||||
msg.BaseTextMessage.CopyFrom(from)
|
||||
|
||||
fromTextMsg, ok := from.(*TextMessage)
|
||||
if ok {
|
||||
msg.MsgText = fromTextMsg.MsgText
|
||||
}
|
||||
|
||||
msg.cache = nil
|
||||
msg.RecalculateBuffer()
|
||||
}
|
||||
func (msg *TextMessage) SetType(msgtype string) {
|
||||
msg.BaseTextMessage.SetType(msgtype)
|
||||
msg.cache = nil
|
||||
|
Reference in New Issue
Block a user