From bbde1219479bb257c7bc1f9546bd67e8a151198c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 10 Apr 2019 01:04:39 +0300 Subject: It compiles. Ship it! --- ui/messages/base.go | 15 +++++++-------- ui/messages/message.go | 2 ++ ui/messages/parser.go | 1 - ui/messages/textmessage.go | 18 +++++++++++++----- 4 files changed, 22 insertions(+), 14 deletions(-) (limited to 'ui/messages') diff --git a/ui/messages/base.go b/ui/messages/base.go index b8b1694..d9db866 100644 --- a/ui/messages/base.go +++ b/ui/messages/base.go @@ -192,6 +192,9 @@ func (msg *BaseMessage) FormatDate() string { } func (msg *BaseMessage) ID() string { + if len(msg.MsgID) == 0 { + return msg.MsgTxnID + } return msg.MsgID } @@ -199,6 +202,10 @@ func (msg *BaseMessage) SetID(id string) { msg.MsgID = id } +func (msg *BaseMessage) TxnID() string { + return msg.MsgTxnID +} + func (msg *BaseMessage) Type() mautrix.MessageType { return msg.MsgType } @@ -219,14 +226,6 @@ func (msg *BaseMessage) SetIsHighlight(isHighlight bool) { msg.MsgIsHighlight = isHighlight } -func (msg *BaseMessage) IsService() bool { - return msg.MsgIsService -} - -func (msg *BaseMessage) SetIsService(isService bool) { - msg.MsgIsService = isService -} - func (msg *BaseMessage) Source() json.RawMessage { return msg.MsgSource } diff --git a/ui/messages/message.go b/ui/messages/message.go index 634bd11..bd78e5d 100644 --- a/ui/messages/message.go +++ b/ui/messages/message.go @@ -19,6 +19,7 @@ package messages import ( "maunium.net/go/gomuks/config" "maunium.net/go/gomuks/interface" + "maunium.net/go/mautrix" "maunium.net/go/mauview" "maunium.net/go/tcell" ) @@ -27,6 +28,7 @@ import ( type UIMessage interface { ifc.Message + Type() mautrix.MessageType Sender() string SenderColor() tcell.Color TextColor() tcell.Color diff --git a/ui/messages/parser.go b/ui/messages/parser.go index f45eea2..7b76a69 100644 --- a/ui/messages/parser.go +++ b/ui/messages/parser.go @@ -29,7 +29,6 @@ import ( "maunium.net/go/gomuks/ui/messages/html" "maunium.net/go/gomuks/ui/messages/tstring" "maunium.net/go/gomuks/ui/widget" - htmlp "maunium.net/go/gomuks/ui/messages/html" ) func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Event) UIMessage { diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go index f7c54ca..588dee4 100644 --- a/ui/messages/textmessage.go +++ b/ui/messages/textmessage.go @@ -18,6 +18,7 @@ package messages import ( "fmt" + "time" "maunium.net/go/mautrix" @@ -39,6 +40,18 @@ func NewTextMessage(event *mautrix.Event, displayname string, text string) UIMes } } +func NewServiceMessage(text string) UIMessage { + return &TextMessage{ + BaseMessage: BaseMessage{ + MsgSenderID: "*", + MsgSender: "*", + MsgTimestamp: time.Now(), + MsgIsService: true, + }, + MsgText: text, + } +} + func (msg *TextMessage) getCache() tstring.TString { if msg.cache == nil { switch msg.MsgType { @@ -57,11 +70,6 @@ func (msg *TextMessage) SetIsHighlight(isHighlight bool) { msg.cache = nil } -func (msg *TextMessage) SetIsService(isService bool) { - msg.BaseMessage.SetIsService(isService) - msg.cache = nil -} - func (msg *TextMessage) NotificationContent() string { return msg.MsgText } -- cgit v1.2.3