Fix date change messages and input submit handling

This commit is contained in:
Tulir Asokan
2019-04-10 01:42:27 +03:00
parent bbde121947
commit 06c306bee9
5 changed files with 54 additions and 25 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)