aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-05-11 19:55:17 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-05-11 19:55:17 -0700
commit8dd886979ec61e5adb73d8c662de07070be75d41 (patch)
treeb84f3d4d9028c856efeab732cda1ef9d4b54e1cc /Hotline
parent6f166f0f12aab78fb0ab69cca386c8d8450cd9cc (diff)
Add "Show Join/Leave in Chat" option
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Models/Hotline.swift9
-rw-r--r--Hotline/Models/Preferences.swift7
-rw-r--r--Hotline/macOS/SettingsView.swift1
3 files changed, 15 insertions, 2 deletions
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index 5dc61ab..308a764 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -810,7 +810,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)
@@ -928,7 +931,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)