mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 10:25:18 +00:00
* Centralize UI theme colors into semantic ThemePalette tokens Introduce AppTheme/ThemePalette (Utils/Theme.swift) with an environment key and @ThemedPalette property wrapper, persisted via @AppStorage. Views now resolve background/primary/secondary/accentBlue/alertRed/ divider tokens from the environment instead of computing colors inline, removing the backgroundColor/textColor/secondaryTextColor prop-drilling through the header, composer, and people-sheet hierarchy. Matrix theme output is pixel-identical; this is groundwork for a user-selectable theme switcher. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Add liquid glass theme with in-app appearance switcher Add a .liquidGlass AppTheme alongside the matrix terminal theme, selectable from a one-line APPEARANCE row in the app info sheet (persisted via @AppStorage, applies live). Liquid glass renders system fonts and colors over a subtle gradient backdrop, with the header and composer floating as Liquid Glass panels (real .glassEffect() on iOS/macOS 26, compiler-gated with an ultraThinMaterial fallback for older SDKs). The message list scrolls underneath the chrome via safe-area insets, and all sheets share the same backdrop and surface language. The matrix theme is unchanged. Details: - Theme is threaded through ChatMessageFormatter so message AttributedStrings switch font design per theme; the per-message format cache gains a variant key so themes never serve each other's cached strings - New palette tokens: accent (interactive tint) and locationAccent (geohash green), replacing scattered hardcoded greens/blues in the voice note, waveform, verification, and people-sheet views - Header controls get full-height tap targets and the people count becomes a real Button (previously a tap gesture on the cluster) - CommandSuggestionsView renders nothing when empty instead of a zero-height view that pushed the composer input off-center - New appearance strings localized for all 29 catalog languages Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
188 lines
6.3 KiB
Swift
188 lines
6.3 KiB
Swift
import BitFoundation
|
|
import Combine
|
|
import SwiftUI
|
|
#if os(iOS)
|
|
import UIKit
|
|
#endif
|
|
|
|
@MainActor
|
|
final class ConversationUIModel: ObservableObject {
|
|
@Published private(set) var showAutocomplete = false
|
|
@Published private(set) var autocompleteSuggestions: [String] = []
|
|
@Published private(set) var currentNickname: String
|
|
@Published private(set) var isBatchingPublic = false
|
|
@Published private(set) var canSendMediaInCurrentContext = true
|
|
|
|
private let chatViewModel: ChatViewModel
|
|
private let privateConversationModel: PrivateConversationModel
|
|
private let conversations: ConversationStore
|
|
private var activeChannel: ChannelID
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
init(
|
|
chatViewModel: ChatViewModel,
|
|
privateConversationModel: PrivateConversationModel,
|
|
conversations: ConversationStore
|
|
) {
|
|
self.chatViewModel = chatViewModel
|
|
self.privateConversationModel = privateConversationModel
|
|
self.conversations = conversations
|
|
self.activeChannel = conversations.activeChannel
|
|
self.currentNickname = chatViewModel.nickname
|
|
self.isBatchingPublic = chatViewModel.isBatchingPublic
|
|
self.showAutocomplete = chatViewModel.showAutocomplete
|
|
self.autocompleteSuggestions = chatViewModel.autocompleteSuggestions
|
|
self.canSendMediaInCurrentContext = chatViewModel.canSendMediaInCurrentContext
|
|
|
|
bind()
|
|
}
|
|
|
|
func setCurrentColorScheme(_ colorScheme: ColorScheme) {
|
|
chatViewModel.currentColorScheme = colorScheme
|
|
}
|
|
|
|
func setCurrentTheme(_ theme: AppTheme) {
|
|
chatViewModel.currentTheme = theme
|
|
}
|
|
|
|
func sendMessage(_ message: String) {
|
|
chatViewModel.sendMessage(message)
|
|
}
|
|
|
|
func clearCurrentConversation() {
|
|
chatViewModel.sendMessage("/clear")
|
|
}
|
|
|
|
func sendHug(to sender: String) {
|
|
chatViewModel.sendMessage("/hug @\(sender)")
|
|
}
|
|
|
|
func sendSlap(to sender: String) {
|
|
chatViewModel.sendMessage("/slap @\(sender)")
|
|
}
|
|
|
|
func block(peerID: PeerID?, displayName: String?) {
|
|
guard let displayName else { return }
|
|
|
|
if let peerID, peerID.isGeoChat,
|
|
let full = chatViewModel.fullNostrHex(forSenderPeerID: peerID) {
|
|
chatViewModel.blockGeohashUser(pubkeyHexLowercased: full, displayName: displayName)
|
|
} else {
|
|
chatViewModel.sendMessage("/block \(displayName)")
|
|
}
|
|
}
|
|
|
|
func updateAutocomplete(for text: String, cursorPosition: Int) {
|
|
chatViewModel.updateAutocomplete(for: text, cursorPosition: cursorPosition)
|
|
}
|
|
|
|
func completeNickname(_ nickname: String, in text: inout String) -> Int {
|
|
chatViewModel.completeNickname(nickname, in: &text)
|
|
}
|
|
|
|
func formatMessage(_ message: BitchatMessage, colorScheme: ColorScheme, theme: AppTheme? = nil) -> AttributedString {
|
|
chatViewModel.formatMessageAsText(message, colorScheme: colorScheme, theme: theme)
|
|
}
|
|
|
|
func formatMessageHeader(_ message: BitchatMessage, colorScheme: ColorScheme, theme: AppTheme? = nil) -> AttributedString {
|
|
chatViewModel.formatMessageHeader(message, colorScheme: colorScheme, theme: theme)
|
|
}
|
|
|
|
func mediaAttachment(for message: BitchatMessage) -> BitchatMessage.Media? {
|
|
message.mediaAttachment(for: currentNickname)
|
|
}
|
|
|
|
func isSelfSender(peerID: PeerID?, displayName: String?) -> Bool {
|
|
chatViewModel.isSelfSender(peerID: peerID, displayName: displayName)
|
|
}
|
|
|
|
func isSentByCurrentUser(_ message: BitchatMessage) -> Bool {
|
|
message.sender == currentNickname || message.sender.hasPrefix(currentNickname + "#")
|
|
}
|
|
|
|
func isMediaMessageFromCurrentUser(_ message: BitchatMessage) -> Bool {
|
|
message.sender == currentNickname || message.senderPeerID == chatViewModel.meshService.myPeerID
|
|
}
|
|
|
|
func senderDisplayName(for peerID: PeerID, fallbackMessages: [BitchatMessage]) -> String? {
|
|
if peerID.isGeoDM || peerID.isGeoChat {
|
|
return chatViewModel.geohashDisplayName(for: peerID)
|
|
}
|
|
if let nickname = chatViewModel.meshService.peerNickname(peerID: peerID) {
|
|
return nickname
|
|
}
|
|
return fallbackMessages.last(where: { $0.senderPeerID == peerID && $0.sender != "system" })?.sender
|
|
}
|
|
|
|
#if os(iOS)
|
|
func processSelectedImage(_ image: UIImage?) {
|
|
chatViewModel.processThenSendImage(image)
|
|
}
|
|
#endif
|
|
|
|
func processSelectedImage(from url: URL?) {
|
|
#if os(macOS)
|
|
chatViewModel.processThenSendImage(from: url)
|
|
#endif
|
|
}
|
|
|
|
func sendVoiceNote(at url: URL) {
|
|
chatViewModel.sendVoiceNote(at: url)
|
|
}
|
|
|
|
func cancelMediaSend(messageID: String) {
|
|
chatViewModel.cancelMediaSend(messageID: messageID)
|
|
}
|
|
|
|
func deleteMediaMessage(messageID: String) {
|
|
chatViewModel.deleteMediaMessage(messageID: messageID)
|
|
}
|
|
|
|
private func bind() {
|
|
chatViewModel.$nickname
|
|
.receive(on: DispatchQueue.main)
|
|
.assign(to: &$currentNickname)
|
|
|
|
chatViewModel.$showAutocomplete
|
|
.receive(on: DispatchQueue.main)
|
|
.assign(to: &$showAutocomplete)
|
|
|
|
chatViewModel.$autocompleteSuggestions
|
|
.receive(on: DispatchQueue.main)
|
|
.assign(to: &$autocompleteSuggestions)
|
|
|
|
chatViewModel.$isBatchingPublic
|
|
.receive(on: DispatchQueue.main)
|
|
.assign(to: &$isBatchingPublic)
|
|
|
|
conversations.$activeChannel
|
|
.receive(on: DispatchQueue.main)
|
|
.sink { [weak self] channel in
|
|
self?.activeChannel = channel
|
|
self?.refreshComputedState()
|
|
}
|
|
.store(in: &cancellables)
|
|
|
|
privateConversationModel.$selectedPeerID
|
|
.receive(on: DispatchQueue.main)
|
|
.sink { [weak self] _ in
|
|
self?.refreshComputedState()
|
|
}
|
|
.store(in: &cancellables)
|
|
}
|
|
|
|
private func refreshComputedState() {
|
|
if let selectedPeerID = privateConversationModel.selectedPeerID {
|
|
canSendMediaInCurrentContext = !(selectedPeerID.isGeoDM || selectedPeerID.isGeoChat)
|
|
return
|
|
}
|
|
|
|
switch activeChannel {
|
|
case .mesh:
|
|
canSendMediaInCurrentContext = true
|
|
case .location:
|
|
canSendMediaInCurrentContext = false
|
|
}
|
|
}
|
|
}
|