aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-04-20 22:19:42 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-04-20 22:19:42 -0700
commit3934a0487ad80f231e4088902bf8308c12c2d0b0 (patch)
tree846ebd450292db1309e79bdef20b2c17692eafdc /Hotline
parent1a82975ad00bced8bba8cd6df6a9920a7ae93c61 (diff)
Add handling for new news post transaction
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Hotline/HotlineClient.swift8
-rw-r--r--Hotline/Models/Hotline.swift13
-rw-r--r--Hotline/Utility/SoundEffects.swift1
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