mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-27 16:45:21 +00:00
Empty-mesh liveliness: nearby conversations, echoes, wave, dead drops, radar (#1409)
* Empty-mesh liveliness: nearby conversations, echoes, wave action, dead drops, radar The empty mesh timeline was a dead end: a grey zero and "nobody in range yet". This turns it into a live surface and gives the app pull when the mesh wakes up: - Nearest conversation: background geohash sampling now tracks actual chat messages (not just presence) per regional channel; the empty state surfaces the busiest nearby conversation with a preview, one tap to join (GeohashChatActivityTracker, fed from GeoPresenceTracker). - Echoes: the carried 6h store-and-forward window renders as dimmed "heard here earlier" rows at launch (new Transport collectArchivedPublicMessages -> GossipSyncManager snapshot, decoded with signature-derived nicknames; content-identity dedup guards against re-synced duplicates). - Wave: the "bitchatters nearby" notification gains a "wave" quick action that broadcasts a mesh 👋 straight from the notification, even backgrounded (first UNNotificationCategory in the app). - Dead drops: /drop pins a note to the current building geohash as a kind-1 location note with a 24h NIP-40 expiry; expired notes are now dropped client-side at ingest; the notices sheet shows "fades in Xh"; a "location notes" toggle plus location-permission controls live in app info (also fixes the duplicated Voice section). - Radar: an ambient sonar animation shows the radio scanning, with a privacy-safe daily tally ("N devices passed within range today" via salted per-day hashes) and a "notes left here" hint that opens the notices geo tab. All new user-facing strings ship in all 29 locales. 1403 tests green, including new suites for the activity tracker, sightings tally, and note expiry/drop publishing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Review round: app-info polish, urgent/expiry parity, centered radar, pin fill, Codex P2s - App info: LOCATION header uppercased like sibling sections; location notes and live voice descriptions shortened (29 locales); redundant "location access granted" line removed. - Notices parity: urgent + expiry controls now show on the geo tab too; the bridged Nostr note carries ["t","urgent"] and NIP-40 so relay-side readers see both; urgent parsed back from incoming notes. - Radar moved from the top of the empty state to the center of the chat area, below the help text (empty state fills the visible height). - Header pin fills whenever the scope has notices (was: only unseen), and Nostr-only nearby notes now light it too. - Codex P2 fixes: notification completion deferred until the wave action is handled (background suspension dropped the send); NIP-40 notes now prune on a timer when they expire while displayed; the location-notes kill switch retargets the nearby-notes counter immediately. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Hide macOS segmented picker's built-in label in notices composer (duplicate 'expires in') Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Geo notes: permanent (∞) expiry default, urgent stays mesh-only - Geo expiry picker gains ∞ as the default: a permanent note posts as a pure relay note (no NIP-40 tag, no mesh-board copy — a board copy must fade within days, contradicting the ∞ the user picked). 1/3/7d keep the board + bridged-note path with NIP-40. - The notes manager is now owned by the notices sheet (not the list) so the composer local-echoes ∞ notes into the list; it revives via refresh() after a tab-switch cancel, and its expiry-prune timer survives cancel (weak self, dies with the instance). - Urgent toggle returns to mesh-only per review — notes are ambient; the read-side urgent-tag parse stays so tagged notes still render. - macOS: hide the segmented picker's built-in label (duplicate "expires in"). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Clearing the mesh timeline dismisses echoes for good; tighter divider copy Triple-tap /clear emptied the timeline but the next launch re-seeded "heard here earlier" from the persisted archive. A MeshEchoSettings watermark now records the clear; only messages heard after it come back (the archive itself still carries everything for peers' sync). The echo dedup keys reset with it, and panic wipe drops the watermark. Divider copy tightened to "heard here earlier · last 6h" (29 locales). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Echoes visual polish: tinted history block, radar-captioned tally, ambient footer Device-test feedback on the echoes screen: - Archived echoes now sit on a subtle tinted background (secondary at 8%) in addition to the dim, so "heard here earlier" reads as one distinct block; the divider carries the echo ID prefix to join it. - "N devices passed within range today" moves out of the narration lines to sit centered under the radar as its caption. - When the timeline holds only echoes/system lines, a compact ambient footer (small radar + tally + live hints) renders below the history instead of the whole ambient layer vanishing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Notes strip persists above the mesh chat; leaner empty-state narration - The 📍 "notes left here" line was empty-state-only, so starting a conversation hid it. It is now a tappable strip pinned above the mesh timeline whenever unexpired notes exist at this place (opens the notices geo tab); the nearby-notes counter runs for the whole mesh timeline, not just the empty state. - Empty state narration drops "nobody in range yet..." (the radar and the sightings caption already say it) and the nearby-conversation hint moves below the help line instead of splitting the narration. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Radar means searching: hide the sweep once mesh peers are connected or reachable 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>
This commit is contained in:
co-authored by
jack
Claude Fable 5
parent
ef848857b7
commit
74b8a47d02
@@ -10,6 +10,8 @@ struct AppInfoView: View {
|
||||
var topologyProvider: (@MainActor () -> MeshTopologyDisplayModel)?
|
||||
@State private var showTopology = false
|
||||
@State private var liveVoiceEnabled = PTTSettings.liveVoiceEnabled
|
||||
@State private var locationNotesEnabled = LocationNotesSettings.enabled
|
||||
@ObservedObject private var locationManager = LocationChannelManager.shared
|
||||
|
||||
private var selectedTheme: AppTheme {
|
||||
AppTheme(rawValue: appThemeRawValue) ?? .matrix
|
||||
@@ -88,6 +90,17 @@ struct AppInfoView: View {
|
||||
)
|
||||
}
|
||||
|
||||
enum Location {
|
||||
static let title: LocalizedStringKey = "app_info.location.title"
|
||||
static let notes = AppInfoFeatureInfo(
|
||||
icon: "mappin.and.ellipse",
|
||||
title: "app_info.location.notes.title",
|
||||
description: "app_info.location.notes.description"
|
||||
)
|
||||
static let enable: LocalizedStringKey = "app_info.location.enable"
|
||||
static let openSettings: LocalizedStringKey = "app_info.location.open_settings"
|
||||
}
|
||||
|
||||
enum Network {
|
||||
static let title: LocalizedStringKey = "app_info.network.title"
|
||||
static let topology = AppInfoFeatureInfo(
|
||||
@@ -250,19 +263,24 @@ struct AppInfoView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// Voice
|
||||
// Location (notes / dead drops)
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
SectionHeader(Strings.Voice.title)
|
||||
SectionHeader(Strings.Location.title)
|
||||
|
||||
HStack(spacing: 0) {
|
||||
FeatureRow(info: Strings.Voice.live)
|
||||
Toggle(Strings.Voice.live.title, isOn: $liveVoiceEnabled)
|
||||
FeatureRow(info: Strings.Location.notes)
|
||||
Toggle(Strings.Location.notes.title, isOn: $locationNotesEnabled)
|
||||
.labelsHidden()
|
||||
.tint(palette.accent)
|
||||
.onChange(of: liveVoiceEnabled) { newValue in
|
||||
PTTSettings.liveVoiceEnabled = newValue
|
||||
.onChange(of: locationNotesEnabled) { newValue in
|
||||
LocationNotesSettings.enabled = newValue
|
||||
if newValue {
|
||||
locationManager.enableLocationChannels()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locationPermissionRow
|
||||
}
|
||||
|
||||
// Network diagnostics
|
||||
@@ -340,6 +358,34 @@ struct AppInfoView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppInfoView {
|
||||
/// One status/action line under the notes toggle so the location
|
||||
/// requirement is actionable right here instead of only in the channel
|
||||
/// sheet.
|
||||
@ViewBuilder
|
||||
var locationPermissionRow: some View {
|
||||
if locationNotesEnabled {
|
||||
switch locationManager.permissionState {
|
||||
case .notDetermined:
|
||||
Button(Strings.Location.enable) {
|
||||
locationManager.enableLocationChannels()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.bitchatFont(size: 13)
|
||||
.foregroundColor(palette.accent)
|
||||
case .denied, .restricted:
|
||||
Button(Strings.Location.openSettings, action: SystemSettings.location.open)
|
||||
.buttonStyle(.plain)
|
||||
.bitchatFont(size: 13)
|
||||
.foregroundColor(palette.accent)
|
||||
case .authorized:
|
||||
// Granted needs no status line — the toggle being on says it.
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AppInfoFeatureInfo {
|
||||
let icon: String
|
||||
let title: LocalizedStringKey
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
//
|
||||
// MeshEmptyStateView.swift
|
||||
// bitchat
|
||||
//
|
||||
// The empty mesh timeline, upgraded from a dead end into a live surface:
|
||||
// a sonar shows the radio scanning, the daily sightings tally proves the
|
||||
// spot isn't dead, the liveliest nearby geohash conversation is one tap
|
||||
// away, and notes left at this place surface when there are any.
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MeshEmptyStateView: View {
|
||||
/// Visible chat height to fill; the radar centers in the space left
|
||||
/// below the narration. Zero (previews) keeps a compact layout.
|
||||
var fillHeight: CGFloat = 0
|
||||
/// Ambient-footer mode, appended below archived echoes: skips the
|
||||
/// intro/help narration (the timeline isn't empty) and shrinks the
|
||||
/// radar, keeping the sightings tally and the live hints visible.
|
||||
var compact: Bool = false
|
||||
|
||||
@EnvironmentObject private var locationChannelsModel: LocationChannelsModel
|
||||
@EnvironmentObject private var peerListModel: PeerListModel
|
||||
@ObservedObject private var activityTracker = GeohashChatActivityTracker.shared
|
||||
@ObservedObject private var sightingsTracker = MeshSightingsTracker.shared
|
||||
|
||||
@ThemedPalette private var palette
|
||||
|
||||
/// The activity window is evaluated at render time; without new events
|
||||
/// nothing would trigger a re-render, so a stale "people are talking"
|
||||
/// hint could linger. A slow tick keeps the hints and relative times
|
||||
/// honest.
|
||||
@State private var refreshTick = 0
|
||||
private let refreshTimer = Timer.publish(every: 60, on: .main, in: .common).autoconnect()
|
||||
|
||||
private enum Strings {
|
||||
static let meshIntro = String(localized: "content.empty.mesh_intro", comment: "First line of the empty mesh timeline explaining what the mesh channel is")
|
||||
static let switchHint = String(localized: "content.empty.switch_hint", comment: "Empty timeline hint pointing at the channel switcher and the help screen")
|
||||
static let sightingsOne = String(localized: "content.empty.sightings_one", comment: "Empty mesh timeline stat when exactly one device came within range today")
|
||||
|
||||
static func sightingsMany(_ count: Int) -> String {
|
||||
String(
|
||||
format: String(localized: "content.empty.sightings_many", comment: "Empty mesh timeline stat counting devices that came within range today"),
|
||||
locale: .current,
|
||||
count
|
||||
)
|
||||
}
|
||||
|
||||
static func activityOne(_ geohash: String) -> String {
|
||||
String(
|
||||
format: String(localized: "content.empty.activity_one", comment: "Empty mesh timeline hint when one person is chatting in a nearby geohash channel; placeholder is the geohash"),
|
||||
locale: .current,
|
||||
geohash
|
||||
)
|
||||
}
|
||||
|
||||
static func activityMany(_ geohash: String) -> String {
|
||||
String(
|
||||
format: String(localized: "content.empty.activity_many", comment: "Empty mesh timeline hint when several people are chatting in a nearby geohash channel; placeholder is the geohash"),
|
||||
locale: .current,
|
||||
geohash
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// The radar means "searching for people": once anyone is connected or
|
||||
/// reachable on the mesh, the search is over and the sweep goes away.
|
||||
private var isSearchingForPeers: Bool {
|
||||
peerListModel.connectedMeshPeerCount == 0 && peerListModel.reachableMeshPeerCount == 0
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
if compact {
|
||||
if isSearchingForPeers {
|
||||
radarBlock
|
||||
}
|
||||
if let conversation = nearbyConversation {
|
||||
conversationHint(conversation)
|
||||
}
|
||||
} else {
|
||||
// The radar + tally already say "scanning, nobody yet", so
|
||||
// the narration stays to two lines with the live hint after
|
||||
// them, not wedged in between.
|
||||
narrationLine(Strings.meshIntro)
|
||||
narrationLine(Strings.switchHint)
|
||||
if let conversation = nearbyConversation {
|
||||
conversationHint(conversation)
|
||||
}
|
||||
|
||||
// The radar centers in whatever space is left below the
|
||||
// text — the flexible spacers split it evenly.
|
||||
if isSearchingForPeers {
|
||||
Spacer(minLength: 24)
|
||||
radarBlock
|
||||
Spacer(minLength: 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(minHeight: compact ? 0 : fillHeight, alignment: .top)
|
||||
.onReceive(refreshTimer) { _ in refreshTick += 1 }
|
||||
}
|
||||
|
||||
/// The radar with today's tally as its caption — the stat belongs to
|
||||
/// the scanning visual, not the narration lines.
|
||||
private var radarBlock: some View {
|
||||
VStack(spacing: 4) {
|
||||
MeshRadarView(height: compact ? 44 : 72)
|
||||
if sightingsTracker.todayCount > 0 {
|
||||
Text(verbatim: sightingsText)
|
||||
.bitchatFont(size: 11)
|
||||
.foregroundColor(palette.secondary.opacity(0.8))
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
private extension MeshEmptyStateView {
|
||||
var nearbyConversation: NearbyConversation? {
|
||||
activityTracker.mostActiveConversation(among: locationChannelsModel.availableChannels)
|
||||
}
|
||||
|
||||
var sightingsText: String {
|
||||
sightingsTracker.todayCount == 1
|
||||
? Strings.sightingsOne
|
||||
: Strings.sightingsMany(sightingsTracker.todayCount)
|
||||
}
|
||||
|
||||
func conversationHint(_ conversation: NearbyConversation) -> some View {
|
||||
let headline = conversation.messageCount == 1
|
||||
? Strings.activityOne(conversation.channel.geohash)
|
||||
: Strings.activityMany(conversation.channel.geohash)
|
||||
|
||||
return Button {
|
||||
locationChannelsModel.markTeleported(for: conversation.channel.geohash, false)
|
||||
locationChannelsModel.select(.location(conversation.channel))
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
actionLine("💬 \(headline)")
|
||||
narrationLine(" \(previewText(for: conversation.lastMessage))")
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
func previewText(for message: GeohashChatPreview) -> String {
|
||||
let maxLen = TransportConfig.uiGeoNotifySnippetMaxLen
|
||||
var content = message.content
|
||||
if content.count > maxLen {
|
||||
content = String(content.prefix(maxLen)) + "…"
|
||||
}
|
||||
let formatter = RelativeDateTimeFormatter()
|
||||
formatter.unitsStyle = .abbreviated
|
||||
let ago = formatter.localizedString(for: message.timestamp, relativeTo: Date())
|
||||
return "<\(message.senderName)> \(content) · \(ago)"
|
||||
}
|
||||
|
||||
func narrationLine(_ text: String) -> some View {
|
||||
emptyStateLine(text, color: palette.secondary.opacity(0.9))
|
||||
}
|
||||
|
||||
/// Tappable lines render in the primary color so they read as actions
|
||||
/// amid the grey narration.
|
||||
func actionLine(_ text: String) -> some View {
|
||||
emptyStateLine(text, color: palette.primary)
|
||||
}
|
||||
|
||||
func emptyStateLine(_ text: String, color: Color) -> some View {
|
||||
// Non-breaking space before the closing asterisk so a tight wrap
|
||||
// can't orphan a lone "*" onto its own line.
|
||||
Text(verbatim: "* \(text)\u{00A0}*")
|
||||
.bitchatFont(size: 13)
|
||||
.foregroundColor(color)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// MeshRadarView.swift
|
||||
// bitchat
|
||||
//
|
||||
// Ambient sonar shown on the empty mesh timeline: expanding rings around a
|
||||
// center dot make it visible that the radio is broadcasting and scanning
|
||||
// even when nobody is in range. Purely decorative — hidden from
|
||||
// accessibility, static under Reduce Motion.
|
||||
// This is free and unencumbered software released into the public domain.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MeshRadarView: View {
|
||||
/// Full size on the empty timeline; the ambient footer under archived
|
||||
/// echoes uses a smaller one.
|
||||
var height: CGFloat = 72
|
||||
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
@ThemedPalette private var palette
|
||||
|
||||
private let ringCount = 3
|
||||
private let period: TimeInterval = 3.0
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if reduceMotion {
|
||||
radar(at: 0.35)
|
||||
} else {
|
||||
TimelineView(.animation(minimumInterval: 1.0 / 20.0)) { context in
|
||||
radar(at: context.date.timeIntervalSinceReferenceDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: height)
|
||||
.frame(maxWidth: .infinity)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
|
||||
private func radar(at time: TimeInterval) -> some View {
|
||||
Canvas { context, size in
|
||||
let center = CGPoint(x: size.width / 2, y: size.height / 2)
|
||||
let maxRadius = min(size.width, size.height) / 2 - 2
|
||||
|
||||
for ring in 0..<ringCount {
|
||||
let phase = (time / period + Double(ring) / Double(ringCount))
|
||||
.truncatingRemainder(dividingBy: 1)
|
||||
let radius = maxRadius * phase
|
||||
guard radius > 1 else { continue }
|
||||
let alpha = 0.45 * (1 - phase)
|
||||
let rect = CGRect(
|
||||
x: center.x - radius,
|
||||
y: center.y - radius,
|
||||
width: radius * 2,
|
||||
height: radius * 2
|
||||
)
|
||||
context.stroke(
|
||||
Path(ellipseIn: rect),
|
||||
with: .color(palette.primary.opacity(alpha)),
|
||||
lineWidth: 1
|
||||
)
|
||||
}
|
||||
|
||||
let dot = CGRect(x: center.x - 2, y: center.y - 2, width: 4, height: 4)
|
||||
context.fill(Path(ellipseIn: dot), with: .color(palette.primary.opacity(0.9)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,12 +23,15 @@ struct ContentHeaderView: View {
|
||||
|
||||
/// 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] = []
|
||||
|
||||
/// Nostr-only location notes at this place (live while the empty mesh
|
||||
/// timeline is showing) — they should light the pin too.
|
||||
@ObservedObject private var nearbyNotes = NearbyNotesCounter.shared
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
Text(verbatim: "bitchat/")
|
||||
@@ -157,11 +160,11 @@ struct ContentHeaderView: View {
|
||||
scopes.insert(geoScope)
|
||||
}
|
||||
boardAlertsModel.markSeen(forScopes: scopes)
|
||||
showNotices = true
|
||||
appChromeModel.presentNotices()
|
||||
}) {
|
||||
// Fill marks unseen new pins; the tint says the current
|
||||
// scope has notices at all.
|
||||
Image(systemName: unseenNoticesCount > 0 ? "pin.fill" : "pin")
|
||||
// Filled whenever the current scope has notices at all
|
||||
// (matching the orange tint); hollow means nothing here.
|
||||
Image(systemName: scopeHasNotices || unseenNoticesCount > 0 ? "pin.fill" : "pin")
|
||||
.font(.bitchatSystem(size: 12))
|
||||
.foregroundColor(
|
||||
scopeHasNotices || unseenNoticesCount > 0
|
||||
@@ -293,7 +296,10 @@ struct ContentHeaderView: View {
|
||||
.environmentObject(locationChannelsModel)
|
||||
.environmentObject(peerListModel)
|
||||
}
|
||||
.sheet(isPresented: $showNotices) {
|
||||
.sheet(
|
||||
isPresented: $appChromeModel.isNoticesSheetPresented,
|
||||
onDismiss: { appChromeModel.noticesSheetPrefersGeoTab = false }
|
||||
) {
|
||||
NoticesView(
|
||||
senderNickname: appChromeModel.nickname,
|
||||
board: appChromeModel.boardManager,
|
||||
@@ -334,8 +340,12 @@ private extension ContentHeaderView {
|
||||
}
|
||||
|
||||
/// Open the notices sheet on the tab matching the current channel: the
|
||||
/// geohash channel's notices, or the mesh-local board in mesh chat.
|
||||
/// geohash channel's notices, or the mesh-local board in mesh chat. An
|
||||
/// explicit geo-tab request (the "notes left here" hint) wins.
|
||||
var initialNoticesTab: NoticesView.Tab {
|
||||
if appChromeModel.noticesSheetPrefersGeoTab {
|
||||
return .geo
|
||||
}
|
||||
if case .location = locationChannelsModel.selectedChannel {
|
||||
return .geo
|
||||
}
|
||||
@@ -351,9 +361,12 @@ private extension ContentHeaderView {
|
||||
return locationChannelsModel.currentBuildingGeohash
|
||||
}
|
||||
|
||||
/// Whether either tab of the notices sheet currently has content.
|
||||
/// Whether either tab of the notices sheet currently has content: board
|
||||
/// posts in scope, plus Nostr-only location notes when the nearby-notes
|
||||
/// counter happens to be live (it runs with the empty mesh timeline).
|
||||
var scopeHasNotices: Bool {
|
||||
boardPosts.contains { $0.geohash.isEmpty || $0.geohash == noticesGeoScope }
|
||||
|| nearbyNotes.noteCount > 0
|
||||
}
|
||||
|
||||
/// New pins in either visible scope since the sheet was last opened.
|
||||
|
||||
@@ -19,6 +19,8 @@ struct MessageListView: View {
|
||||
@EnvironmentObject private var privateConversationModel: PrivateConversationModel
|
||||
@EnvironmentObject private var conversationUIModel: ConversationUIModel
|
||||
@EnvironmentObject private var locationChannelsModel: LocationChannelsModel
|
||||
@EnvironmentObject private var appChromeModel: AppChromeModel
|
||||
@ObservedObject private var nearbyNotes = NearbyNotesCounter.shared
|
||||
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@Environment(\.appTheme) private var theme
|
||||
@@ -45,6 +47,9 @@ struct MessageListView: View {
|
||||
/// switches swap the timeline wholesale, so a count delta is only a
|
||||
/// "new messages" signal while the context is unchanged.
|
||||
@State private var unseenBaselineKey = ""
|
||||
/// Whether this instance holds the nearby-notes counter active (mesh
|
||||
/// public timeline only); balanced against activate/deactivate.
|
||||
@State private var holdsNotesCounter = false
|
||||
|
||||
@ThemedPalette private var palette
|
||||
|
||||
@@ -72,10 +77,19 @@ struct MessageListView: View {
|
||||
return MessageDisplayItem(id: "\(contextKey)|\(message.id)", message: message)
|
||||
}
|
||||
|
||||
VStack(spacing: 0) {
|
||||
// Notes pinned to this place stay visible while chatting — a
|
||||
// conversation starting must not hide what's left here.
|
||||
if privatePeer == nil,
|
||||
case .mesh = locationChannelsModel.selectedChannel,
|
||||
nearbyNotes.noteCount > 0 {
|
||||
notesHereStrip
|
||||
}
|
||||
GeometryReader { geometry in
|
||||
ScrollViewReader { proxy in
|
||||
ScrollView {
|
||||
if messageItems.isEmpty && privatePeer == nil {
|
||||
publicEmptyState
|
||||
publicEmptyState(fillHeight: geometry.size.height)
|
||||
}
|
||||
LazyVStack(alignment: .leading, spacing: 0) {
|
||||
ForEach(messageItems) { item in
|
||||
@@ -150,10 +164,23 @@ struct MessageListView: View {
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 1)
|
||||
// Archived echoes read as one tinted block, not
|
||||
// just faded rows.
|
||||
.background(message.isArchivedEcho ? palette.secondary.opacity(0.08) : Color.clear)
|
||||
}
|
||||
}
|
||||
.transaction { tx in if conversationUIModel.isBatchingPublic { tx.disablesAnimations = true } }
|
||||
.padding(.vertical, 2)
|
||||
|
||||
// Only carried history on screen: the ambient layer (radar,
|
||||
// sightings, live hints) stays visible below it instead of
|
||||
// vanishing the moment echoes exist.
|
||||
if privatePeer == nil, showsAmbientFooter(messageItems: messageItems) {
|
||||
MeshEmptyStateView(compact: true)
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.top, 20)
|
||||
.padding(.bottom, 8)
|
||||
}
|
||||
}
|
||||
.overlay(alignment: .bottomTrailing) {
|
||||
if !isAtBottom && !messageItems.isEmpty {
|
||||
@@ -246,6 +273,12 @@ struct MessageListView: View {
|
||||
scrollThrottleTimer?.invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear { updateNotesCounterHold() }
|
||||
.onDisappear { releaseNotesCounterHold() }
|
||||
.onChange(of: locationChannelsModel.selectedChannel) { _ in updateNotesCounterHold() }
|
||||
.onChange(of: privatePeer) { _ in updateNotesCounterHold() }
|
||||
.environment(\.openURL, OpenURLAction { url in
|
||||
// Intercept custom cashu: links created in attributed text
|
||||
if let scheme = url.scheme?.lowercased(), scheme == "cashu" || scheme == "lightning" {
|
||||
@@ -270,16 +303,75 @@ private extension MessageListView {
|
||||
return locationChannelsModel.selectedChannel.contextKey
|
||||
}
|
||||
|
||||
/// Tappable strip above the mesh timeline while notes are pinned at this
|
||||
/// place: opens the notices sheet on the geo tab.
|
||||
var notesHereStrip: some View {
|
||||
let text: String = nearbyNotes.noteCount == 1
|
||||
? String(localized: "content.empty.notes_one", comment: "Hint when exactly one note was left at this place")
|
||||
: String(
|
||||
format: String(localized: "content.empty.notes_many", comment: "Hint counting notes left at this place"),
|
||||
locale: .current,
|
||||
nearbyNotes.noteCount
|
||||
)
|
||||
|
||||
return Button {
|
||||
appChromeModel.presentNotices(geoTab: true)
|
||||
} label: {
|
||||
HStack(spacing: 6) {
|
||||
Text(verbatim: "📍 \(text)")
|
||||
.bitchatFont(size: 12)
|
||||
.foregroundColor(palette.primary)
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.bitchatSystem(size: 10))
|
||||
.foregroundColor(palette.secondary)
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 7)
|
||||
.background(palette.secondary.opacity(0.08))
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
/// The nearby-notes counter runs whenever the mesh public timeline is
|
||||
/// showing — the strip needs a live count before it can decide to exist.
|
||||
func updateNotesCounterHold() {
|
||||
let shouldHold = privatePeer == nil && locationChannelsModel.selectedChannel.isMesh
|
||||
guard shouldHold != holdsNotesCounter else { return }
|
||||
holdsNotesCounter = shouldHold
|
||||
if shouldHold {
|
||||
NearbyNotesCounter.shared.activate()
|
||||
} else {
|
||||
NearbyNotesCounter.shared.deactivate()
|
||||
}
|
||||
}
|
||||
|
||||
func releaseNotesCounterHold() {
|
||||
guard holdsNotesCounter else { return }
|
||||
holdsNotesCounter = false
|
||||
NearbyNotesCounter.shared.deactivate()
|
||||
}
|
||||
|
||||
/// True when the mesh timeline holds nothing but archived echoes and
|
||||
/// system lines — no live conversation yet, so the ambient layer still
|
||||
/// applies.
|
||||
private func showsAmbientFooter(messageItems: [MessageDisplayItem]) -> Bool {
|
||||
guard case .mesh = locationChannelsModel.selectedChannel,
|
||||
!messageItems.isEmpty else { return false }
|
||||
return messageItems.allSatisfy { $0.message.isArchivedEcho || $0.message.sender == "system" }
|
||||
}
|
||||
|
||||
/// Terminal-styled narration for an empty public timeline: says which
|
||||
/// channel this is, that the app is waiting for peers, and where to go
|
||||
/// next. Rendered inside the ScrollView; disappears with the first row.
|
||||
var publicEmptyState: some View {
|
||||
/// The mesh case fills the visible chat height so its radar can center
|
||||
/// in the space below the text.
|
||||
func publicEmptyState(fillHeight: CGFloat) -> some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
switch locationChannelsModel.selectedChannel {
|
||||
case .mesh:
|
||||
emptyStateLine(String(localized: "content.empty.mesh_intro", comment: "First line of the empty mesh timeline explaining what the mesh channel is"))
|
||||
emptyStateLine(String(localized: "content.empty.mesh_waiting", comment: "Second line of the empty mesh timeline saying no peers are in range yet"))
|
||||
emptyStateLine(String(localized: "content.empty.switch_hint", comment: "Empty timeline hint pointing at the channel switcher and the help screen"))
|
||||
MeshEmptyStateView(fillHeight: max(0, fillHeight - 24))
|
||||
case .location(let channel):
|
||||
emptyStateLine(
|
||||
String(
|
||||
@@ -410,6 +502,9 @@ private extension MessageListView {
|
||||
TextMessageView(message: message)
|
||||
}
|
||||
}
|
||||
// Archived echoes ("heard here earlier") render dimmed: real history,
|
||||
// visually distinct from the live conversation.
|
||||
.opacity(message.isArchivedEcho ? 0.55 : 1)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
+118
-31
@@ -31,10 +31,18 @@ struct NoticesView: View {
|
||||
@State private var tab: Tab
|
||||
@State private var draft: String = ""
|
||||
@State private var urgent = false
|
||||
@State private var expiryDays = 7
|
||||
/// Days until the notice fades; `permanentExpiry` (geo default) means no
|
||||
/// NIP-40 tag — the note stays until its relay drops it.
|
||||
@State private var expiryDays: Int
|
||||
|
||||
/// Sentinel picker tag for the ∞ option (geo tab only).
|
||||
private static let permanentExpiry = 0
|
||||
|
||||
/// Injected notes manager for tests; live use derives one per geohash.
|
||||
private let notesManager: LocationNotesManager?
|
||||
/// Live manager owned by the sheet so the composer can post pure Nostr
|
||||
/// notes (∞ expiry has no mesh-board copy) and the list can render them.
|
||||
@State private var liveGeoManager: LocationNotesManager?
|
||||
|
||||
init(
|
||||
senderNickname: String,
|
||||
@@ -46,6 +54,27 @@ struct NoticesView: View {
|
||||
self.board = board
|
||||
self.notesManager = notesManager
|
||||
_tab = State(initialValue: initialTab)
|
||||
_expiryDays = State(initialValue: initialTab == .geo ? Self.permanentExpiry : 7)
|
||||
}
|
||||
|
||||
private var activeNotesManager: LocationNotesManager? {
|
||||
notesManager ?? liveGeoManager
|
||||
}
|
||||
|
||||
/// Creates (or retargets/revives) the sheet-owned notes manager for the
|
||||
/// current geo scope.
|
||||
private func ensureGeoNotesManager() {
|
||||
guard notesManager == nil, tab == .geo, let geohash = geoGeohash else { return }
|
||||
if let manager = liveGeoManager {
|
||||
if manager.geohash != geohash.lowercased() {
|
||||
manager.setGeohash(geohash)
|
||||
} else if manager.state == .idle {
|
||||
// Cancelled on a tab switch; returning re-subscribes.
|
||||
manager.refresh()
|
||||
}
|
||||
} else {
|
||||
liveGeoManager = LocationNotesManager(geohash: geohash)
|
||||
}
|
||||
}
|
||||
|
||||
private var maxDraftLines: Int { dynamicTypeSize.isAccessibilitySize ? 5 : 3 }
|
||||
@@ -90,6 +119,7 @@ struct NoticesView: View {
|
||||
static let send = String(localized: "board.accessibility.post", defaultValue: "Post notice", comment: "Accessibility label for the board post button")
|
||||
static let deleteAction = String(localized: "board.action.delete", defaultValue: "delete", comment: "Delete action for own board posts")
|
||||
static let expiryLabel = String(localized: "board.compose.expiry", defaultValue: "expires in", comment: "Label for the board post expiry picker")
|
||||
static let permanentOption = String(localized: "notices.expiry.permanent", defaultValue: "permanent", comment: "Accessibility label for the ∞ (never expires) option in the geo notes expiry picker")
|
||||
static let closeHint = String(localized: "notices.accessibility.close", defaultValue: "Close notices", comment: "Accessibility label for the notices close button")
|
||||
static let meshSource = String(localized: "notices.source.mesh", defaultValue: "mesh", comment: "Source badge for notices carried by the mesh")
|
||||
static let nostrSource = String(localized: "notices.source.nostr", defaultValue: "net", comment: "Source badge for notices seen on internet relays")
|
||||
@@ -109,6 +139,16 @@ struct NoticesView: View {
|
||||
)
|
||||
}
|
||||
|
||||
static func fades(_ expiresAt: Date) -> String {
|
||||
let formatter = RelativeDateTimeFormatter()
|
||||
formatter.unitsStyle = .abbreviated
|
||||
return String(
|
||||
format: String(localized: "notices.fades", defaultValue: "fades %@", comment: "Shown on notices with an expiry; placeholder is a localized relative time like 'in 23h'"),
|
||||
locale: .current,
|
||||
formatter.localizedString(for: expiresAt, relativeTo: Date())
|
||||
)
|
||||
}
|
||||
|
||||
static func rowAccessibilityLabel(author: String, content: String, urgent: Bool) -> String {
|
||||
let base = String(
|
||||
format: String(localized: "board.accessibility.post_row", defaultValue: "Notice from %@: %@", comment: "Accessibility label for a board post row"),
|
||||
@@ -132,18 +172,29 @@ struct NoticesView: View {
|
||||
.frame(minWidth: 420, idealWidth: 440, minHeight: 620, idealHeight: 680)
|
||||
#endif
|
||||
.themedSheetBackground()
|
||||
.onAppear { beginGeoLocationIfNeeded() }
|
||||
.onAppear {
|
||||
beginGeoLocationIfNeeded()
|
||||
ensureGeoNotesManager()
|
||||
}
|
||||
.onChange(of: tab) { newTab in
|
||||
if newTab == .geo {
|
||||
beginGeoLocationIfNeeded()
|
||||
ensureGeoNotesManager()
|
||||
} else {
|
||||
locationChannelsModel.endLiveRefresh()
|
||||
}
|
||||
// Each tab keeps its natural default: geo notes stay until
|
||||
// deleted (∞), mesh board posts fade within a week.
|
||||
expiryDays = newTab == .geo ? Self.permanentExpiry : 7
|
||||
urgent = false
|
||||
}
|
||||
// Catches permission granted from the geo tab's enable button.
|
||||
.onChange(of: locationChannelsModel.permissionState) { _ in
|
||||
beginGeoLocationIfNeeded()
|
||||
}
|
||||
.onChange(of: geoGeohash) { _ in
|
||||
ensureGeoNotesManager()
|
||||
}
|
||||
.onDisappear { locationChannelsModel.endLiveRefresh() }
|
||||
}
|
||||
|
||||
@@ -207,7 +258,14 @@ struct NoticesView: View {
|
||||
)
|
||||
case .geo:
|
||||
if let geohash = geoGeohash {
|
||||
GeoNoticesList(geohash: geohash, board: board, manager: notesManager)
|
||||
if let manager = activeNotesManager {
|
||||
GeoNoticesList(geohash: geohash, board: board, manager: manager)
|
||||
} else {
|
||||
// Manager is created on appear; visible for one frame.
|
||||
Color.clear
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.onAppear { ensureGeoNotesManager() }
|
||||
}
|
||||
} else {
|
||||
locationUnavailableSection
|
||||
}
|
||||
@@ -252,11 +310,10 @@ struct NoticesView: View {
|
||||
.disabled(!sendEnabled)
|
||||
.accessibilityLabel(Strings.send)
|
||||
}
|
||||
// Urgency and expiry only travel with the mesh copy — the bridged
|
||||
// Nostr note carries neither, so relay-side readers would never
|
||||
// see them. Offer the controls only where they fully apply.
|
||||
if tab == .mesh {
|
||||
HStack(spacing: 12) {
|
||||
// Both tabs pick an expiry (geo notes may be ∞); urgency is a
|
||||
// mesh-board concept — notes are ambient by nature.
|
||||
HStack(spacing: 12) {
|
||||
if tab == .mesh {
|
||||
Toggle(isOn: $urgent) {
|
||||
Text(Strings.urgentToggle)
|
||||
.bitchatFont(size: 12)
|
||||
@@ -265,19 +322,30 @@ struct NoticesView: View {
|
||||
.toggleStyle(.switch)
|
||||
.fixedSize()
|
||||
.accessibilityLabel(Strings.urgentToggle)
|
||||
Spacer()
|
||||
Text(Strings.expiryLabel)
|
||||
.bitchatFont(size: 12)
|
||||
.foregroundColor(palette.secondary)
|
||||
Picker(Strings.expiryLabel, selection: $expiryDays) {
|
||||
ForEach([1, 3, 7], id: \.self) { days in
|
||||
Text(Strings.expiryDaysOption(days)).tag(days)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.fixedSize()
|
||||
.accessibilityLabel(Strings.expiryLabel)
|
||||
}
|
||||
Spacer()
|
||||
Text(Strings.expiryLabel)
|
||||
.bitchatFont(size: 12)
|
||||
.foregroundColor(palette.secondary)
|
||||
Picker(Strings.expiryLabel, selection: $expiryDays) {
|
||||
// Mesh board posts must fade (the wire caps their
|
||||
// lifetime); only relay-backed geo notes can be ∞.
|
||||
if tab == .geo {
|
||||
Text(verbatim: "∞")
|
||||
.accessibilityLabel(Strings.permanentOption)
|
||||
.tag(Self.permanentExpiry)
|
||||
}
|
||||
ForEach([1, 3, 7], id: \.self) { days in
|
||||
Text(Strings.expiryDaysOption(days)).tag(days)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
// macOS segmented pickers render their own label; the themed
|
||||
// Text alongside already carries it (and accessibility keeps
|
||||
// the explicit label below).
|
||||
.labelsHidden()
|
||||
.fixedSize()
|
||||
.accessibilityLabel(Strings.expiryLabel)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
@@ -293,14 +361,27 @@ struct NoticesView: View {
|
||||
|
||||
private func send() {
|
||||
guard let geohash = activeGeohash, let content = draft.trimmedOrNilIfEmpty else { return }
|
||||
// Geo posts go to the board and are bridged to Nostr by BoardManager,
|
||||
// so mesh and internet see the same notice. They always use the
|
||||
// defaults: non-urgent, 7-day expiry (NIP-40 on the bridged copy).
|
||||
|
||||
// ∞ (geo default): a pure relay note with no NIP-40 tag. It skips
|
||||
// the mesh board deliberately — a board copy must fade within days,
|
||||
// which would contradict the permanence the user just picked.
|
||||
if tab == .geo, expiryDays == Self.permanentExpiry {
|
||||
guard let manager = activeNotesManager else { return }
|
||||
manager.send(content: content, nickname: senderNickname, expiresAt: nil)
|
||||
draft = ""
|
||||
urgent = false
|
||||
return
|
||||
}
|
||||
|
||||
// Expiring posts go to the board and are bridged to Nostr by
|
||||
// BoardManager, so mesh and internet see the same notice with the
|
||||
// chosen expiry (expiresAt on mesh, NIP-40 on the bridged note).
|
||||
// Urgency is mesh-only.
|
||||
let sent = board.createPost(
|
||||
content: content,
|
||||
geohash: geohash,
|
||||
urgent: tab == .mesh && urgent,
|
||||
expiryDays: tab == .mesh ? expiryDays : 7,
|
||||
expiryDays: expiryDays,
|
||||
nickname: senderNickname
|
||||
)
|
||||
if sent {
|
||||
@@ -310,18 +391,19 @@ struct NoticesView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The geo tab's list: owns the Nostr notes subscription for the scope
|
||||
/// geohash and merges it with the board posts for the same geohash.
|
||||
/// The geo tab's list: renders the sheet-owned Nostr notes subscription
|
||||
/// merged with the board posts for the same geohash. The manager lives on
|
||||
/// `NoticesView` so the composer can post through the same instance (∞
|
||||
/// notes local-echo into this list).
|
||||
private struct GeoNoticesList: View {
|
||||
let geohash: String
|
||||
@ObservedObject var board: BoardManager
|
||||
@StateObject private var notesManager: LocationNotesManager
|
||||
@ObservedObject var notesManager: LocationNotesManager
|
||||
|
||||
init(geohash: String, board: BoardManager, manager: LocationNotesManager? = nil) {
|
||||
let gh = geohash.lowercased()
|
||||
self.geohash = gh
|
||||
init(geohash: String, board: BoardManager, manager: LocationNotesManager) {
|
||||
self.geohash = geohash.lowercased()
|
||||
self.board = board
|
||||
_notesManager = StateObject(wrappedValue: manager ?? LocationNotesManager(geohash: gh))
|
||||
self.notesManager = manager
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -475,6 +557,11 @@ private struct NoticesList: View {
|
||||
Text(Self.timestampText(for: item.createdAt))
|
||||
.bitchatFont(size: 11)
|
||||
.foregroundColor(palette.secondary)
|
||||
if let expiresAt = item.expiresAt, expiresAt > Date() {
|
||||
Text(Strings.fades(expiresAt))
|
||||
.bitchatFont(size: 11)
|
||||
.foregroundColor(palette.secondary.opacity(0.8))
|
||||
}
|
||||
Spacer()
|
||||
if showsSource {
|
||||
sourceBadge(item)
|
||||
|
||||
Reference in New Issue
Block a user