aboutsummaryrefslogtreecommitdiff
path: root/ui/types
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-22 21:44:46 +0200
committerTulir Asokan <tulir@maunium.net>2018-03-22 21:45:02 +0200
commit152b89ed5e6a4a3edbfc40222b4388049a213b82 (patch)
treee8507622e14f873128dd457b0f95f13cc460b459 /ui/types
parent702a75a8c0355737e3e62735b59fe30bee7e42f4 (diff)
Add support for m.emote. Fixes #6
Diffstat (limited to 'ui/types')
-rw-r--r--ui/types/message.go29
-rw-r--r--ui/types/meta.go5
2 files changed, 32 insertions, 2 deletions
diff --git a/ui/types/message.go b/ui/types/message.go
index e6ded4a..5cbc61d 100644
--- a/ui/types/message.go
+++ b/ui/types/message.go
@@ -17,6 +17,7 @@
package types
import (
+ "fmt"
"regexp"
"strings"
@@ -26,13 +27,15 @@ import (
type Message struct {
BasicMeta
+ Type string
ID string
Text string
+ sending bool
buffer []string
prevBufferWidth int
}
-func NewMessage(id, sender, text, timestamp, date string, senderColor tcell.Color) *Message {
+func NewMessage(id, sender, msgtype, text, timestamp, date string, senderColor tcell.Color) *Message {
return &Message{
BasicMeta: BasicMeta{
Sender: sender,
@@ -42,9 +45,11 @@ func NewMessage(id, sender, text, timestamp, date string, senderColor tcell.Colo
TextColor: tcell.ColorDefault,
TimestampColor: tcell.ColorDefault,
},
+ Type: msgtype,
Text: text,
ID: id,
prevBufferWidth: 0,
+ sending: false,
}
}
@@ -65,7 +70,11 @@ func (message *Message) CalculateBuffer(width int) {
return
}
message.buffer = []string{}
- forcedLinebreaks := strings.Split(message.Text, "\n")
+ text := message.Text
+ if message.Type == "m.emote" {
+ text = fmt.Sprintf("* %s %s", message.Sender, message.Text)
+ }
+ forcedLinebreaks := strings.Split(text, "\n")
newlines := 0
for _, str := range forcedLinebreaks {
if len(str) == 0 && newlines < 1 {
@@ -94,6 +103,22 @@ func (message *Message) CalculateBuffer(width int) {
message.prevBufferWidth = width
}
+func (message *Message) GetDisplaySender() string {
+ if message.sending {
+ return "Sending..."
+ }
+ switch message.Type {
+ case "m.emote":
+ return ""
+ default:
+ return message.Sender
+ }
+}
+
+func (message *Message) SetIsSending(sending bool) {
+ message.sending = sending
+}
+
func (message *Message) RecalculateBuffer() {
message.CalculateBuffer(message.prevBufferWidth)
}
diff --git a/ui/types/meta.go b/ui/types/meta.go
index c1817d4..03e18d6 100644
--- a/ui/types/meta.go
+++ b/ui/types/meta.go
@@ -22,6 +22,7 @@ import (
type MessageMeta interface {
GetSender() string
+ GetDisplaySender() string
GetSenderColor() tcell.Color
GetTextColor() tcell.Color
GetTimestampColor() tcell.Color
@@ -34,6 +35,10 @@ type BasicMeta struct {
SenderColor, TextColor, TimestampColor tcell.Color
}
+func (meta *BasicMeta) GetDisplaySender() string {
+ return meta.Sender
+}
+
func (meta *BasicMeta) GetSender() string {
return meta.Sender
}