aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-17 13:46:02 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-17 13:46:02 +0300
commitb76c301145c543ebcdc5534d4f292b056aa51219 (patch)
tree569b66f60ee40f85c8ebc090c9162348a3b15567 /ui
parentfe439f076ad3d76c459c9a76c4bbdcda5182ed85 (diff)
Add initial support for rendering replies
Diffstat (limited to 'ui')
-rw-r--r--ui/message-view.go6
-rw-r--r--ui/messages/base.go3
-rw-r--r--ui/messages/parser.go4
-rw-r--r--ui/messages/textmessage.go10
-rw-r--r--ui/room-view.go32
-rw-r--r--ui/view-main.go4
6 files changed, 38 insertions, 21 deletions
diff --git a/ui/message-view.go b/ui/message-view.go
index 9aa38a1..1773be0 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -143,8 +143,6 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction MessageDir
view.replaceMessage(oldMsg, message)
view.deleteMessageID(message.TxnID)
direction = IgnoreMessage
- } else if oldMsg = view.getMessageByID(message.Relation.GetReplaceID()); oldMsg != nil {
- direction = IgnoreMessage
}
view.updateWidestSender(message.Sender())
@@ -608,6 +606,10 @@ func (view *MessageView) Draw(screen mauview.Screen) {
usernameX, line, view.widestSender(),
msg.SenderColor())
//}
+ if msg.Edited {
+ // TODO add better indicator for edits
+ screen.SetCell(usernameX + view.widestSender(), line, tcell.StyleDefault.Foreground(tcell.ColorDarkRed), '*')
+ }
prevMsg = msg
}
diff --git a/ui/messages/base.go b/ui/messages/base.go
index d072943..567e614 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -54,6 +54,7 @@ type UIMessage struct {
State event.OutgoingState
IsHighlight bool
IsService bool
+ Edited bool
Source json.RawMessage
ReplyTo *UIMessage
Renderer MessageRenderer
@@ -80,6 +81,7 @@ func newUIMessage(evt *event.Event, displayname string, renderer MessageRenderer
State: evt.Gomuks.OutgoingState,
IsHighlight: false,
IsService: false,
+ Edited: len(evt.Gomuks.Edits) > 0,
Source: evt.Content.VeryRaw,
Renderer: renderer,
}
@@ -231,7 +233,6 @@ func (msg *UIMessage) SetID(id string) {
}
func (msg *UIMessage) SetIsHighlight(isHighlight bool) {
- // TODO Textmessage cache needs to be cleared
msg.IsHighlight = isHighlight
}
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index 695dac6..e1c0053 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -127,8 +127,8 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *event.Event
if len(evt.Content.GetReplyTo()) > 0 {
evt.Content.RemoveReplyFallback()
}
- if evt.Content.GetRelatesTo().Type == mautrix.RelReplace && evt.Content.NewContent != nil {
- evt.Content = *evt.Content.NewContent
+ if len(evt.Gomuks.Edits) > 0 {
+ evt.Content = *evt.Gomuks.Edits[len(evt.Gomuks.Edits)-1].Content.NewContent
}
switch evt.Content.MsgType {
case "m.text", "m.notice", "m.emote":
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 5527677..2e27e33 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -29,9 +29,10 @@ import (
)
type TextMessage struct {
- cache tstring.TString
- buffer []tstring.TString
- Text string
+ cache tstring.TString
+ buffer []tstring.TString
+ isHighlight bool
+ Text string
}
// NewTextMessage creates a new UITextMessage object with the provided values and the default state.
@@ -85,6 +86,9 @@ func (msg *TextMessage) String() string {
}
func (msg *TextMessage) CalculateBuffer(prefs config.UserPreferences, width int, uiMsg *UIMessage) {
+ if uiMsg.IsHighlight != msg.isHighlight {
+ msg.cache = nil
+ }
msg.buffer = calculateBufferWithText(prefs, msg.getCache(uiMsg), width, uiMsg)
}
diff --git a/ui/room-view.go b/ui/room-view.go
index 344b873..31da3c6 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -412,7 +412,7 @@ func (view *RoomView) SendMessage(msgtype mautrix.MessageType, text string) {
}
evt := view.parent.matrix.PrepareMarkdownMessage(view.Room.ID, msgtype, text)
msg := view.parseEvent(evt)
- view.AddMessage(msg)
+ view.content.AddMessage(msg, AppendMessage)
eventID, err := view.parent.matrix.SendEvent(evt)
if err != nil {
msg.State = event.StateSendFail
@@ -462,20 +462,32 @@ func (view *RoomView) AddServiceMessage(text string) {
view.content.AddMessage(messages.NewServiceMessage(text), AppendMessage)
}
-func (view *RoomView) AddMessage(message ifc.Message) {
- view.content.AddMessage(message, AppendMessage)
-}
-
func (view *RoomView) parseEvent(evt *event.Event) *messages.UIMessage {
return messages.ParseEvent(view.parent.matrix, view.parent, view.Room, evt)
}
-func (view *RoomView) ParseEvent(evt *event.Event) ifc.Message {
- msg := view.parseEvent(evt)
- if msg == nil {
- return nil
+func (view *RoomView) AddHistoryEvent(evt *event.Event) {
+ if msg := view.parseEvent(evt); msg != nil {
+ view.content.AddMessage(msg, PrependMessage)
+ }
+}
+
+func (view *RoomView) AddEvent(evt *event.Event) ifc.Message {
+ if msg := view.parseEvent(evt); msg != nil {
+ view.content.AddMessage(msg, AppendMessage)
+ return msg
+ }
+ return nil
+}
+
+func (view *RoomView) AddRedaction(redactedEvt *event.Event) {
+ view.AddEvent(redactedEvt)
+}
+
+func (view *RoomView) AddEdit(evt *event.Event) {
+ if msg := view.parseEvent(evt); msg != nil {
+ view.content.AddMessage(msg, IgnoreMessage)
}
- return msg
}
func (view *RoomView) GetEvent(eventID string) ifc.Message {
diff --git a/ui/view-main.go b/ui/view-main.go
index 5357d24..67dbb4b 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -453,9 +453,7 @@ func (view *MainView) LoadHistory(roomID string) {
return
}
for _, evt := range history {
- if message := roomView.ParseEvent(evt); message != nil {
- msgView.AddMessage(message, PrependMessage)
- }
+ roomView.AddHistoryEvent(evt)
}
view.parent.Render()
}