From 06c306bee91ce2b7e7b5f32fad7c3f8b5b38d883 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 10 Apr 2019 01:42:27 +0300 Subject: Fix date change messages and input submit handling --- ui/messages/base.go | 6 ++++++ ui/messages/expandedtextmessage.go | 21 +++++++++++++++++++++ ui/messages/message.go | 1 + 3 files changed, 28 insertions(+) (limited to 'ui/messages') diff --git a/ui/messages/base.go b/ui/messages/base.go index d9db866..f54c2cd 100644 --- a/ui/messages/base.go +++ b/ui/messages/base.go @@ -191,6 +191,12 @@ func (msg *BaseMessage) FormatDate() string { return msg.MsgTimestamp.Format(DateFormat) } +func (msg *BaseMessage) SameDate(message UIMessage) bool { + year1, month1, day1 := msg.Timestamp().Date() + year2, month2, day2 := message.Timestamp().Date() + return day1 == day2 && month1 == month2 && year1 == year2 +} + func (msg *BaseMessage) ID() string { if len(msg.MsgID) == 0 { return msg.MsgTxnID diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go index 4a4ed24..b2005b9 100644 --- a/ui/messages/expandedtextmessage.go +++ b/ui/messages/expandedtextmessage.go @@ -17,7 +17,10 @@ package messages import ( + "time" + "maunium.net/go/mautrix" + "maunium.net/go/tcell" "maunium.net/go/gomuks/config" "maunium.net/go/gomuks/ui/messages/tstring" @@ -36,6 +39,24 @@ func NewExpandedTextMessage(event *mautrix.Event, displayname string, text tstri } } +var ZeroTime = time.Time{} + +func NewDateChangeMessage(text string) UIMessage { + midnight := time.Now() + midnight = time.Date(midnight.Year(), midnight.Month(), midnight.Day(), + 0, 0, 0, 0, + midnight.Location()) + return &ExpandedTextMessage{ + BaseMessage: BaseMessage{ + MsgSenderID: "*", + MsgSender: "*", + MsgTimestamp: midnight, + MsgIsService: true, + }, + MsgText: tstring.NewColorTString(text, tcell.ColorGreen), + } +} + func (msg *ExpandedTextMessage) GenerateText() tstring.TString { return msg.MsgText } diff --git a/ui/messages/message.go b/ui/messages/message.go index bd78e5d..c1f2014 100644 --- a/ui/messages/message.go +++ b/ui/messages/message.go @@ -35,6 +35,7 @@ type UIMessage interface { TimestampColor() tcell.Color FormatTime() string FormatDate() string + SameDate(message UIMessage) bool CalculateBuffer(preferences config.UserPreferences, width int) Draw(screen mauview.Screen) -- cgit v1.2.3