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 /ui | |
parent | 815190be147e575f12211c468f8121e5c60e6337 (diff) |
Add toggle for desktop notifications
Diffstat (limited to 'ui')
-rw-r--r-- | ui/commands.go | 77 | ||||
-rw-r--r-- | ui/view-main.go | 2 |
2 files changed, 52 insertions, 27 deletions
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" && |