aboutsummaryrefslogtreecommitdiff
path: root/ui/widget
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/widget
parent702a75a8c0355737e3e62735b59fe30bee7e42f4 (diff)
Add support for m.emote. Fixes #6
Diffstat (limited to 'ui/widget')
-rw-r--r--ui/widget/message-view.go10
-rw-r--r--ui/widget/room-view.go18
2 files changed, 22 insertions, 6 deletions
diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go
index fe906b5..a4ba236 100644
--- a/ui/widget/message-view.go
+++ b/ui/widget/message-view.go
@@ -74,8 +74,8 @@ func NewMessageView() *MessageView {
}
}
-func (view *MessageView) NewMessage(id, sender, text string, timestamp time.Time) *types.Message {
- return types.NewMessage(id, sender, text,
+func (view *MessageView) NewMessage(id, sender, msgtype, text string, timestamp time.Time) *types.Message {
+ return types.NewMessage(id, sender, msgtype, text,
timestamp.Format(view.TimestampFormat),
timestamp.Format(view.DateFormat),
GetHashColor(sender))
@@ -151,6 +151,8 @@ func (view *MessageView) AddMessage(message *types.Message, direction MessageDir
msg, messageExists := view.messageIDs[message.ID]
if msg != nil && messageExists {
message.CopyTo(msg)
+ message = msg
+ message.SetIsSending(false)
direction = IgnoreMessage
}
@@ -338,9 +340,9 @@ func (view *MessageView) Draw(screen tcell.Screen) {
if len(meta.GetTimestamp()) > 0 {
view.writeLine(screen, meta.GetTimestamp(), x, y+line, meta.GetTimestampColor())
}
- if len(meta.GetSender()) > 0 && (prevMeta == nil || meta.GetSender() != prevMeta.GetSender()) {
+ if prevMeta == nil || meta.GetSender() != prevMeta.GetSender() {
view.writeLineRight(
- screen, meta.GetSender(),
+ screen, meta.GetDisplaySender(),
x+usernameOffsetX, y+line,
view.widestSender, meta.GetSenderColor())
}
diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go
index 141e993..7e01fd4 100644
--- a/ui/widget/room-view.go
+++ b/ui/widget/room-view.go
@@ -19,6 +19,7 @@ package widget
import (
"fmt"
"path/filepath"
+ "strconv"
"strings"
"time"
@@ -239,12 +240,25 @@ func (view *RoomView) UpdateUserList() {
}
}
-func (view *RoomView) NewMessage(id, sender, text string, timestamp time.Time) *types.Message {
+func (view *RoomView) NewMessage(id, sender, msgtype, text string, timestamp time.Time) *types.Message {
member := view.Room.GetMember(sender)
if member != nil {
sender = member.DisplayName
}
- return view.content.NewMessage(id, sender, text, timestamp)
+ return view.content.NewMessage(id, sender, msgtype, text, timestamp)
+}
+
+func (view *RoomView) NewTempMessage(msgtype, text string) *types.Message {
+ now := time.Now()
+ 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
+ view.AddMessage(message, AppendMessage)
+ return message
}
func (view *RoomView) AddMessage(message *types.Message, direction MessageDirection) {