mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22: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>
216 lines
7.0 KiB
Swift
216 lines
7.0 KiB
Swift
//
|
|
// BoardAlertsModelTests.swift
|
|
// bitchatTests
|
|
//
|
|
// This is free and unencumbered software released into the public domain.
|
|
// For more information, see <https://unlicense.org>
|
|
//
|
|
|
|
import Combine
|
|
import Foundation
|
|
import Testing
|
|
@testable import bitchat
|
|
|
|
@MainActor
|
|
struct BoardAlertsModelTests {
|
|
|
|
private let baseDate = Date(timeIntervalSince1970: 1_700_000_000)
|
|
private var baseMs: UInt64 { UInt64(baseDate.timeIntervalSince1970 * 1000) }
|
|
private let ownKey = Data(repeating: 7, count: 32)
|
|
|
|
private final class Harness {
|
|
var lines: [(content: String, geohash: String)] = []
|
|
var pendingFlushes: [@MainActor () -> Void] = []
|
|
|
|
@MainActor
|
|
func flushAll() {
|
|
let flushes = pendingFlushes
|
|
pendingFlushes = []
|
|
for flush in flushes { flush() }
|
|
}
|
|
}
|
|
|
|
private func makeModel(harness: Harness, now: Date? = nil) -> BoardAlertsModel {
|
|
let fixedNow = now ?? baseDate
|
|
return BoardAlertsModel(
|
|
arrivals: Empty(completeImmediately: false).eraseToAnyPublisher(),
|
|
dependencies: BoardAlertsModel.Dependencies(
|
|
isOwnPost: { [ownKey] in $0.authorSigningKey == ownKey },
|
|
emitSystemLine: { content, geohash in
|
|
harness.lines.append((content, geohash))
|
|
},
|
|
now: { fixedNow },
|
|
scheduleFlush: { flush in
|
|
harness.pendingFlushes.append(flush)
|
|
}
|
|
)
|
|
)
|
|
}
|
|
|
|
private func makePost(
|
|
content: String = "hello",
|
|
geohash: String = "9q8yy",
|
|
nickname: String = "alice",
|
|
createdAt: UInt64? = nil,
|
|
urgent: Bool = false,
|
|
authorKey: Data = Data(repeating: 1, count: 32),
|
|
postID: Data? = nil
|
|
) -> BoardPostPacket {
|
|
BoardPostPacket(
|
|
postID: postID ?? Data((0..<16).map { _ in UInt8.random(in: 0...255) }),
|
|
geohash: geohash,
|
|
content: content,
|
|
authorSigningKey: authorKey,
|
|
authorNickname: nickname,
|
|
createdAt: createdAt ?? baseMs,
|
|
expiresAt: (createdAt ?? baseMs) + 24 * 60 * 60 * 1000,
|
|
flags: urgent ? BoardPostPacket.urgentFlag : 0,
|
|
signature: Data(repeating: 2, count: 64)
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func ownPosts_neverBadgeOrAlert() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(urgent: true, authorKey: ownKey))
|
|
harness.flushAll()
|
|
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 0)
|
|
#expect(harness.lines.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func routinePost_badgesWithoutChatLine() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(geohash: ""))
|
|
harness.flushAll()
|
|
|
|
#expect(model.unseenCount(forGeohash: "") == 1)
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 0)
|
|
#expect(harness.lines.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func urgentRecentPost_emitsLineInMatchingScope() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(content: "road closed", geohash: "9q8yy", urgent: true))
|
|
#expect(harness.lines.isEmpty)
|
|
harness.flushAll()
|
|
|
|
#expect(harness.lines.count == 1)
|
|
#expect(harness.lines[0].geohash == "9q8yy")
|
|
#expect(harness.lines[0].content.contains("road closed"))
|
|
#expect(harness.lines[0].content.contains("@alice"))
|
|
}
|
|
|
|
@Test
|
|
func urgentBackfilledPost_badgesOnly() {
|
|
let harness = Harness()
|
|
let arrivalTime = baseDate.addingTimeInterval(BoardAlertsModel.inlineRecencyWindow + 120)
|
|
let model = makeModel(harness: harness, now: arrivalTime)
|
|
|
|
model.handleArrival(makePost(createdAt: baseMs, urgent: true))
|
|
harness.flushAll()
|
|
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 1)
|
|
#expect(harness.lines.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func simultaneousUrgentPosts_collapseIntoOneLine() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(content: "one", urgent: true))
|
|
model.handleArrival(makePost(content: "two", urgent: true))
|
|
model.handleArrival(makePost(content: "three", urgent: true))
|
|
harness.flushAll()
|
|
|
|
#expect(harness.lines.count == 1)
|
|
#expect(harness.lines[0].content.contains("3"))
|
|
#expect(harness.pendingFlushes.isEmpty)
|
|
}
|
|
|
|
@Test
|
|
func urgentPostsInDifferentScopes_alertEachScope() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(content: "geo pin", geohash: "9q8yy", urgent: true))
|
|
model.handleArrival(makePost(content: "mesh pin", geohash: "", urgent: true))
|
|
harness.flushAll()
|
|
|
|
#expect(harness.lines.count == 2)
|
|
#expect(Set(harness.lines.map(\.geohash)) == ["9q8yy", ""])
|
|
}
|
|
|
|
@Test
|
|
func duplicateArrival_isHandledOnce() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
let id = Data(repeating: 3, count: 16)
|
|
|
|
model.handleArrival(makePost(urgent: true, postID: id))
|
|
model.handleArrival(makePost(urgent: true, postID: id))
|
|
harness.flushAll()
|
|
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 1)
|
|
#expect(harness.lines.count == 1)
|
|
#expect(!harness.lines[0].content.contains("2"))
|
|
}
|
|
|
|
@Test
|
|
func markSeen_clearsOnlyVisibleScopes() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(geohash: ""))
|
|
model.handleArrival(makePost(geohash: "9q8yy"))
|
|
model.handleArrival(makePost(geohash: "u4pruyd"))
|
|
|
|
// Opening the sheet on mesh + 9q8yy must not eat the badge for the
|
|
// never-shown u4pruyd channel.
|
|
model.markSeen(forScopes: ["", "9q8yy"])
|
|
|
|
#expect(model.unseenCount(forGeohash: "") == 0)
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 0)
|
|
#expect(model.unseenCount(forGeohash: "u4pruyd") == 1)
|
|
}
|
|
|
|
@Test
|
|
func reset_dropsPendingUrgentLinesAndBadges() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
|
|
model.handleArrival(makePost(content: "pre-wipe secret", urgent: true))
|
|
#expect(harness.pendingFlushes.count == 1)
|
|
|
|
// Panic wipe lands before the collapse flush fires.
|
|
model.reset()
|
|
harness.flushAll()
|
|
|
|
#expect(harness.lines.isEmpty)
|
|
#expect(model.unseenCount(forGeohash: "9q8yy") == 0)
|
|
}
|
|
|
|
@Test
|
|
func longUrgentContent_isTruncatedInLine() {
|
|
let harness = Harness()
|
|
let model = makeModel(harness: harness)
|
|
let long = String(repeating: "a", count: 400)
|
|
|
|
model.handleArrival(makePost(content: long, urgent: true))
|
|
harness.flushAll()
|
|
|
|
#expect(harness.lines.count == 1)
|
|
#expect(harness.lines[0].content.count < 200)
|
|
#expect(harness.lines[0].content.contains("…"))
|
|
}
|
|
}
|