diff options
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 8 | ||||
| -rw-r--r-- | Hotline/Models/Hotline.swift | 13 | ||||
| -rw-r--r-- | Hotline/Utility/SoundEffects.swift | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index 7006c59..c511555 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -40,6 +40,7 @@ protocol HotlineClientDelegate: AnyObject { func hotlineReceivedUserAccess(options: HotlineUserAccessOptions) func hotlineUserChanged(user: HotlineUser) func hotlineUserDisconnected(userID: UInt16) + func hotlineReceivedNewsPost(message: String) } extension HotlineClientDelegate { @@ -51,6 +52,7 @@ extension HotlineClientDelegate { func hotlineReceivedUserAccess(options: HotlineUserAccessOptions) {} func hotlineUserChanged(user: HotlineUser) {} func hotlineUserDisconnected(userID: UInt16) {} + func hotlineReceivedNewsPost(message: String) {} } enum HotlineClientStage { @@ -342,6 +344,12 @@ class HotlineClient: NetSocketDelegate { self.delegate?.hotlineReceivedUserAccess(options: accessOptions) } } + + case .newMessage: + if let messageField = packet.getField(type: .data), + let message = messageField.getString() { + self.delegate?.hotlineReceivedNewsPost(message: message) + } default: print("HotlineClient: UNKNOWN transaction \(packet.type) with \(packet.fields.count) parameters") diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index 6b5e3a7..baf87eb 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -649,6 +649,19 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { func hotlineReceivedAgreement(text: String) { self.chat.append(ChatMessage(text: text, type: .agreement, date: Date())) } + + func hotlineReceivedNewsPost(message: String) { + soundEffects.playSoundEffect(.newNews) + let messageBoardRegex = /([\s\r\n]*[_\-]+[\s\r\n]+)/ + let matches = message.matches(of: messageBoardRegex) + + if matches.count == 1 { + let range = matches[0].range + self.messageBoard.insert(String(message[message.startIndex..<range.lowerBound]), at: 0) + } else { + self.messageBoard.insert(message, at: 0) + } + } func hotlineReceivedServerMessage(message: String) { // print("Hotline: received server message:\n\(message)") diff --git a/Hotline/Utility/SoundEffects.swift b/Hotline/Utility/SoundEffects.swift index 426bfa2..175fa5b 100644 --- a/Hotline/Utility/SoundEffects.swift +++ b/Hotline/Utility/SoundEffects.swift @@ -7,6 +7,7 @@ enum SoundEffects: String { case transferComplete = "transfer-complete" case userLogin = "user-login" case userLogout = "user-logout" + case newNews = "new-news" } @Observable |