Fix date change messages and input submit handling
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user