aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/base.go19
-rw-r--r--ui/messages/expandedtextmessage.go15
-rw-r--r--ui/messages/imagemessage.go12
-rw-r--r--ui/messages/meta.go14
-rw-r--r--ui/messages/parser/htmlparser.go14
-rw-r--r--ui/messages/parser/parser.go2
-rw-r--r--ui/messages/textmessage.go12
7 files changed, 16 insertions, 72 deletions
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 50f2735..5322b34 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -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...".
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index ec359c9..38e0afd 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -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()
}
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index 7478876..cd8c2fe 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -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.
diff --git a/ui/messages/meta.go b/ui/messages/meta.go
index 7e2f29f..3a1dd19 100644
--- a/ui/messages/meta.go
+++ b/ui/messages/meta.go
@@ -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()
-}
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index 4f3522a..5e3b289 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -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,
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index 58b0248..d12383a 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -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)
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 489e8a7..5139e07 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -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