aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/types/message.go55
-rw-r--r--ui/view-main.go5
-rw-r--r--ui/widget/message-view.go1
-rw-r--r--ui/widget/room-view.go5
4 files changed, 34 insertions, 32 deletions
diff --git a/ui/types/message.go b/ui/types/message.go
index e212a80..fa3b6ef 100644
--- a/ui/types/message.go
+++ b/ui/types/message.go
@@ -41,6 +41,7 @@ type Message struct {
Type string
Sender string
SenderColor tcell.Color
+ TextColor tcell.Color
Timestamp string
Date string
Text string
@@ -56,6 +57,7 @@ func NewMessage(id, sender, msgtype, text, timestamp, date string, senderColor t
Timestamp: timestamp,
Date: date,
SenderColor: senderColor,
+ TextColor: tcell.ColorDefault,
Type: msgtype,
Text: text,
ID: id,
@@ -70,9 +72,11 @@ func (message *Message) CopyTo(to *Message) {
to.Type = message.Type
to.Sender = message.Sender
to.SenderColor = message.SenderColor
+ to.TextColor = message.TextColor
to.Timestamp = message.Timestamp
to.Date = message.Date
to.Text = message.Text
+ to.State = message.State
to.RecalculateBuffer()
}
@@ -98,14 +102,7 @@ func (message *Message) GetSender() string {
}
}
-// GetSenderColor returns the color the name of the sender should be shown in.
-//
-// If the message is being sent, the color is gray.
-// If sending has failed, the color is red.
-//
-// In any other case, the color is whatever is specified in the Message struct.
-// Usually that means it is the hash-based color of the sender (see ui/widget/color.go)
-func (message *Message) GetSenderColor() tcell.Color {
+func (message *Message) getStateSpecificColor() tcell.Color {
switch message.State {
case MessageStateSending:
return tcell.ColorGray
@@ -114,32 +111,44 @@ func (message *Message) GetSenderColor() tcell.Color {
case MessageStateDefault:
fallthrough
default:
- return message.SenderColor
+ return tcell.ColorDefault
}
}
-// GetTextColor returns the color the actual content of the message should be shown in.
+// GetSenderColor returns the color the name of the sender should be shown in.
//
-// As with GetSenderColor(), messages being sent and messages that failed to be sent are
-// gray and red respectively.
+// If the message is being sent, the color is gray.
+// If sending has failed, the color is red.
//
-// However, other messages are the default color instead of a color stored in the struct.
-func (message *Message) GetTextColor() tcell.Color {
- switch message.State {
- case MessageStateSending:
- return tcell.ColorGray
- case MessageStateFailed:
- return tcell.ColorRed
- default:
- return tcell.ColorDefault
+// In any other case, the color is whatever is specified in the Message struct.
+// Usually that means it is the hash-based color of the sender (see ui/widget/color.go)
+func (message *Message) GetSenderColor() (color tcell.Color) {
+ color = message.getStateSpecificColor()
+ if color == tcell.ColorDefault {
+ color = message.SenderColor
+ }
+ return
+}
+
+// GetTextColor returns the color the actual content of the message should be shown in.
+//
+// This returns the same colors as GetSenderColor(), but takes the default color from a different variable.
+func (message *Message) GetTextColor() (color tcell.Color) {
+ color = message.getStateSpecificColor()
+ if color == tcell.ColorDefault {
+ color = message.TextColor
}
+ return
}
// GetTimestampColor returns the color the timestamp should be shown in.
//
-// Currently, this simply calls GetTextColor().
+// As with GetSenderColor(), messages being sent and messages that failed to be sent are
+// gray and red respectively.
+//
+// However, other messages are the default color instead of a color stored in the struct.
func (message *Message) GetTimestampColor() tcell.Color {
- return message.GetTextColor()
+ return message.getStateSpecificColor()
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
diff --git a/ui/view-main.go b/ui/view-main.go
index 1bf98a3..83da396 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -138,10 +138,7 @@ func (view *MainView) sendTempMessage(roomView *widget.RoomView, tempMessage *ty
defer view.gmx.Recover()
eventID, err := view.matrix.SendMessage(roomView.Room.ID, tempMessage.Type, tempMessage.Text)
if err != nil {
- tempMessage.TextColor = tcell.ColorRed
- tempMessage.TimestampColor = tcell.ColorRed
- tempMessage.SenderColor = tcell.ColorRed
- tempMessage.Sender = "Error"
+ tempMessage.State = types.MessageStateFailed
roomView.SetStatus(fmt.Sprintf("Failed to send message: %s", err))
} else {
roomView.MessageView().UpdateMessageID(tempMessage, eventID)
diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go
index 444aa03..dc0cde5 100644
--- a/ui/widget/message-view.go
+++ b/ui/widget/message-view.go
@@ -152,7 +152,6 @@ func (view *MessageView) AddMessage(message *types.Message, direction MessageDir
if msg != nil && messageExists {
message.CopyTo(msg)
message = msg
- message.SetIsSending(false)
direction = IgnoreMessage
}
diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go
index 83073c2..69216fb 100644
--- a/ui/widget/room-view.go
+++ b/ui/widget/room-view.go
@@ -253,10 +253,7 @@ func (view *RoomView) NewTempMessage(msgtype, text string) *types.Message {
id := strconv.FormatInt(now.UnixNano(), 10)
sender := view.Room.GetSessionOwner().DisplayName
message := view.NewMessage(id, sender, msgtype, text, now)
- message.SetIsSending(true)
- message.TimestampColor = tcell.ColorGray
- message.TextColor = tcell.ColorGray
- message.SenderColor = tcell.ColorGray
+ message.State = types.MessageStateSending
view.AddMessage(message, AppendMessage)
return message
}