diff options
author | Tulir Asokan <tulir@maunium.net> | 2020-04-16 19:42:55 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2020-04-19 15:01:16 +0300 |
commit | bc80ff3a56a81ee07580880bd2a169958910b489 (patch) | |
tree | bffd486509553637349e6c26051fa80251256564 | |
parent | 815190be147e575f12211c468f8121e5c60e6337 (diff) |
Add toggle for desktop notifications
-rw-r--r-- | config/config.go | 19 | ||||
-rw-r--r-- | ui/commands.go | 77 | ||||
-rw-r--r-- | ui/view-main.go | 2 |
3 files changed, 62 insertions, 36 deletions
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 <rooms/users/baremessages/images/typingnotif/emojis>") 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 <rooms/users/baremessages/images/typingnotif/emojis>") 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" && |