diff options
| author | Dustin Mierau <mierau@users.noreply.github.com> | 2024-05-14 15:40:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-14 15:40:07 -0700 |
| commit | ec78dfa6c0a407cb9160e913886887a764f8e1d3 (patch) | |
| tree | 486c877688ff11d636c8427e80243430329b41d4 /Hotline | |
| parent | 1dbc84ae671d87b7d5aaef35667c43a9d5fe9f37 (diff) | |
| parent | 8dd886979ec61e5adb73d8c662de07070be75d41 (diff) | |
Merge pull request #19 from jhalter/add_show_join_leave_pref
Add "Show Join/Leave in Chat" option
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Models/Hotline.swift | 9 | ||||
| -rw-r--r-- | Hotline/Models/Preferences.swift | 7 | ||||
| -rw-r--r-- | Hotline/macOS/SettingsView.swift | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index 4c9defa..06baf04 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -854,7 +854,10 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { func hotlineUserDisconnected(userID: UInt16) { if let existingUserIndex = self.users.firstIndex(where: { $0.id == UInt(userID) }) { let user = self.users.remove(at: existingUserIndex) - self.chat.append(ChatMessage(text: "\(user.name) left", type: .status, date: Date())) + + if Prefs.shared.showJoinLeaveMessages { + self.chat.append(ChatMessage(text: "\(user.name) left", type: .status, date: Date())) + } if Prefs.shared.playSounds && Prefs.shared.playLeaveSound { SoundEffectPlayer.shared.playSoundEffect(.userLogout) @@ -972,7 +975,9 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { print("Hotline: added user: \(user.name)") self.users.append(User(hotlineUser: user)) - self.chat.append(ChatMessage(text: "\(user.name) joined", type: .status, date: Date())) + if Prefs.shared.showJoinLeaveMessages { + self.chat.append(ChatMessage(text: "\(user.name) joined", type: .status, date: Date())) + } } } diff --git a/Hotline/Models/Preferences.swift b/Hotline/Models/Preferences.swift index 3925bc7..207ce91 100644 --- a/Hotline/Models/Preferences.swift +++ b/Hotline/Models/Preferences.swift @@ -17,6 +17,7 @@ enum PrefsKeys: String { case playErrorSound = "play error sound" case playChatInvitationSound = "play chat invitation sound" case showBannerToolbar = "show banner toolbar" + case showJoinLeaveMessages = "show join leave messages" } @Observable @@ -39,6 +40,7 @@ class Prefs { PrefsKeys.playErrorSound.rawValue: true, PrefsKeys.playChatInvitationSound.rawValue: true, PrefsKeys.showBannerToolbar.rawValue: true, + PrefsKeys.showJoinLeaveMessages.rawValue: true, ]) self.username = UserDefaults.standard.string(forKey: PrefsKeys.username.rawValue)! @@ -57,6 +59,7 @@ class Prefs { self.playErrorSound = UserDefaults.standard.bool(forKey: PrefsKeys.playErrorSound.rawValue) self.playChatInvitationSound = UserDefaults.standard.bool(forKey: PrefsKeys.playChatInvitationSound.rawValue) self.showBannerToolbar = UserDefaults.standard.bool(forKey: PrefsKeys.showBannerToolbar.rawValue) + self.showJoinLeaveMessages = UserDefaults.standard.bool(forKey: PrefsKeys.showJoinLeaveMessages.rawValue) } public static let shared = Prefs() @@ -124,4 +127,8 @@ class Prefs { var showBannerToolbar: Bool { didSet { UserDefaults.standard.set(self.showBannerToolbar, forKey: PrefsKeys.showBannerToolbar.rawValue) } } + + var showJoinLeaveMessages: Bool { + didSet { UserDefaults.standard.set(self.showJoinLeaveMessages, forKey: PrefsKeys.showJoinLeaveMessages.rawValue) } + } } diff --git a/Hotline/macOS/SettingsView.swift b/Hotline/macOS/SettingsView.swift index 79f0156..81a2f8d 100644 --- a/Hotline/macOS/SettingsView.swift +++ b/Hotline/macOS/SettingsView.swift @@ -11,6 +11,7 @@ struct GeneralSettingsView: View { Form { TextField("Your Name", text: $username, prompt: Text("guest")) + Toggle("Show Join/Leave in Chat", isOn: $preferences.showJoinLeaveMessages) Toggle("Refuse private messages", isOn: $preferences.refusePrivateMessages) Toggle("Refuse private chat", isOn: $preferences.refusePrivateChat) Toggle("Automatic Response", isOn: $preferences.enableAutomaticMessage) |