diff options
| author | Dustin Mierau <dustin@mierau.me> | 2025-11-14 08:38:32 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2025-11-14 08:38:32 -0800 |
| commit | 46384d99b78cca150aa720eb915d161b5be8c08d (patch) | |
| tree | 33b56420adae4f3158e7a07530c12b73e9f5d312 /Hotline | |
| parent | 7ca2ece66a5d40964f5d640255d1b137433511a9 (diff) | |
Cleanup user client info sheet. Hide button if you don't have persmission to do so.
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 4 | ||||
| -rw-r--r-- | Hotline/Hotline/HotlineProtocol.swift | 9 | ||||
| -rw-r--r-- | Hotline/State/HotlineState.swift | 2 | ||||
| -rw-r--r-- | Hotline/macOS/MessageView.swift | 50 | ||||
| -rw-r--r-- | Hotline/macOS/UserInfo.swift | 25 |
5 files changed, 47 insertions, 43 deletions
diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index 1394057..1440b71 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -552,7 +552,7 @@ public actor HotlineClient { /// /// - Parameters: /// - userID: Target user ID - public func getClientInfoText(for userID: UInt16) async throws -> (username: String, info: String)? { + public func getClientInfoText(for userID: UInt16) async throws -> HotlineUserClientInfo? { var transaction = HotlineTransaction(id: self.generateTransactionID(), type: .getClientInfoText) transaction.setFieldUInt16(type: .userID, val: userID) @@ -560,7 +560,7 @@ public actor HotlineClient { if let username = reply.getField(type: .userName)?.getString(), let info = reply.getField(type: .data)?.getString() { - return (username: username, info: info) + return HotlineUserClientInfo(username: username, details: info) } return nil diff --git a/Hotline/Hotline/HotlineProtocol.swift b/Hotline/Hotline/HotlineProtocol.swift index 4857d87..92fdfd2 100644 --- a/Hotline/Hotline/HotlineProtocol.swift +++ b/Hotline/Hotline/HotlineProtocol.swift @@ -516,6 +516,15 @@ public class HotlineFile: Identifiable, Hashable { } } +public struct HotlineUserClientInfo: Identifiable { + public var username: String + public var details: String + + public var id: String { + self.username + } +} + public struct HotlineUser: Identifiable, Hashable, Sendable { public let id: UInt16 public let iconID: UInt16 diff --git a/Hotline/State/HotlineState.swift b/Hotline/State/HotlineState.swift index 318a468..e78a780 100644 --- a/Hotline/State/HotlineState.swift +++ b/Hotline/State/HotlineState.swift @@ -798,7 +798,7 @@ class HotlineState: Equatable { self.users = hotlineUsers.map { User(hotlineUser: $0) } } - func getClientInfoText(id userID: UInt16) async throws -> (username: String, info: String)? { + func getClientInfoText(id userID: UInt16) async throws -> HotlineUserClientInfo? { guard let client = self.client else { throw HotlineClientError.notConnected } diff --git a/Hotline/macOS/MessageView.swift b/Hotline/macOS/MessageView.swift index 861a14a..6690a88 100644 --- a/Hotline/macOS/MessageView.swift +++ b/Hotline/macOS/MessageView.swift @@ -1,37 +1,5 @@ import SwiftUI -struct UserInfo: Identifiable { - let username: String - let data: String - - var id: String { - self.username - } -} - -struct UserInfoView: View { - @Environment(\.dismiss) private var dismiss - - let info: UserInfo - - var body: some View { - ScrollView(.vertical) { - Text(self.info.data) - .fontDesign(.monospaced) - .textSelection(.enabled) - .padding() - } - .frame(width: 300, height: 400) - .toolbar { - if #available(macOS 26.0, *) { - Button(role: .close) { - self.dismiss() - } - } - } - } -} - struct MessageView: View { @Environment(HotlineState.self) private var model: HotlineState @Environment(\.colorScheme) private var colorScheme @@ -39,7 +7,7 @@ struct MessageView: View { @State private var input: String = "" @State private var scrollPos: Int? @State private var contentHeight: CGFloat = 0 - @State private var userInfo: UserInfo? + @State private var userInfo: HotlineUserClientInfo? @Namespace private var bottomID @FocusState private var focusedField: FocusedField? @@ -60,11 +28,13 @@ struct MessageView: View { } .background(Color(nsColor: .textBackgroundColor)) .toolbar { - ToolbarItem { - Button { - self.getUserInfo() - } label: { - Image(systemName: "info.circle") + if self.model.access?.contains(.canGetClientInfo) == true { + ToolbarItem { + Button { + self.getUserInfo() + } label: { + Image(systemName: "info.circle") + } } } } @@ -75,8 +45,8 @@ struct MessageView: View { private func getUserInfo() { Task { - if let (username, info) = try await self.model.getClientInfoText(id: self.userID) { - self.userInfo = UserInfo(username: username, data: info) + if let info = try await self.model.getClientInfoText(id: self.userID) { + self.userInfo = info } } } diff --git a/Hotline/macOS/UserInfo.swift b/Hotline/macOS/UserInfo.swift new file mode 100644 index 0000000..328fc02 --- /dev/null +++ b/Hotline/macOS/UserInfo.swift @@ -0,0 +1,25 @@ +import SwiftUI + +struct UserInfoView: View { + @Environment(\.dismiss) private var dismiss + + let info: HotlineUserClientInfo + + var body: some View { + ScrollView(.vertical) { + Text(self.info.details) + .fontDesign(.monospaced) + .textSelection(.enabled) + .frame(maxWidth: .infinity, alignment: .topLeading) + .padding() + } + .frame(width: 350, height: 400) + .toolbar { + ToolbarItem(placement: .confirmationAction) { + Button("OK") { + self.dismiss() + } + } + } + } +} |