diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-01-13 19:48:03 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-01-13 19:48:03 -0800 |
| commit | e201330efa9fe8f8177119fe001fa0c42fd4053a (patch) | |
| tree | 287567c81134760ac096c858a77bd6b356a82a6e /Hotline | |
| parent | 3f4e2c33a4c2719388d9378def981688fcaed210 (diff) | |
Add support for posting to the message board.
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 10 | ||||
| -rw-r--r-- | Hotline/Models/Hotline.swift | 4 | ||||
| -rw-r--r-- | Hotline/macOS/MessageBoardView.swift | 32 | ||||
| -rw-r--r-- | Hotline/macOS/ServerView.swift | 2 |
4 files changed, 46 insertions, 2 deletions
diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index 0535f7b..93d2485 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -466,6 +466,16 @@ class HotlineClient: NetSocketDelegate { } } + @MainActor func sendPostMessageBoard(text: String) { + guard text.count > 0 else { + return + } + + var t = HotlineTransaction(type: .oldPostNews) + t.setFieldString(type: .data, val: text) + self.sendPacket(t) + } + @MainActor func sendGetNewsCategories(path: [String] = [], callback: (([HotlineNewsCategory]) -> Void)?) { var t = HotlineTransaction(type: .getNewsCategoryNameList) if !path.isEmpty { diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index bdba307..f15bbb6 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -292,6 +292,10 @@ final class Hotline: HotlineClientDelegate, HotlineFileClientDelegate { return self.messageBoard } + @MainActor func postToMessageBoard(text: String) { + self.client.sendPostMessageBoard(text: text) + } + @MainActor func getFileList(path: [String] = []) async -> [FileInfo] { return await withCheckedContinuation { [weak self] continuation in self?.client.sendGetFileList(path: path) { [weak self] files in diff --git a/Hotline/macOS/MessageBoardView.swift b/Hotline/macOS/MessageBoardView.swift index 65a947f..e7fdeb5 100644 --- a/Hotline/macOS/MessageBoardView.swift +++ b/Hotline/macOS/MessageBoardView.swift @@ -4,6 +4,8 @@ struct MessageBoardView: View { @Environment(Hotline.self) private var model: Hotline @State private var initialLoadComplete = false + @State private var composerDisplayed = false + @State private var composerText = "" var body: some View { NavigationStack { @@ -12,6 +14,7 @@ struct MessageBoardView: View { ForEach(model.messageBoard, id: \.self) { Text($0) .lineLimit(100) + .lineSpacing(4) .padding() .textSelection(.enabled) Divider() @@ -35,10 +38,37 @@ struct MessageBoardView: View { } .background(Color(nsColor: .textBackgroundColor)) } + .sheet(isPresented: $composerDisplayed) { + TextEditor(text: $composerText) + .padding() + .font(.system(size: 13)) + .lineSpacing(4) + .background(Color(nsColor: .textBackgroundColor)) + .frame(idealWidth: 450, idealHeight: 350) + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button("Cancel") { + composerDisplayed.toggle() + } + } + + ToolbarItem(placement: .primaryAction) { + Button("Post") { + composerDisplayed.toggle() + let text = composerText + composerText = "" + model.postToMessageBoard(text: text) + Task { + await model.getMessageBoard() + } + } + } + } + } .toolbar { ToolbarItem(placement:.primaryAction) { Button { - + composerDisplayed.toggle() } label: { Image(systemName: "square.and.pencil") } diff --git a/Hotline/macOS/ServerView.swift b/Hotline/macOS/ServerView.swift index 7571bdf..aaa9c4e 100644 --- a/Hotline/macOS/ServerView.swift +++ b/Hotline/macOS/ServerView.swift @@ -167,7 +167,7 @@ struct ServerView: View { static var menuItems = [ MenuItem(name: "Chat", image: "bubble", type: .chat), MenuItem(name: "News", image: "newspaper", type: .news, serverVersion: 150), - MenuItem(name: "Board", image: "note.text", type: .messageBoard), + MenuItem(name: "Board", image: "pin", type: .messageBoard), MenuItem(name: "Files", image: "folder", type: .files), ] |