Fix bugs and compile errors
This commit is contained in:
parent
373b25c01c
commit
a5e7800ab6
@ -41,6 +41,7 @@ type Message struct {
|
|||||||
Type string
|
Type string
|
||||||
Sender string
|
Sender string
|
||||||
SenderColor tcell.Color
|
SenderColor tcell.Color
|
||||||
|
TextColor tcell.Color
|
||||||
Timestamp string
|
Timestamp string
|
||||||
Date string
|
Date string
|
||||||
Text string
|
Text string
|
||||||
@ -56,6 +57,7 @@ func NewMessage(id, sender, msgtype, text, timestamp, date string, senderColor t
|
|||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Date: date,
|
Date: date,
|
||||||
SenderColor: senderColor,
|
SenderColor: senderColor,
|
||||||
|
TextColor: tcell.ColorDefault,
|
||||||
Type: msgtype,
|
Type: msgtype,
|
||||||
Text: text,
|
Text: text,
|
||||||
ID: id,
|
ID: id,
|
||||||
@ -70,9 +72,11 @@ func (message *Message) CopyTo(to *Message) {
|
|||||||
to.Type = message.Type
|
to.Type = message.Type
|
||||||
to.Sender = message.Sender
|
to.Sender = message.Sender
|
||||||
to.SenderColor = message.SenderColor
|
to.SenderColor = message.SenderColor
|
||||||
|
to.TextColor = message.TextColor
|
||||||
to.Timestamp = message.Timestamp
|
to.Timestamp = message.Timestamp
|
||||||
to.Date = message.Date
|
to.Date = message.Date
|
||||||
to.Text = message.Text
|
to.Text = message.Text
|
||||||
|
to.State = message.State
|
||||||
to.RecalculateBuffer()
|
to.RecalculateBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,14 +102,7 @@ func (message *Message) GetSender() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSenderColor returns the color the name of the sender should be shown in.
|
func (message *Message) getStateSpecificColor() tcell.Color {
|
||||||
//
|
|
||||||
// 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 {
|
|
||||||
switch message.State {
|
switch message.State {
|
||||||
case MessageStateSending:
|
case MessageStateSending:
|
||||||
return tcell.ColorGray
|
return tcell.ColorGray
|
||||||
@ -114,32 +111,44 @@ func (message *Message) GetSenderColor() tcell.Color {
|
|||||||
case MessageStateDefault:
|
case MessageStateDefault:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return message.SenderColor
|
return tcell.ColorDefault
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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() (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.
|
// 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.
|
||||||
|
//
|
||||||
// As with GetSenderColor(), messages being sent and messages that failed to be sent are
|
// As with GetSenderColor(), messages being sent and messages that failed to be sent are
|
||||||
// gray and red respectively.
|
// gray and red respectively.
|
||||||
//
|
//
|
||||||
// However, other messages are the default color instead of a color stored in the struct.
|
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTimestampColor returns the color the timestamp should be shown in.
|
|
||||||
//
|
|
||||||
// Currently, this simply calls GetTextColor().
|
|
||||||
func (message *Message) GetTimestampColor() tcell.Color {
|
func (message *Message) GetTimestampColor() tcell.Color {
|
||||||
return message.GetTextColor()
|
return message.getStateSpecificColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecalculateBuffer calculates the buffer again with the previously provided width.
|
// RecalculateBuffer calculates the buffer again with the previously provided width.
|
||||||
|
@ -138,10 +138,7 @@ func (view *MainView) sendTempMessage(roomView *widget.RoomView, tempMessage *ty
|
|||||||
defer view.gmx.Recover()
|
defer view.gmx.Recover()
|
||||||
eventID, err := view.matrix.SendMessage(roomView.Room.ID, tempMessage.Type, tempMessage.Text)
|
eventID, err := view.matrix.SendMessage(roomView.Room.ID, tempMessage.Type, tempMessage.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tempMessage.TextColor = tcell.ColorRed
|
tempMessage.State = types.MessageStateFailed
|
||||||
tempMessage.TimestampColor = tcell.ColorRed
|
|
||||||
tempMessage.SenderColor = tcell.ColorRed
|
|
||||||
tempMessage.Sender = "Error"
|
|
||||||
roomView.SetStatus(fmt.Sprintf("Failed to send message: %s", err))
|
roomView.SetStatus(fmt.Sprintf("Failed to send message: %s", err))
|
||||||
} else {
|
} else {
|
||||||
roomView.MessageView().UpdateMessageID(tempMessage, eventID)
|
roomView.MessageView().UpdateMessageID(tempMessage, eventID)
|
||||||
|
@ -152,7 +152,6 @@ func (view *MessageView) AddMessage(message *types.Message, direction MessageDir
|
|||||||
if msg != nil && messageExists {
|
if msg != nil && messageExists {
|
||||||
message.CopyTo(msg)
|
message.CopyTo(msg)
|
||||||
message = msg
|
message = msg
|
||||||
message.SetIsSending(false)
|
|
||||||
direction = IgnoreMessage
|
direction = IgnoreMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,10 +253,7 @@ func (view *RoomView) NewTempMessage(msgtype, text string) *types.Message {
|
|||||||
id := strconv.FormatInt(now.UnixNano(), 10)
|
id := strconv.FormatInt(now.UnixNano(), 10)
|
||||||
sender := view.Room.GetSessionOwner().DisplayName
|
sender := view.Room.GetSessionOwner().DisplayName
|
||||||
message := view.NewMessage(id, sender, msgtype, text, now)
|
message := view.NewMessage(id, sender, msgtype, text, now)
|
||||||
message.SetIsSending(true)
|
message.State = types.MessageStateSending
|
||||||
message.TimestampColor = tcell.ColorGray
|
|
||||||
message.TextColor = tcell.ColorGray
|
|
||||||
message.SenderColor = tcell.ColorGray
|
|
||||||
view.AddMessage(message, AppendMessage)
|
view.AddMessage(message, AppendMessage)
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user