diff --git a/config/config.go b/config/config.go index 634120b..d85e243 100644 --- a/config/config.go +++ b/config/config.go @@ -40,15 +40,16 @@ type AuthCache struct { } type UserPreferences struct { - HideUserList bool `yaml:"hide_user_list"` - HideRoomList bool `yaml:"hide_room_list"` - BareMessageView bool `yaml:"bare_message_view"` - DisableImages bool `yaml:"disable_images"` - DisableTypingNotifs bool `yaml:"disable_typing_notifs"` - DisableEmojis bool `yaml:"disable_emojis"` - DisableMarkdown bool `yaml:"disable_markdown"` - DisableHTML bool `yaml:"disable_html"` - DisableDownloads bool `yaml:"disable_downloads"` + HideUserList bool `yaml:"hide_user_list"` + HideRoomList bool `yaml:"hide_room_list"` + BareMessageView bool `yaml:"bare_message_view"` + DisableImages bool `yaml:"disable_images"` + DisableTypingNotifs bool `yaml:"disable_typing_notifs"` + DisableEmojis bool `yaml:"disable_emojis"` + DisableMarkdown bool `yaml:"disable_markdown"` + DisableHTML bool `yaml:"disable_html"` + DisableDownloads bool `yaml:"disable_downloads"` + DisableNotifications bool `yaml:"disable_notifications"` } // Config contains the main config of gomuks. diff --git a/ui/commands.go b/ui/commands.go index ba13fc3..dc26733 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -559,51 +559,76 @@ func cmdSetState(cmd *Command) { } } +type ToggleMessage interface { + Format(state bool) string +} + +type HideMessage string + +func (hm HideMessage) Format(state bool) string { + if state { + return string(hm) + " is now hidden" + } else { + return string(hm) + " is now visible" + } +} + +type SimpleToggleMessage string + +func (stm SimpleToggleMessage) Format(state bool) string { + if state { + return "Disabled " + string(stm) + } else { + return "Enabled " + string(stm) + } +} + +var toggleMsg = map[string]ToggleMessage{ + "rooms": HideMessage("room list sidebar"), + "users": HideMessage("user list sidebar"), + "baremessages": SimpleToggleMessage("bare message view"), + "images": SimpleToggleMessage("image rendering"), + "typingnotif": SimpleToggleMessage("typing notifications"), + "emojis": SimpleToggleMessage("emoji shortcode conversion"), + "html": SimpleToggleMessage("HTML input"), + "markdown": SimpleToggleMessage("markdown input"), + "downloads": SimpleToggleMessage("automatic downloads"), + "notifications": SimpleToggleMessage("desktop notifications"), +} + func cmdToggle(cmd *Command) { if len(cmd.Args) == 0 { cmd.Reply("Usage: /toggle ") return } + var val *bool switch cmd.Args[0] { case "rooms": - cmd.Config.Preferences.HideRoomList = !cmd.Config.Preferences.HideRoomList + val = &cmd.Config.Preferences.HideRoomList case "users": - cmd.Config.Preferences.HideUserList = !cmd.Config.Preferences.HideUserList + val = &cmd.Config.Preferences.HideUserList case "baremessages": - cmd.Config.Preferences.BareMessageView = !cmd.Config.Preferences.BareMessageView + val = &cmd.Config.Preferences.BareMessageView case "images": - cmd.Config.Preferences.DisableImages = !cmd.Config.Preferences.DisableImages + val = &cmd.Config.Preferences.DisableImages case "typingnotif": - cmd.Config.Preferences.DisableTypingNotifs = !cmd.Config.Preferences.DisableTypingNotifs + val = &cmd.Config.Preferences.DisableTypingNotifs case "emojis": - cmd.Config.Preferences.DisableEmojis = !cmd.Config.Preferences.DisableEmojis + val = &cmd.Config.Preferences.DisableEmojis case "html": - cmd.Config.Preferences.DisableHTML = !cmd.Config.Preferences.DisableHTML - if cmd.Config.Preferences.DisableHTML { - cmd.Reply("Disabled HTML input") - } else { - cmd.Reply("Enabled HTML input") - } + val = &cmd.Config.Preferences.DisableHTML case "markdown": - cmd.Config.Preferences.DisableMarkdown = !cmd.Config.Preferences.DisableMarkdown - if cmd.Config.Preferences.DisableMarkdown { - cmd.Reply("Disabled Markdown input") - } else { - cmd.Reply("Enabled Markdown input") - } + val = &cmd.Config.Preferences.DisableMarkdown case "downloads": - cmd.Config.Preferences.DisableDownloads = !cmd.Config.Preferences.DisableDownloads - if cmd.Config.Preferences.DisableDownloads { - cmd.Reply("Disabled Downloads input") - } else { - cmd.Reply("Enabled Downloads input") - } + val = &cmd.Config.Preferences.DisableDownloads + case "notifications": + val = &cmd.Config.Preferences.DisableNotifications default: cmd.Reply("Usage: /toggle ") return } - // is there a reason this is called twice? - // cmd.UI.Render() + *val = !(*val) + cmd.Reply(toggleMsg[cmd.Args[0]].Format(*val)) cmd.UI.Render() go cmd.Matrix.SendPreferencesToMatrix() } diff --git a/ui/view-main.go b/ui/view-main.go index 581e186..e38756f 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -426,7 +426,7 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul view.matrix.MarkRead(room.ID, message.ID()) } - if shouldNotify && !recentlyFocused { + if shouldNotify && !recentlyFocused && !view.config.Preferences.DisableNotifications { // Push rules say notify and the terminal is not focused, send desktop notification. shouldPlaySound := should.PlaySound && should.SoundName == "default" &&