mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 08:45:19 +00:00
* Unified notices: merge board pins and location notes into one sheet One pin icon in the header now opens a single Notices sheet with a geo/mesh scope toggle, replacing the separate board, location-notes, and mesh-only note buttons: - geo tab: current geohash's notices — mesh-synced board posts merged and deduped with Nostr kind-1 location notes, with per-item mesh/net source badges. Scope follows the selected location channel, or the device's building geohash when chatting on mesh. - mesh tab: mesh-local board only (fully offline). - One composer: geo posts go to the board and bridge to Nostr (existing bridge), so mesh and internet see the same notice. - Merged delete: tombstoning an own board post now also retracts the bridged Nostr copy via NIP-09 (new createDeleteEvent, bridged event ids tracked in BoardManager); own Nostr-only notes are deletable too. - LocationNotesManager accepts any channel-precision geohash (1-12 chars), not just building-level. BoardView and LocationNotesView are superseded by NoticesView. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Notices round 2: honest composer, friendlier copy, new-pin chat alerts - Urgent + expiry controls now appear on the mesh tab only: the bridged Nostr copy of a geo post carries neither, so relay-side readers would never see them. Geo posts default to non-urgent with 7-day expiry, and the bridged note now gets a NIP-40 expiration tag so honoring relays drop it in step with the board copy. - Geo tab explainer reuses the original location-notes description (keeps its 29 existing translations); mesh tab gets a new plain- language description. - New-pin chat alerts, fully local (no wire traffic): BoardStore fires postArrivals for posts newly accepted from the wire; BoardAlertsModel filters own posts, dedups by postID, and for urgent pins created within the last 30 minutes emits one system line into the matching timeline (geo pin -> that geohash's chat, mesh pin -> mesh chat), collapsing simultaneous arrivals into a count line. - Routine pins light up the header: the pin icon tints orange whenever the current scope has notices at all, and fills (pin.fill) while unseen new pins are waiting; opening the sheet clears them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * i18n: translate the unified-notices strings into all 28 non-English locales Adds the 13 new notices keys (sheet title, geo/mesh tabs, mesh description, source badges, urgent alert lines, button tooltip and accessibility strings) to the string catalog with translations for every locale the app ships. The geo tab already reuses the fully translated location_notes.description; this covers the rest. Insertion preserves the catalog's case-insensitive key order, so the diff is purely additive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Address Codex review: panic-wipe reset, scoped badge clear, geohash-aware dedupe - BoardStore.wipe() now emits didWipe; BoardAlertsModel subscribes and resets, so a panic wipe drops pending urgent lines (which could otherwise re-append pre-wipe content into chat after the collapse flush), unseen badge scopes, and handled-post history. - Opening the notices sheet clears unseen badges only for the scopes it actually shows (mesh + current geo scope); pins for other geohash channels keep their badge until visited. - LocationNotesManager.Note now retains the matched g tag, and the bridged-copy dedupe requires the note's geohash to equal the board post's — a same-text note from a neighboring cell is no longer swallowed as a duplicate. 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>
376 lines
17 KiB
Swift
376 lines
17 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentHeaderView: View {
|
|
@EnvironmentObject private var appChromeModel: AppChromeModel
|
|
@EnvironmentObject private var verificationModel: VerificationModel
|
|
@EnvironmentObject private var locationChannelsModel: LocationChannelsModel
|
|
@EnvironmentObject private var peerListModel: PeerListModel
|
|
@EnvironmentObject private var boardAlertsModel: BoardAlertsModel
|
|
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
|
|
@Environment(\.appTheme) private var theme
|
|
@ThemedPalette private var palette
|
|
|
|
@Binding var showSidebar: Bool
|
|
@Binding var showVerifySheet: Bool
|
|
var isNicknameFieldFocused: FocusState<Bool>.Binding
|
|
|
|
let headerHeight: CGFloat
|
|
let headerPeerIconSize: CGFloat
|
|
let headerPeerCountFontSize: CGFloat
|
|
|
|
/// Courier envelopes this device is carrying for offline third parties.
|
|
@State private var carriedMailCount = 0
|
|
|
|
/// Unified notices sheet (board posts + location notes) for the current
|
|
/// channel context.
|
|
@State private var showNotices = false
|
|
|
|
/// Board posts mirrored from the store so the pin icon can show when the
|
|
/// current scope has notices.
|
|
@State private var boardPosts: [BoardPostPacket] = []
|
|
|
|
var body: some View {
|
|
HStack(spacing: 0) {
|
|
Text(verbatim: "bitchat/")
|
|
.bitchatFont(size: 18, weight: .medium)
|
|
.foregroundColor(palette.primary)
|
|
.onTapGesture(count: 3) {
|
|
appChromeModel.panicClearAllData()
|
|
}
|
|
.onTapGesture(count: 1) {
|
|
appChromeModel.presentAppInfo()
|
|
}
|
|
// This is the only entry point to App Info, but it reads as
|
|
// static text; surface the tap. (The triple-tap panic wipe
|
|
// stays undiscoverable on purpose — it's destructive.)
|
|
.accessibilityAddTraits(.isButton)
|
|
.accessibilityHint(
|
|
String(localized: "content.accessibility.app_info_hint", comment: "Accessibility hint on the bitchat/ logo explaining a tap opens app info")
|
|
)
|
|
.accessibilityAction {
|
|
appChromeModel.presentAppInfo()
|
|
}
|
|
|
|
HStack(spacing: 0) {
|
|
Text(verbatim: "@")
|
|
.bitchatFont(size: 14)
|
|
.foregroundColor(palette.secondary)
|
|
|
|
TextField(
|
|
"content.input.nickname_placeholder",
|
|
text: Binding(
|
|
get: { appChromeModel.nickname },
|
|
set: { appChromeModel.setNickname($0) }
|
|
)
|
|
)
|
|
.textFieldStyle(.plain)
|
|
.bitchatFont(size: 14)
|
|
.frame(maxWidth: 80)
|
|
.foregroundColor(palette.primary)
|
|
.focused(isNicknameFieldFocused)
|
|
.autocorrectionDisabled(true)
|
|
#if os(iOS)
|
|
.textInputAutocapitalization(.never)
|
|
#endif
|
|
.modifier(FocusEffectDisabledModifier())
|
|
.onChange(of: isNicknameFieldFocused.wrappedValue) { isFocused in
|
|
if !isFocused {
|
|
appChromeModel.validateAndSaveNickname()
|
|
}
|
|
}
|
|
.onSubmit {
|
|
appChromeModel.validateAndSaveNickname()
|
|
}
|
|
}
|
|
|
|
Spacer()
|
|
|
|
let countAndColor = channelPeopleCountAndColor()
|
|
let headerCountColor = countAndColor.1
|
|
let headerOtherPeersCount: Int = {
|
|
if case .location = locationChannelsModel.selectedChannel {
|
|
return peerListModel.visibleGeohashPeerCount
|
|
}
|
|
return countAndColor.0
|
|
}()
|
|
|
|
HStack(spacing: 2) {
|
|
if locationChannelsModel.gatewayEnabled {
|
|
Image(systemName: "globe")
|
|
.font(.bitchatSystem(size: 12))
|
|
.foregroundColor(palette.secondary.opacity(0.8))
|
|
.headerTapTarget()
|
|
.accessibilityLabel(
|
|
String(localized: "content.accessibility.gateway_active", defaultValue: "Internet gateway active, sharing your connection with the mesh", comment: "Accessibility label for the internet gateway indicator")
|
|
)
|
|
.help(
|
|
String(localized: "content.header.gateway_active", defaultValue: "Sharing your internet connection with nearby mesh peers", comment: "Tooltip for the internet gateway indicator")
|
|
)
|
|
}
|
|
|
|
if carriedMailCount > 0 {
|
|
Image(systemName: "figure.walk")
|
|
.font(.bitchatSystem(size: 12))
|
|
.foregroundColor(palette.secondary.opacity(0.8))
|
|
.headerTapTarget()
|
|
.accessibilityLabel(
|
|
String(
|
|
format: String(localized: "content.accessibility.carrying_mail", defaultValue: "Carrying %lld sealed messages for friends", comment: "Accessibility label for the courier mail indicator"),
|
|
locale: .current,
|
|
carriedMailCount
|
|
)
|
|
)
|
|
.help(
|
|
String(localized: "content.header.carrying_mail", defaultValue: "Carrying sealed messages for friends to deliver", comment: "Tooltip for the courier mail indicator")
|
|
)
|
|
}
|
|
|
|
if appChromeModel.hasUnreadPrivateMessages {
|
|
Button(action: { appChromeModel.openMostRelevantPrivateChat() }) {
|
|
Image(systemName: "envelope.fill")
|
|
.font(.bitchatSystem(size: 12))
|
|
.foregroundColor(Color.orange)
|
|
.headerTapTarget()
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(
|
|
String(localized: "content.accessibility.open_unread_private_chat", comment: "Accessibility label for the unread private chat button")
|
|
)
|
|
}
|
|
|
|
Button(action: {
|
|
var scopes: Set<String> = [""]
|
|
if let geoScope = noticesGeoScope {
|
|
scopes.insert(geoScope)
|
|
}
|
|
boardAlertsModel.markSeen(forScopes: scopes)
|
|
showNotices = true
|
|
}) {
|
|
// Fill marks unseen new pins; the tint says the current
|
|
// scope has notices at all.
|
|
Image(systemName: unseenNoticesCount > 0 ? "pin.fill" : "pin")
|
|
.font(.bitchatSystem(size: 12))
|
|
.foregroundColor(
|
|
scopeHasNotices || unseenNoticesCount > 0
|
|
? Color.orange.opacity(0.8)
|
|
: palette.secondary.opacity(0.9)
|
|
)
|
|
.headerTapTarget()
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(
|
|
String(localized: "content.accessibility.notices", defaultValue: "Notices", comment: "Accessibility label for the notices button")
|
|
)
|
|
.accessibilityValue(
|
|
unseenNoticesCount > 0
|
|
? String(
|
|
format: String(localized: "content.accessibility.notices_new", defaultValue: "%lld new", comment: "Accessibility value for the notices button when unseen pins arrived"),
|
|
locale: .current,
|
|
unseenNoticesCount
|
|
)
|
|
: ""
|
|
)
|
|
.help(
|
|
String(localized: "content.header.notices", defaultValue: "Notices: pinned posts for this area and the mesh", comment: "Tooltip for the notices button")
|
|
)
|
|
|
|
if case .location(let channel) = locationChannelsModel.selectedChannel {
|
|
Button(action: { locationChannelsModel.toggleBookmark(channel.geohash) }) {
|
|
Image(systemName: locationChannelsModel.isBookmarked(channel.geohash) ? "bookmark.fill" : "bookmark")
|
|
.font(.bitchatSystem(size: 12))
|
|
.headerTapTarget()
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(
|
|
String(
|
|
format: String(localized: "content.accessibility.toggle_bookmark", comment: "Accessibility label for toggling a geohash bookmark"),
|
|
locale: .current,
|
|
channel.geohash
|
|
)
|
|
)
|
|
}
|
|
|
|
Button(action: { appChromeModel.isLocationChannelsSheetPresented = true }) {
|
|
let badgeText: String = {
|
|
switch locationChannelsModel.selectedChannel {
|
|
case .mesh: return "#mesh"
|
|
case .location(let channel): return "#\(channel.geohash)"
|
|
}
|
|
}()
|
|
let badgeColor: Color = {
|
|
switch locationChannelsModel.selectedChannel {
|
|
case .mesh:
|
|
return Color(hue: 0.60, saturation: 0.85, brightness: 0.82)
|
|
case .location:
|
|
return palette.locationAccent
|
|
}
|
|
}()
|
|
|
|
Text(badgeText)
|
|
.bitchatFont(size: 14)
|
|
.foregroundColor(badgeColor)
|
|
.lineLimit(headerLineLimit)
|
|
.fixedSize(horizontal: true, vertical: false)
|
|
.layoutPriority(2)
|
|
.padding(.horizontal, 6)
|
|
.frame(maxHeight: .infinity)
|
|
.contentShape(Rectangle())
|
|
.accessibilityLabel(
|
|
String(localized: "content.accessibility.location_channels", comment: "Accessibility label for the location channels button")
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
Button(action: {
|
|
withAnimation(.easeInOut(duration: TransportConfig.uiAnimationMediumSeconds)) {
|
|
showSidebar.toggle()
|
|
}
|
|
}) {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "person.2.fill")
|
|
.font(.system(size: headerPeerIconSize, weight: .regular))
|
|
Text("\(headerOtherPeersCount)")
|
|
.font(.system(size: headerPeerCountFontSize, weight: .regular, design: theme.bodyFontDesign))
|
|
.accessibilityHidden(true)
|
|
}
|
|
.foregroundColor(headerCountColor)
|
|
.lineLimit(headerLineLimit)
|
|
.fixedSize(horizontal: true, vertical: false)
|
|
.padding(.leading, 6)
|
|
.frame(maxHeight: .infinity)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(
|
|
String(
|
|
format: String(localized: "content.accessibility.people_count", comment: "Accessibility label announcing number of people in header"),
|
|
locale: .current,
|
|
headerOtherPeersCount
|
|
)
|
|
)
|
|
// Connected-vs-nobody is otherwise encoded only in the icon's
|
|
// color; say it.
|
|
.accessibilityValue(
|
|
headerPeersReachable
|
|
? String(localized: "content.accessibility.peers_connected", comment: "Accessibility value when peers are reachable")
|
|
: String(localized: "content.accessibility.peers_none", comment: "Accessibility value when no peers are reachable")
|
|
)
|
|
}
|
|
.layoutPriority(3)
|
|
.sheet(isPresented: $showVerifySheet) {
|
|
VerificationSheetView(isPresented: $showVerifySheet)
|
|
.environmentObject(verificationModel)
|
|
}
|
|
}
|
|
// Fixed height is load-bearing: children fill the bar with
|
|
// .frame(maxHeight: .infinity) tap targets, so an open-ended
|
|
// minHeight lets the header expand to swallow the whole screen.
|
|
// headerHeight is a @ScaledMetric, so it still grows with Dynamic
|
|
// Type.
|
|
.frame(height: headerHeight)
|
|
.padding(.horizontal, 12)
|
|
.onReceive(CourierStore.shared.$carriedCount) { count in
|
|
carriedMailCount = count
|
|
}
|
|
.onReceive(BoardStore.shared.$postsSnapshot) { posts in
|
|
boardPosts = posts
|
|
}
|
|
.sheet(isPresented: $appChromeModel.isLocationChannelsSheetPresented) {
|
|
LocationChannelsSheet(isPresented: $appChromeModel.isLocationChannelsSheetPresented)
|
|
.environmentObject(locationChannelsModel)
|
|
.environmentObject(peerListModel)
|
|
}
|
|
.sheet(isPresented: $showNotices) {
|
|
NoticesView(
|
|
senderNickname: appChromeModel.nickname,
|
|
board: appChromeModel.boardManager,
|
|
initialTab: initialNoticesTab
|
|
)
|
|
.environmentObject(locationChannelsModel)
|
|
}
|
|
.onAppear {
|
|
locationChannelsModel.refreshMeshChannelsIfNeeded()
|
|
}
|
|
.onChange(of: locationChannelsModel.selectedChannel) { _ in
|
|
locationChannelsModel.refreshMeshChannelsIfNeeded()
|
|
}
|
|
.onChange(of: locationChannelsModel.permissionState) { _ in
|
|
locationChannelsModel.refreshMeshChannelsIfNeeded()
|
|
}
|
|
.alert("content.alert.screenshot.title", isPresented: $appChromeModel.showScreenshotPrivacyWarning) {
|
|
Button("common.ok", role: .cancel) {}
|
|
} message: {
|
|
Text("content.alert.screenshot.message")
|
|
}
|
|
.themedChromePanel(edge: .top)
|
|
}
|
|
}
|
|
|
|
private extension View {
|
|
/// Expands a small header icon to a comfortably tappable, full-bar-height
|
|
/// hit area without changing its visual size.
|
|
func headerTapTarget() -> some View {
|
|
frame(minWidth: 30, maxHeight: .infinity)
|
|
.contentShape(Rectangle())
|
|
}
|
|
}
|
|
|
|
private extension ContentHeaderView {
|
|
var headerLineLimit: Int? {
|
|
dynamicTypeSize.isAccessibilitySize ? 2 : 1
|
|
}
|
|
|
|
/// Open the notices sheet on the tab matching the current channel: the
|
|
/// geohash channel's notices, or the mesh-local board in mesh chat.
|
|
var initialNoticesTab: NoticesView.Tab {
|
|
if case .location = locationChannelsModel.selectedChannel {
|
|
return .geo
|
|
}
|
|
return .mesh
|
|
}
|
|
|
|
/// The geo scope the notices sheet would open on: the selected location
|
|
/// channel, or the device's building geohash when chatting on mesh.
|
|
var noticesGeoScope: String? {
|
|
if case .location(let channel) = locationChannelsModel.selectedChannel {
|
|
return channel.geohash
|
|
}
|
|
return locationChannelsModel.currentBuildingGeohash
|
|
}
|
|
|
|
/// Whether either tab of the notices sheet currently has content.
|
|
var scopeHasNotices: Bool {
|
|
boardPosts.contains { $0.geohash.isEmpty || $0.geohash == noticesGeoScope }
|
|
}
|
|
|
|
/// New pins in either visible scope since the sheet was last opened.
|
|
var unseenNoticesCount: Int {
|
|
let meshCount = boardAlertsModel.unseenCount(forGeohash: "")
|
|
let geoCount = noticesGeoScope.map { boardAlertsModel.unseenCount(forGeohash: $0) } ?? 0
|
|
return meshCount + geoCount
|
|
}
|
|
|
|
/// Whether anyone is actually reachable on the current channel — the
|
|
/// state the count icon's color encodes visually.
|
|
var headerPeersReachable: Bool {
|
|
switch locationChannelsModel.selectedChannel {
|
|
case .location:
|
|
return peerListModel.visibleGeohashPeerCount > 0
|
|
case .mesh:
|
|
return peerListModel.connectedMeshPeerCount > 0
|
|
}
|
|
}
|
|
|
|
func channelPeopleCountAndColor() -> (Int, Color) {
|
|
switch locationChannelsModel.selectedChannel {
|
|
case .location:
|
|
let count = peerListModel.visibleGeohashPeerCount
|
|
return (count, count > 0 ? palette.locationAccent : palette.secondary)
|
|
case .mesh:
|
|
let meshBlue = Color(hue: 0.60, saturation: 0.85, brightness: 0.82)
|
|
let color: Color = peerListModel.connectedMeshPeerCount > 0 ? meshBlue : palette.secondary
|
|
return (peerListModel.reachableMeshPeerCount, color)
|
|
}
|
|
}
|
|
}
|