Merge remote-tracking branch 'lxea/hidetimestamp'

This commit is contained in:
Tulir Asokan 2021-09-19 20:54:04 -04:00
commit 57d0c8db5f
3 changed files with 21 additions and 3 deletions

View File

@ -43,6 +43,7 @@ type AuthCache struct {
type UserPreferences struct { type UserPreferences struct {
HideUserList bool `yaml:"hide_user_list"` HideUserList bool `yaml:"hide_user_list"`
HideRoomList bool `yaml:"hide_room_list"` HideRoomList bool `yaml:"hide_room_list"`
HideTimeStamp bool `yaml:"hide_time_stamp"`
BareMessageView bool `yaml:"bare_message_view"` BareMessageView bool `yaml:"bare_message_view"`
DisableImages bool `yaml:"disable_images"` DisableImages bool `yaml:"disable_images"`
DisableTypingNotifs bool `yaml:"disable_typing_notifs"` DisableTypingNotifs bool `yaml:"disable_typing_notifs"`

View File

@ -703,6 +703,7 @@ func (nkm NewlineKeybindMessage) Name() string {
var toggleMsg = map[string]ToggleMessage{ var toggleMsg = map[string]ToggleMessage{
"rooms": HideMessage("Room list sidebar"), "rooms": HideMessage("Room list sidebar"),
"users": HideMessage("User list sidebar"), "users": HideMessage("User list sidebar"),
"timestamp": HideMessage("Message timestamp"),
"baremessages": SimpleToggleMessage("bare message view"), "baremessages": SimpleToggleMessage("bare message view"),
"images": SimpleToggleMessage("image rendering"), "images": SimpleToggleMessage("image rendering"),
"typingnotif": SimpleToggleMessage("typing notifications"), "typingnotif": SimpleToggleMessage("typing notifications"),
@ -738,6 +739,8 @@ func cmdToggle(cmd *Command) {
val = &cmd.Config.Preferences.HideRoomList val = &cmd.Config.Preferences.HideRoomList
case "users": case "users":
val = &cmd.Config.Preferences.HideUserList val = &cmd.Config.Preferences.HideUserList
case "timestamp":
val = &cmd.Config.Preferences.HideTimeStamp
case "baremessages": case "baremessages":
val = &cmd.Config.Preferences.BareMessageView val = &cmd.Config.Preferences.BareMessageView
case "images": case "images":

View File

@ -160,8 +160,12 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction MessageDir
width := view.width() width := view.width()
bare := view.config.Preferences.BareMessageView bare := view.config.Preferences.BareMessageView
if !bare { if !bare {
if view.config.Preferences.HideTimeStamp {
width -= TimestampSenderGap + view.widestSender() + SenderMessageGap
} else {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
} }
}
message.CalculateBuffer(view.config.Preferences, width) message.CalculateBuffer(view.config.Preferences, width)
makeDateChange := func() *messages.UIMessage { makeDateChange := func() *messages.UIMessage {
@ -323,8 +327,12 @@ func (view *MessageView) recalculateBuffers() {
if recalculateMessageBuffers || len(view.messages) != view.prevMsgCount { if recalculateMessageBuffers || len(view.messages) != view.prevMsgCount {
width := view.width() width := view.width()
if !prefs.BareMessageView { if !prefs.BareMessageView {
if prefs.HideTimeStamp {
width -= TimestampSenderGap + view.widestSender() + SenderMessageGap
} else {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
} }
}
view.msgBuffer = []*messages.UIMessage{} view.msgBuffer = []*messages.UIMessage{}
view.prevMsgCount = 0 view.prevMsgCount = 0
for i, message := range view.messages { for i, message := range view.messages {
@ -436,6 +444,9 @@ func (view *MessageView) OnMouseEvent(event mauview.MouseEvent) bool {
view.msgBufferLock.RUnlock() view.msgBufferLock.RUnlock()
usernameX := view.TimestampWidth + TimestampSenderGap usernameX := view.TimestampWidth + TimestampSenderGap
if !view.config.Preferences.HideTimeStamp {
usernameX = TimestampSenderGap
}
messageX := usernameX + view.widestSender() + SenderMessageGap messageX := usernameX + view.widestSender() + SenderMessageGap
if x >= messageX { if x >= messageX {
@ -602,6 +613,9 @@ func (view *MessageView) Draw(screen mauview.Screen) {
} }
usernameX := view.TimestampWidth + TimestampSenderGap usernameX := view.TimestampWidth + TimestampSenderGap
if view.config.Preferences.HideTimeStamp {
usernameX = TimestampSenderGap
}
messageX := usernameX + view.widestSender() + SenderMessageGap messageX := usernameX + view.widestSender() + SenderMessageGap
bareMode := view.config.Preferences.BareMessageView bareMode := view.config.Preferences.BareMessageView
@ -643,7 +657,7 @@ func (view *MessageView) Draw(screen mauview.Screen) {
continue continue
} }
if len(msg.FormatTime()) > 0 { if len(msg.FormatTime()) > 0 && !view.config.Preferences.HideTimeStamp {
widget.WriteLineSimpleColor(screen, msg.FormatTime(), 0, line, msg.TimestampColor()) widget.WriteLineSimpleColor(screen, msg.FormatTime(), 0, line, msg.TimestampColor())
} }
// TODO hiding senders might not be that nice after all, maybe an option? (disabled for now) // TODO hiding senders might not be that nice after all, maybe an option? (disabled for now)