Skip to content

Commit

Permalink
Merge remote-tracking branch 'lxea/hidetimestamp'
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 20, 2021
2 parents 05790c1 + cd82d4d commit 57d0c8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AuthCache struct {
type UserPreferences struct {
HideUserList bool `yaml:"hide_user_list"`
HideRoomList bool `yaml:"hide_room_list"`
HideTimeStamp bool `yaml:"hide_time_stamp"`
BareMessageView bool `yaml:"bare_message_view"`
DisableImages bool `yaml:"disable_images"`
DisableTypingNotifs bool `yaml:"disable_typing_notifs"`
Expand Down
3 changes: 3 additions & 0 deletions ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ func (nkm NewlineKeybindMessage) Name() string {
var toggleMsg = map[string]ToggleMessage{
"rooms": HideMessage("Room list sidebar"),
"users": HideMessage("User list sidebar"),
"timestamp": HideMessage("Message timestamp"),
"baremessages": SimpleToggleMessage("bare message view"),
"images": SimpleToggleMessage("image rendering"),
"typingnotif": SimpleToggleMessage("typing notifications"),
Expand Down Expand Up @@ -738,6 +739,8 @@ func cmdToggle(cmd *Command) {
val = &cmd.Config.Preferences.HideRoomList
case "users":
val = &cmd.Config.Preferences.HideUserList
case "timestamp":
val = &cmd.Config.Preferences.HideTimeStamp
case "baremessages":
val = &cmd.Config.Preferences.BareMessageView
case "images":
Expand Down
20 changes: 17 additions & 3 deletions ui/message-view.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction MessageDir
width := view.width()
bare := view.config.Preferences.BareMessageView
if !bare {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
if view.config.Preferences.HideTimeStamp {
width -= TimestampSenderGap + view.widestSender() + SenderMessageGap
} else {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
}
}
message.CalculateBuffer(view.config.Preferences, width)

Expand Down Expand Up @@ -323,7 +327,11 @@ func (view *MessageView) recalculateBuffers() {
if recalculateMessageBuffers || len(view.messages) != view.prevMsgCount {
width := view.width()
if !prefs.BareMessageView {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
if prefs.HideTimeStamp {
width -= TimestampSenderGap + view.widestSender() + SenderMessageGap
} else {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender() + SenderMessageGap
}
}
view.msgBuffer = []*messages.UIMessage{}
view.prevMsgCount = 0
Expand Down Expand Up @@ -436,6 +444,9 @@ func (view *MessageView) OnMouseEvent(event mauview.MouseEvent) bool {
view.msgBufferLock.RUnlock()

usernameX := view.TimestampWidth + TimestampSenderGap
if !view.config.Preferences.HideTimeStamp {
usernameX = TimestampSenderGap
}
messageX := usernameX + view.widestSender() + SenderMessageGap

if x >= messageX {
Expand Down Expand Up @@ -602,6 +613,9 @@ func (view *MessageView) Draw(screen mauview.Screen) {
}

usernameX := view.TimestampWidth + TimestampSenderGap
if view.config.Preferences.HideTimeStamp {
usernameX = TimestampSenderGap
}
messageX := usernameX + view.widestSender() + SenderMessageGap

bareMode := view.config.Preferences.BareMessageView
Expand Down Expand Up @@ -643,7 +657,7 @@ func (view *MessageView) Draw(screen mauview.Screen) {
continue
}

if len(msg.FormatTime()) > 0 {
if len(msg.FormatTime()) > 0 && !view.config.Preferences.HideTimeStamp {
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)
Expand Down

0 comments on commit 57d0c8d

Please sign in to comment.