diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-20 19:14:39 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-20 19:55:42 +0200 |
commit | 095b982603c26e250e61cf006157019e2b55be74 (patch) | |
tree | 080644e83572b0dff33e77fbad5e2301243fd5ab /ui/types | |
parent | 59cd9003013aa62495d2a73c28f22fd7e64f861a (diff) |
Show messages in message view while sending
Diffstat (limited to 'ui/types')
-rw-r--r-- | ui/types/message.go | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/ui/types/message.go b/ui/types/message.go index 8899a7d..7b96193 100644 --- a/ui/types/message.go +++ b/ui/types/message.go @@ -25,24 +25,26 @@ import ( ) type Message struct { - ID string - Sender string - Text string - Timestamp string - Date string - - Buffer []string - SenderColor tcell.Color + BasicMeta + ID string + Text string + Buffer []string + prevBufferWidth int } func NewMessage(id, sender, text, timestamp, date string, senderColor tcell.Color) *Message { return &Message{ - ID: id, - Sender: sender, - Text: text, - Timestamp: timestamp, - Date: date, - SenderColor: senderColor, + BasicMeta: BasicMeta{ + Sender: sender, + Timestamp: timestamp, + Date: date, + SenderColor: senderColor, + TextColor: tcell.ColorDefault, + TimestampColor: tcell.ColorDefault, + }, + Text: text, + ID: id, + prevBufferWidth: 0, } } @@ -51,6 +53,13 @@ var ( spacePattern = regexp.MustCompile(`\s+`) ) +func (message *Message) CopyTo(to *Message) { + to.BasicMeta = message.BasicMeta + to.ID = message.ID + to.Text = message.Text + to.RecalculateBuffer() +} + func (message *Message) CalculateBuffer(width int) { if width < 1 { return @@ -82,28 +91,9 @@ func (message *Message) CalculateBuffer(width int) { str = str[len(extract):] } } + message.prevBufferWidth = width } -func (message *Message) GetSender() string { - return message.Sender -} - -func (message *Message) GetSenderColor() tcell.Color { - return message.SenderColor -} - -func (message *Message) GetTimestamp() string { - return message.Timestamp -} - -func (message *Message) GetDate() string { - return message.Date -} - -func (message *Message) GetTextColor() tcell.Color { - return tcell.ColorDefault -} - -func (message *Message) GetTimestampColor() tcell.Color { - return tcell.ColorDefault +func (message *Message) RecalculateBuffer() { + message.CalculateBuffer(message.prevBufferWidth) } |