Compare commits

...

49 Commits

Author SHA1 Message Date
Jack Kingsman a351c86ccb Add favorites as contact field (dug) 2026-04-05 20:50:27 -07:00
Jack Kingsman c2e1a3cbe6 Import radio favorites as favorites 2026-04-05 18:15:04 -07:00
jkingsman c2d1339256 Default stale node pruning for visualizer to ON 2026-04-05 15:55:47 -07:00
jkingsman cb7139a7e1 Always offer basic auth, move docker-not-found warning to the top 2026-04-05 15:41:02 -07:00
Jack Kingsman 6332387704 Define a better y domain for repeater battery voltage 2026-04-05 12:45:52 -07:00
Jack Kingsman 3f2b8e2a1f Refocus CLI textbox after command completion. Closes #164. 2026-04-05 11:55:52 -07:00
Jack Kingsman 40c37745b6 Massage the Readme a bit more 2026-04-05 11:55:31 -07:00
Jack Kingsman 9edac47aa2 Add clearer warning about RemoteTerm taking over the radio and governing contacts/channels loading. Closes #163. 2026-04-05 11:49:57 -07:00
Jack Kingsman 44f8aafb66 Retain recent traces and make them click-to-trace. Closes #160. 2026-04-04 16:43:12 -07:00
Jack Kingsman 9e3805f5d0 Use receipt time not sender time for display 2026-04-04 16:24:36 -07:00
Jack Kingsman 457799d8df Calm down clock skew loggings 2026-04-04 15:31:30 -07:00
Jack Kingsman de3ad2d51f Calm it down on sync logs 2026-04-04 15:10:45 -07:00
Jack Kingsman ad83bc7979 Show telemetry inline 2026-04-04 14:29:31 -07:00
Jack Kingsman 9ebf63491c Have tests use prod regexes 2026-04-04 13:13:37 -07:00
Jack Kingsman b19585db6d Go crazy style on systemd escaping. Closes #159. 2026-04-04 12:24:36 -07:00
Jack Kingsman c28d22379e Be a little gentler; call it a room finder rather than a cracker 2026-04-04 12:06:28 -07:00
Jack Kingsman 1e5ccf6c29 Add clearer issue identification for missing HTTPS context for channel finder 2026-04-04 12:03:07 -07:00
Jack Kingsman 81f5bde287 Add hop counts to width selection 2026-04-03 22:06:00 -07:00
Jack Kingsman c33eb469ac Updating changelog + build for 3.8.0 2026-04-03 19:36:27 -07:00
Jack Kingsman 0fe6584e7a Add packet display to map & add map dark mode 2026-04-03 19:18:22 -07:00
Jack Kingsman 557d79d437 Add packets to general map 2026-04-03 18:57:34 -07:00
Jack Kingsman daff3dcb4a Drop low value tests 2026-04-03 17:55:02 -07:00
Jack Kingsman 77db7287d6 Drop lame imports 2026-04-03 17:51:26 -07:00
Jack Kingsman 67873e8dd9 Drop some duplicated logic and defns 2026-04-03 17:47:44 -07:00
Jack Kingsman e2ddf5f79f Move require connected down into the manager 2026-04-03 17:37:30 -07:00
Jack Kingsman 4a93641f04 Axe some dead code 2026-04-03 17:22:04 -07:00
Jack Kingsman d5922a214b Clear out old migration logic and replace with thin shim for favorites; sort order is lost 2026-04-03 17:15:41 -07:00
Jack Kingsman 7ad1ee26a4 Add RSSI/SNR to received messages. Closes #148. 2026-04-03 15:20:44 -07:00
Jack Kingsman 08238aa464 Add close button to modal. Closes #156 (and modals lol), ish. 2026-04-03 14:54:59 -07:00
Jack Kingsman 1046baf741 Add auto-resend option for not-heard-repeated messages. Closes #154. 2026-04-03 14:43:52 -07:00
Jack Kingsman 42e1b7b5d9 Add canonical style reference. Closes #155. 2026-04-03 14:27:44 -07:00
Jack Kingsman 3ca4f7edf7 Fix missing test failures and patch double declared model 2026-04-03 14:15:19 -07:00
Jack Kingsman 55081d4a2d Add hop width to channel info. Closes #153. 2026-04-03 14:04:35 -07:00
Jack Kingsman be2b2604df Add intervalized repeater metrics collection. Closes #151. 2026-04-03 13:45:39 -07:00
Jack Kingsman 35981d8f8b Be more aggressive about resetting the hop width and warning if that doesn't work. This and the prior work closes #152. 2026-04-03 13:16:43 -07:00
Jack Kingsman 8e998c03ba Add channel path hash width override 2026-04-03 13:05:58 -07:00
Jack Kingsman d802dd4212 Fix table display in primary agents.md 2026-04-02 20:31:54 -07:00
Jack Kingsman 7557eb1fa6 Merge pull request #150 from jkingsman/bugbash-v7
Bugbash v7
2026-04-02 20:20:23 -07:00
Jack Kingsman 6a4af5e602 More complete message lifecycle tests 2026-04-02 20:17:51 -07:00
Jack Kingsman 1895e6a919 Clean up legacy sort order 2026-04-02 20:16:16 -07:00
Jack Kingsman 975bf7f03f Docs, dead code, and schema updates 2026-04-02 19:03:02 -07:00
Jack Kingsman c7d5d3887d Yield radio lock on build repeater ops and use INSERT OR IGNORE instead of check-then-act on packet ops 2026-04-02 18:53:34 -07:00
Jack Kingsman 5c93d8487e Stop using db ops to do casing; unify on write and then our indices are happy once more 2026-04-02 18:50:56 -07:00
Jack Kingsman 5d2834a9fb Add some tests around cascade deletion behaving now that we have FK pragma turned on 2026-04-02 18:46:37 -07:00
Jack Kingsman cfe485bf29 Be kinder about streaming volume in memory 2026-04-02 18:43:48 -07:00
Jack Kingsman e7f6bd0397 Bump python requirement so as not to hit toml issues 2026-04-02 18:41:03 -07:00
Jack Kingsman 1e7dc6af46 Don't clobber sort order 2026-04-02 18:40:25 -07:00
Jack Kingsman af40cc3c8e Add more recent screenshot 2026-04-02 18:06:29 -07:00
Jack Kingsman 2561b70fed Fix tests for apprise redaction 2026-04-02 18:03:34 -07:00
141 changed files with 4084 additions and 2429 deletions
+5 -2
View File
@@ -327,6 +327,7 @@ All endpoints are prefixed with `/api` (e.g., `/api/health`).
| GET | `/api/contacts/analytics` | Unified keyed-or-name contact analytics payload |
| GET | `/api/contacts/repeaters/advert-paths` | List recent unique advert paths for all contacts |
| POST | `/api/contacts` | Create contact (optionally trigger historical DM decrypt) |
| POST | `/api/contacts/bulk-delete` | Delete multiple contacts |
| DELETE | `/api/contacts/{public_key}` | Delete contact |
| POST | `/api/contacts/{public_key}/mark-read` | Mark contact conversation as read |
| POST | `/api/contacts/{public_key}/command` | Send CLI command to repeater |
@@ -346,12 +347,13 @@ All endpoints are prefixed with `/api` (e.g., `/api/health`).
| POST | `/api/contacts/{public_key}/room/status` | Fetch room-server status telemetry |
| POST | `/api/contacts/{public_key}/room/lpp-telemetry` | Fetch room-server CayenneLPP sensor data |
| POST | `/api/contacts/{public_key}/room/acl` | Fetch room-server ACL entries |
| GET | `/api/channels` | List channels |
| GET | `/api/channels/{key}/detail` | Comprehensive channel profile (message stats, top senders) |
| POST | `/api/channels` | Create channel |
| POST | `/api/channels/bulk-hashtag` | Create multiple hashtag channels |
| DELETE | `/api/channels/{key}` | Delete channel |
| POST | `/api/channels/{key}/flood-scope-override` | Set or clear a per-channel regional flood-scope override |
| POST | `/api/channels/{key}/path-hash-mode-override` | Set or clear a per-channel path hash mode override |
| POST | `/api/channels/{key}/mark-read` | Mark channel as read |
| GET | `/api/messages` | List with filters (`q`, `after`/`after_id` for forward pagination) |
| GET | `/api/messages/around/{id}` | Get messages around a specific message (for jump-to-message) |
@@ -400,6 +402,7 @@ All endpoints are prefixed with `/api` (e.g., `/api/health`).
- Hashtag channels: `SHA256("#name")[:16]` converted to hex
- Custom channels: User-provided or generated
- Channels may also persist `flood_scope_override`; when set, channel sends temporarily switch the radio flood scope to that value for the duration of the send, then restore the global app setting.
- Channels may persist `path_hash_mode_override` (0/1/2); when set, channel sends temporarily switch the radio path hash mode for the duration of the send, then restore the radio default.
### Message Types
@@ -475,7 +478,7 @@ mc.subscribe(EventType.ACK, handler)
| `MESHCORE_ENABLE_MESSAGE_POLL_FALLBACK` | `false` | Switch the always-on radio audit task from hourly checks to aggressive 10-second polling; the audit checks both missed message drift and channel-slot cache drift |
| `MESHCORE_FORCE_CHANNEL_SLOT_RECONFIGURE` | `false` | Disable channel-slot reuse and force `set_channel(...)` before every channel send, even on serial/BLE |
**Note:** Runtime app settings are stored in the database (`app_settings` table), not environment variables. These include `max_radio_contacts`, `auto_decrypt_dm_on_advert`, `sidebar_sort_order`, `advert_interval`, `last_advert_time`, `favorites`, `last_message_times`, `flood_scope`, `blocked_keys`, and `blocked_names`. `max_radio_contacts` is the configured radio contact capacity baseline used by background maintenance: favorites reload first, non-favorite fill targets about 80% of that value, and full offload/reload triggers around 95% occupancy. They are configured via `GET/PATCH /api/settings`. The backend still carries `sidebar_sort_order` for compatibility and migration, but the current frontend sidebar stores sort order per section (`Channels`, `Contacts`, `Repeaters`) in localStorage rather than treating it as one shared server-backed preference. MQTT, bot, webhook, Apprise, and SQS configs are stored in the `fanout_configs` table, managed via `/api/fanout`. If the radio's channel slots appear unstable or another client is mutating them underneath this app, operators can force the old always-reconfigure send path with `MESHCORE_FORCE_CHANNEL_SLOT_RECONFIGURE=true`.
**Note:** Runtime app settings are stored in the database (`app_settings` table), not environment variables. These include `max_radio_contacts`, `auto_decrypt_dm_on_advert`, `advert_interval`, `last_advert_time`, `favorites`, `last_message_times`, `flood_scope`, `blocked_keys`, `blocked_names`, and `discovery_blocked_types`. `max_radio_contacts` is the configured radio contact capacity baseline used by background maintenance: favorites reload first, non-favorite fill targets about 80% of that value, and full offload/reload triggers around 95% occupancy. They are configured via `GET/PATCH /api/settings`. MQTT, bot, webhook, Apprise, and SQS configs are stored in the `fanout_configs` table, managed via `/api/fanout`. If the radio's channel slots appear unstable or another client is mutating them underneath this app, operators can force the old always-reconfigure send path with `MESHCORE_FORCE_CHANNEL_SLOT_RECONFIGURE=true`.
Byte-perfect channel retries are user-triggered via `POST /api/messages/channel/{message_id}/resend` and are allowed for 30 seconds after the original send.
+15
View File
@@ -1,3 +1,18 @@
## [3.8.0] - 2026-04-03
* Feature: Per-channel hop width override
* Feature: Intervalized repeater telemetry collection
* Feature: Auto-resend option for byte-perfect resends on no repeater echo
* Feature: Attach RSSI/SNR to received packets
* Feature: Add motion packet display to map
* Feature: Map dark mode
* Bugfix: Make DB indices more useful around capitalization
* Misc: Bump required Python to 3.11
* Misc: Performance, documentation, and test improvements
* Misc: More yields during long radio operations
* Misc: Dead code & crufty test removal
* Misc: Remove all but stub frontend favorites migration for very very old versions
## [3.7.1] - 2026-04-02
* Feature: Redact Apprise URLs to prevent sensitive information disclosure
+8 -15
View File
@@ -12,21 +12,14 @@ Backend server + browser interface for MeshCore mesh radio networks. Connect you
* Use the more recent 1.14 firmwares which support multibyte pathing
* Visualize the mesh as a map or node set, view repeater stats, and more!
For advanced setup and troubleshooting see [README_ADVANCED.md](README_ADVANCED.md). If you plan to contribute, read [CONTRIBUTING.md](CONTRIBUTING.md).
**Warning:** This app is for trusted environments only. _Do not put this on an untrusted network, or open it to the public._ You can optionally set `MESHCORE_BASIC_AUTH_USERNAME` and `MESHCORE_BASIC_AUTH_PASSWORD` for app-wide HTTP Basic auth, but that is only a coarse gate and must be paired with HTTPS. The bots can execute arbitrary Python code which means anyone who gets access to the app can, too. To completely disable the bot system, start the server with `MESHCORE_DISABLE_BOTS=true` — this prevents all bot execution and blocks bot configuration changes via the API. If you need stronger access control, consider using a reverse proxy like Nginx, or extending FastAPI; full access control and user management are outside the scope of this app.
![Screenshot of the application's web interface](app_screenshot.png)
## Start Here
Most users should choose one of these paths:
1. Clone and build from source.
2. Download the prebuilt release zip if you are on a resource-constrained system and do not want to build the frontend locally.
3. Use Docker if that better matches how you deploy.
For advanced setup, troubleshooting, HTTPS, systemd service setup, and remediation environment variables, see [README_ADVANCED.md](README_ADVANCED.md).
If you plan to contribute, read [CONTRIBUTING.md](CONTRIBUTING.md).
> [!WARNING]
> RemoteTerm does *full* management of the radio, meaning that once a radio is connected to RemoteTerm, all contacts/channels will be imported and offloaded to RemoteTerm and the contacts actually synced to the device will be governed by RemoteTerm. This means that RemoteTerm can be a poor fit for users who are looking to swap radios in and out, maintaining radio state (favorites, channels, etc.) irrespective of app usage.
## Requirements
@@ -71,7 +64,7 @@ usbipd attach --wsl --busid 3-8
```
</details>
## Path 1: Clone And Build
## Install Path 1: Clone And Build
**This approach is recommended over Docker due to intermittent serial communications issues I've seen on \*nix systems.**
@@ -89,10 +82,10 @@ Access the app at http://localhost:8000.
Source checkouts expect a normal frontend build in `frontend/dist`.
> [!NOTE]
> [!TIP]
> Running on lightweight hardware, or just do not want to build the frontend locally? From a cloned checkout, run `python3 scripts/setup/fetch_prebuilt_frontend.py` to fetch and unpack a prebuilt frontend into `frontend/prebuilt`, then start the app normally with `uv run uvicorn app.main:app --host 0.0.0.0 --port 8000`.
> [!TIP]
> [!NOTE]
> On Linux, you can also install RemoteTerm as a persistent `systemd` service that starts on boot and restarts automatically on failure:
>
> ```bash
@@ -101,7 +94,7 @@ Source checkouts expect a normal frontend build in `frontend/dist`.
>
> For the full service workflow and post-install operations, see [README_ADVANCED.md](README_ADVANCED.md).
## Path 2: Docker
## Install Path 2: Docker
> **Warning:** Docker has had reports intermittent issues with serial event subscriptions. The native method above is more reliable.
+5 -5
View File
@@ -190,6 +190,7 @@ app/
- `GET /contacts/analytics` — unified keyed-or-name analytics payload
- `GET /contacts/repeaters/advert-paths` — recent advert paths for all contacts
- `POST /contacts`
- `POST /contacts/bulk-delete`
- `DELETE /contacts/{public_key}`
- `POST /contacts/{public_key}/mark-read`
- `POST /contacts/{public_key}/command`
@@ -214,8 +215,10 @@ app/
- `GET /channels`
- `GET /channels/{key}/detail`
- `POST /channels`
- `POST /channels/bulk-hashtag`
- `DELETE /channels/{key}`
- `POST /channels/{key}/flood-scope-override`
- `POST /channels/{key}/path-hash-mode-override`
- `POST /channels/{key}/mark-read`
### Messages
@@ -278,7 +281,7 @@ Client sends `"ping"` text; server replies `{"type":"pong"}`.
Main tables:
- `contacts` (includes `first_seen` for contact age tracking and `direct_path_hash_mode` / `route_override_*` for DM routing)
- `channels`
Includes optional `flood_scope_override` for channel-specific regional sends.
Includes optional `flood_scope_override` for channel-specific regional sends and optional `path_hash_mode_override` for per-channel path hop width.
- `messages` (includes `sender_name`, `sender_key` for per-contact channel message attribution)
- `raw_packets`
- `contact_advert_paths` (recent unique advertisement paths per contact, keyed by contact + path bytes + hop count)
@@ -300,15 +303,12 @@ Repository writes should prefer typed models such as `ContactUpsert` over ad hoc
- `max_radio_contacts`
- `favorites`
- `auto_decrypt_dm_on_advert`
- `sidebar_sort_order`
- `last_message_times`
- `preferences_migrated`
- `advert_interval`
- `last_advert_time`
- `flood_scope`
- `blocked_keys`, `blocked_names`
Note: `sidebar_sort_order` remains in the backend model for compatibility and migration, but the current frontend sidebar uses per-section localStorage sort preferences instead of a single shared server-backed sort mode.
- `blocked_keys`, `blocked_names`, `discovery_blocked_types`
Note: MQTT, community MQTT, and bot configs were migrated to the `fanout_configs` table (migrations 36-38).
+53 -6
View File
@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS contacts (
on_radio INTEGER DEFAULT 0,
last_contacted INTEGER,
first_seen INTEGER,
last_read_at INTEGER
last_read_at INTEGER,
favorite INTEGER DEFAULT 0
);
CREATE TABLE IF NOT EXISTS channels (
@@ -36,7 +37,9 @@ CREATE TABLE IF NOT EXISTS channels (
is_hashtag INTEGER DEFAULT 0,
on_radio INTEGER DEFAULT 0,
flood_scope_override TEXT,
last_read_at INTEGER
path_hash_mode_override INTEGER,
last_read_at INTEGER,
favorite INTEGER DEFAULT 0
);
CREATE TABLE IF NOT EXISTS messages (
@@ -46,7 +49,7 @@ CREATE TABLE IF NOT EXISTS messages (
text TEXT NOT NULL,
sender_timestamp INTEGER,
received_at INTEGER NOT NULL,
path TEXT,
paths TEXT,
txt_type INTEGER DEFAULT 0,
signature TEXT,
outgoing INTEGER DEFAULT 0,
@@ -91,23 +94,67 @@ CREATE TABLE IF NOT EXISTS contact_name_history (
FOREIGN KEY (public_key) REFERENCES contacts(public_key) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS app_settings (
id INTEGER PRIMARY KEY CHECK (id = 1),
max_radio_contacts INTEGER DEFAULT 200,
favorites TEXT DEFAULT '[]',
auto_decrypt_dm_on_advert INTEGER DEFAULT 1,
last_message_times TEXT DEFAULT '{}',
preferences_migrated INTEGER DEFAULT 0,
advert_interval INTEGER DEFAULT 0,
last_advert_time INTEGER DEFAULT 0,
flood_scope TEXT DEFAULT '',
blocked_keys TEXT DEFAULT '[]',
blocked_names TEXT DEFAULT '[]',
discovery_blocked_types TEXT DEFAULT '[]',
tracked_telemetry_repeaters TEXT DEFAULT '[]',
auto_resend_channel INTEGER DEFAULT 0
);
INSERT OR IGNORE INTO app_settings (id) VALUES (1);
CREATE TABLE IF NOT EXISTS fanout_configs (
id TEXT PRIMARY KEY,
type TEXT NOT NULL,
name TEXT NOT NULL,
enabled INTEGER DEFAULT 0,
config TEXT NOT NULL DEFAULT '{}',
scope TEXT NOT NULL DEFAULT '{}',
sort_order INTEGER DEFAULT 0,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS repeater_telemetry_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
public_key TEXT NOT NULL,
timestamp INTEGER NOT NULL,
data TEXT NOT NULL,
FOREIGN KEY (public_key) REFERENCES contacts(public_key) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_messages_received ON messages(received_at);
CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_dedup_null_safe
ON messages(type, conversation_key, text, COALESCE(sender_timestamp, 0))
WHERE type = 'CHAN';
CREATE UNIQUE INDEX IF NOT EXISTS idx_messages_incoming_priv_dedup
ON messages(type, conversation_key, text, COALESCE(sender_timestamp, 0))
WHERE type = 'PRIV' AND outgoing = 0;
CREATE INDEX IF NOT EXISTS idx_messages_sender_key ON messages(sender_key);
CREATE INDEX IF NOT EXISTS idx_messages_pagination
ON messages(type, conversation_key, received_at DESC, id DESC);
CREATE INDEX IF NOT EXISTS idx_messages_unread_covering
ON messages(type, conversation_key, outgoing, received_at);
CREATE INDEX IF NOT EXISTS idx_raw_packets_message_id ON raw_packets(message_id);
CREATE INDEX IF NOT EXISTS idx_raw_packets_timestamp ON raw_packets(timestamp);
CREATE UNIQUE INDEX IF NOT EXISTS idx_raw_packets_payload_hash ON raw_packets(payload_hash);
CREATE INDEX IF NOT EXISTS idx_contacts_on_radio ON contacts(on_radio);
CREATE INDEX IF NOT EXISTS idx_contacts_type_last_seen ON contacts(type, last_seen);
CREATE INDEX IF NOT EXISTS idx_messages_type_received_conversation
ON messages(type, received_at, conversation_key);
-- idx_messages_sender_key is created by migration 25 (after adding the sender_key column)
-- idx_messages_incoming_priv_dedup is created by migration 44 after legacy rows are reconciled
CREATE INDEX IF NOT EXISTS idx_contact_advert_paths_recent
ON contact_advert_paths(public_key, last_seen DESC);
CREATE INDEX IF NOT EXISTS idx_contact_name_history_key
ON contact_name_history(public_key, last_seen DESC);
CREATE INDEX IF NOT EXISTS idx_repeater_telemetry_pk_ts
ON repeater_telemetry_history(public_key, timestamp);
"""
-8
View File
@@ -1,8 +0,0 @@
"""Shared dependencies for FastAPI routers."""
from app.services.radio_runtime import radio_runtime as radio_manager
def require_connected():
"""Dependency that ensures radio is connected and returns meshcore instance."""
return radio_manager.require_connected()
-1
View File
@@ -202,7 +202,6 @@ async def on_path_update(event: "Event") -> None:
# Legacy firmware/library payloads only support 1-byte hop hashes.
normalized_path_hash_mode = -1 if normalized_path_len == -1 else 0
else:
normalized_path_hash_mode = None
try:
normalized_path_hash_mode = int(path_hash_mode)
except (TypeError, ValueError):
-31
View File
@@ -52,19 +52,6 @@ class ToastPayload(TypedDict):
details: NotRequired[str]
WsEventPayload = (
HealthResponse
| Message
| Contact
| ContactResolvedPayload
| Channel
| ContactDeletedPayload
| ChannelDeletedPayload
| RawPacketBroadcast
| MessageAckedPayload
| ToastPayload
)
_PAYLOAD_ADAPTERS: dict[WsEventType, TypeAdapter[Any]] = {
"health": TypeAdapter(HealthResponse),
"message": TypeAdapter(Message),
@@ -80,14 +67,6 @@ _PAYLOAD_ADAPTERS: dict[WsEventType, TypeAdapter[Any]] = {
}
def validate_ws_event_payload(event_type: str, data: Any) -> WsEventPayload | Any:
"""Validate known WebSocket payloads; pass unknown events through unchanged."""
adapter = _PAYLOAD_ADAPTERS.get(event_type) # type: ignore[arg-type]
if adapter is None:
return data
return adapter.validate_python(data)
def dump_ws_event(event_type: str, data: Any) -> str:
"""Serialize a WebSocket event envelope with validation for known event types."""
adapter = _PAYLOAD_ADAPTERS.get(event_type) # type: ignore[arg-type]
@@ -104,13 +83,3 @@ def dump_ws_event(event_type: str, data: Any) -> str:
event_type,
)
return json.dumps({"type": event_type, "data": data})
def dump_ws_event_payload(event_type: str, data: Any) -> Any:
"""Return the JSON-serializable payload for a WebSocket event."""
adapter = _PAYLOAD_ADAPTERS.get(event_type) # type: ignore[arg-type]
if adapter is None:
return data
validated = adapter.validate_python(data)
return adapter.dump_python(validated, mode="json")
+2 -5
View File
@@ -144,11 +144,8 @@ class MapUploadModule(FanoutModule):
if advert is None:
return
# TODO: advert Ed25519 signature verification is skipped here.
# The radio has already validated the packet before passing it to RT,
# so re-verification is redundant in practice. If added, verify that
# nacl.bindings.crypto_sign_open(sig + (pubkey_bytes || timestamp_bytes),
# advert.public_key_bytes) succeeds before proceeding.
# Advert Ed25519 signature verification is intentionally skipped.
# The radio validates packets before passing them to RT.
# Only process repeaters (2) and rooms (3) — any other role is rejected
if advert.device_role not in _ALLOWED_DEVICE_ROLES:
+2
View File
@@ -21,6 +21,7 @@ from app.radio_sync import (
stop_message_polling,
stop_periodic_advert,
stop_periodic_sync,
stop_telemetry_collect,
)
from app.routers import (
channels,
@@ -103,6 +104,7 @@ async def lifespan(app: FastAPI):
await stop_noise_floor_sampling()
await stop_periodic_advert()
await stop_periodic_sync()
await stop_telemetry_collect()
if radio_manager.meshcore:
await radio_manager.meshcore.stop_auto_message_fetching()
await radio_manager.disconnect()
+186 -7
View File
@@ -389,6 +389,36 @@ async def run_migrations(conn: aiosqlite.Connection) -> int:
await set_version(conn, 50)
applied += 1
if version < 51:
logger.info("Applying migration 51: drop sidebar_sort_order from app_settings")
await _migrate_051_drop_sidebar_sort_order(conn)
await set_version(conn, 51)
applied += 1
if version < 52:
logger.info("Applying migration 52: add path_hash_mode_override to channels")
await _migrate_052_add_channel_path_hash_mode_override(conn)
await set_version(conn, 52)
applied += 1
if version < 53:
logger.info("Applying migration 53: add tracked_telemetry_repeaters to app_settings")
await _migrate_053_tracked_telemetry_repeaters(conn)
await set_version(conn, 53)
applied += 1
if version < 54:
logger.info("Applying migration 54: add auto_resend_channel to app_settings")
await _migrate_054_auto_resend_channel(conn)
await set_version(conn, 54)
applied += 1
if version < 55:
logger.info("Applying migration 55: move favorites to per-entity columns")
await _migrate_055_favorites_to_columns(conn)
await set_version(conn, 55)
applied += 1
if applied > 0:
logger.info(
"Applied %d migration(s), schema now at version %d", applied, await get_version(conn)
@@ -859,13 +889,9 @@ async def _migrate_009_create_app_settings_table(conn: aiosqlite.Connection) ->
"""
)
# Initialize with default row
await conn.execute(
"""
INSERT OR IGNORE INTO app_settings (id, max_radio_contacts, favorites, auto_decrypt_dm_on_advert, sidebar_sort_order, last_message_times, preferences_migrated)
VALUES (1, 200, '[]', 1, 'recent', '{}', 0)
"""
)
# Initialize with default row (use only the id column so this works
# regardless of which columns exist — defaults fill the rest).
await conn.execute("INSERT OR IGNORE INTO app_settings (id) VALUES (1)")
await conn.commit()
logger.debug("Created app_settings table with default values")
@@ -3128,3 +3154,156 @@ async def _migrate_050_repeater_telemetry_history(conn: aiosqlite.Connection) ->
"""
)
await conn.commit()
async def _migrate_051_drop_sidebar_sort_order(conn: aiosqlite.Connection) -> None:
"""Remove vestigial sidebar_sort_order column from app_settings."""
col_cursor = await conn.execute("PRAGMA table_info(app_settings)")
columns = {row[1] for row in await col_cursor.fetchall()}
if "sidebar_sort_order" in columns:
try:
await conn.execute("ALTER TABLE app_settings DROP COLUMN sidebar_sort_order")
await conn.commit()
except Exception as e:
error_msg = str(e).lower()
if "syntax error" in error_msg or "drop column" in error_msg:
logger.debug(
"SQLite doesn't support DROP COLUMN, sidebar_sort_order column will remain"
)
await conn.commit()
else:
raise
async def _migrate_052_add_channel_path_hash_mode_override(conn: aiosqlite.Connection) -> None:
"""Add nullable per-channel path hash mode override column."""
tables_cursor = await conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
if "channels" not in {row[0] for row in await tables_cursor.fetchall()}:
await conn.commit()
return
try:
await conn.execute("ALTER TABLE channels ADD COLUMN path_hash_mode_override INTEGER")
await conn.commit()
except Exception as e:
if "duplicate column" in str(e).lower():
await conn.commit()
else:
raise
async def _migrate_053_tracked_telemetry_repeaters(conn: aiosqlite.Connection) -> None:
"""Add tracked_telemetry_repeaters JSON list column to app_settings."""
tables_cursor = await conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
if "app_settings" not in {row[0] for row in await tables_cursor.fetchall()}:
await conn.commit()
return
col_cursor = await conn.execute("PRAGMA table_info(app_settings)")
columns = {row[1] for row in await col_cursor.fetchall()}
if "tracked_telemetry_repeaters" not in columns:
await conn.execute(
"ALTER TABLE app_settings ADD COLUMN tracked_telemetry_repeaters TEXT DEFAULT '[]'"
)
await conn.commit()
async def _migrate_054_auto_resend_channel(conn: aiosqlite.Connection) -> None:
"""Add auto_resend_channel boolean column to app_settings."""
tables_cursor = await conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
if "app_settings" not in {row[0] for row in await tables_cursor.fetchall()}:
await conn.commit()
return
col_cursor = await conn.execute("PRAGMA table_info(app_settings)")
columns = {row[1] for row in await col_cursor.fetchall()}
if "auto_resend_channel" not in columns:
await conn.execute(
"ALTER TABLE app_settings ADD COLUMN auto_resend_channel INTEGER DEFAULT 0"
)
await conn.commit()
async def _migrate_055_favorites_to_columns(conn: aiosqlite.Connection) -> None:
"""Move favorites from app_settings JSON blob to per-entity boolean columns.
1. Add ``favorite`` column to contacts and channels tables.
2. Backfill from the ``app_settings.favorites`` JSON array.
3. Drop the ``favorites`` column from app_settings.
"""
import json as _json
# --- Add columns ---
tables_cursor = await conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
existing_tables = {row[0] for row in await tables_cursor.fetchall()}
for table in ("contacts", "channels"):
if table not in existing_tables:
continue
col_cursor = await conn.execute(f"PRAGMA table_info({table})")
columns = {row[1] for row in await col_cursor.fetchall()}
if "favorite" not in columns:
await conn.execute(f"ALTER TABLE {table} ADD COLUMN favorite INTEGER DEFAULT 0")
await conn.commit()
# --- Backfill from JSON ---
tables_cursor = await conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
if "app_settings" not in {row[0] for row in await tables_cursor.fetchall()}:
await conn.commit()
return
col_cursor = await conn.execute("PRAGMA table_info(app_settings)")
settings_columns = {row[1] for row in await col_cursor.fetchall()}
if "favorites" not in settings_columns:
await conn.commit()
return
cursor = await conn.execute("SELECT favorites FROM app_settings WHERE id = 1")
row = await cursor.fetchone()
if row and row[0]:
try:
favorites = _json.loads(row[0])
except (ValueError, TypeError):
favorites = []
contact_keys = []
channel_keys = []
for fav in favorites:
if not isinstance(fav, dict):
continue
fav_type = fav.get("type")
fav_id = fav.get("id")
if not fav_id:
continue
if fav_type == "contact":
contact_keys.append(fav_id)
elif fav_type == "channel":
channel_keys.append(fav_id)
if contact_keys:
placeholders = ",".join("?" for _ in contact_keys)
await conn.execute(
f"UPDATE contacts SET favorite = 1 WHERE public_key IN ({placeholders})",
contact_keys,
)
if channel_keys:
placeholders = ",".join("?" for _ in channel_keys)
await conn.execute(
f"UPDATE channels SET favorite = 1 WHERE key IN ({placeholders})",
channel_keys,
)
if contact_keys or channel_keys:
logger.info(
"Backfilled %d contact favorite(s) and %d channel favorite(s) from app_settings",
len(contact_keys),
len(channel_keys),
)
await conn.commit()
# --- Drop the JSON column ---
try:
await conn.execute("ALTER TABLE app_settings DROP COLUMN favorites")
await conn.commit()
except Exception as e:
error_msg = str(e).lower()
if "syntax error" in error_msg or "drop column" in error_msg:
logger.debug("SQLite doesn't support DROP COLUMN; favorites column will remain unused")
await conn.commit()
else:
raise
+32 -74
View File
@@ -91,6 +91,7 @@ class Contact(BaseModel):
lon: float | None = None
last_seen: int | None = None
on_radio: bool = False
favorite: bool = False
last_contacted: int | None = None # Last time we sent/received a message
last_read_at: int | None = None # Server-side read state tracking
first_seen: int | None = None
@@ -196,15 +197,6 @@ class Contact(BaseModel):
"""Convert the stored contact to the repository's write contract."""
return ContactUpsert.from_contact(self, **changes)
@staticmethod
def from_radio_dict(public_key: str, radio_data: dict, on_radio: bool = False) -> dict:
"""Backward-compatible dict wrapper over ContactUpsert.from_radio_dict()."""
return ContactUpsert.from_radio_dict(
public_key,
radio_data,
on_radio=on_radio,
).model_dump()
class CreateContactRequest(BaseModel):
"""Request to create a new contact."""
@@ -283,30 +275,6 @@ class NearestRepeater(BaseModel):
heard_count: int
class ContactDetail(BaseModel):
"""Comprehensive contact profile data."""
contact: Contact
name_history: list[ContactNameHistory] = Field(default_factory=list)
dm_message_count: int = 0
channel_message_count: int = 0
most_active_rooms: list[ContactActiveRoom] = Field(default_factory=list)
advert_paths: list[ContactAdvertPath] = Field(default_factory=list)
advert_frequency: float | None = Field(
default=None,
description="Advert observations per hour (includes multi-path arrivals of same advert)",
)
nearest_repeaters: list[NearestRepeater] = Field(default_factory=list)
class NameOnlyContactDetail(BaseModel):
"""Channel activity summary for a sender name that is not tied to a known key."""
name: str
channel_message_count: int = 0
most_active_rooms: list[ContactActiveRoom] = Field(default_factory=list)
class ContactAnalyticsHourlyBucket(BaseModel):
"""A single hourly activity bucket for contact analytics."""
@@ -354,7 +322,12 @@ class Channel(BaseModel):
default=None,
description="Per-channel outbound flood scope override (null = use global app setting)",
)
path_hash_mode_override: int | None = Field(
default=None,
description="Per-channel path hash mode override (0=1-byte, 1=2-byte, 2=3-byte, null = use radio default)",
)
last_read_at: int | None = None # Server-side read state tracking
favorite: bool = False
class ChannelMessageCounts(BaseModel):
@@ -375,6 +348,18 @@ class ChannelTopSender(BaseModel):
message_count: int
class PathHashWidthStats(BaseModel):
"""Hop byte width distribution for parsed raw packets."""
total_packets: int = 0
single_byte: int = 0
double_byte: int = 0
triple_byte: int = 0
single_byte_pct: float = 0.0
double_byte_pct: float = 0.0
triple_byte_pct: float = 0.0
class ChannelDetail(BaseModel):
"""Comprehensive channel profile data."""
@@ -383,6 +368,7 @@ class ChannelDetail(BaseModel):
first_message_at: int | None = None
unique_sender_count: int = 0
top_senders_24h: list[ChannelTopSender] = Field(default_factory=list)
path_hash_width_24h: PathHashWidthStats = Field(default_factory=PathHashWidthStats)
class MessagePath(BaseModel):
@@ -394,6 +380,8 @@ class MessagePath(BaseModel):
default=None,
description="Hop count. None = legacy (infer as len(path)//2, i.e. 1-byte hops)",
)
rssi: int | None = Field(default=None, description="Last-hop RSSI in dBm")
snr: float | None = Field(default=None, description="Last-hop SNR in dB")
class Message(BaseModel):
@@ -770,13 +758,6 @@ class RadioDiscoveryResponse(BaseModel):
)
class Favorite(BaseModel):
"""A favorite conversation."""
type: Literal["channel", "contact"] = Field(description="'channel' or 'contact'")
id: str = Field(description="Channel key or contact public key")
class UnreadCounts(BaseModel):
"""Aggregated unread counts, mention flags, and last message times for all conversations."""
@@ -804,25 +785,14 @@ class AppSettings(BaseModel):
"favorites reload first, then background fill targets about 80% of this value"
),
)
favorites: list[Favorite] = Field(
default_factory=list, description="List of favorited conversations"
)
auto_decrypt_dm_on_advert: bool = Field(
default=True,
description="Whether to attempt historical DM decryption on new contact advertisement",
)
sidebar_sort_order: Literal["recent", "alpha"] = Field(
default="recent",
description="Sidebar sort order: 'recent' or 'alpha'",
)
last_message_times: dict[str, int] = Field(
default_factory=dict,
description="Map of conversation state keys to last message timestamps",
)
preferences_migrated: bool = Field(
default=False,
description="Whether preferences have been migrated from localStorage",
)
advert_interval: int = Field(
default=0,
description="Periodic advertisement interval in seconds (0 = disabled)",
@@ -850,19 +820,17 @@ class AppSettings(BaseModel):
"advertisements should not create new contacts; existing contacts are still updated"
),
)
class FanoutConfig(BaseModel):
"""Configuration for a single fanout integration."""
id: str
type: str # 'mqtt_private' | 'mqtt_community' | 'bot' | 'webhook' | 'apprise' | 'sqs'
name: str
enabled: bool
config: dict
scope: dict
sort_order: int = 0
created_at: int = 0
tracked_telemetry_repeaters: list[str] = Field(
default_factory=list,
description="Public keys of repeaters opted into periodic telemetry collection (max 8)",
)
auto_resend_channel: bool = Field(
default=False,
description=(
"When enabled, outgoing channel messages that receive no echo within 2 seconds "
"are automatically byte-perfect resent once (within the 30-second dedup window)"
),
)
class BusyChannel(BaseModel):
@@ -877,16 +845,6 @@ class ContactActivityCounts(BaseModel):
last_week: int
class PathHashWidthStats(BaseModel):
total_packets: int
single_byte: int
double_byte: int
triple_byte: int
single_byte_pct: float
double_byte_pct: float
triple_byte_pct: float
class NoiseFloorSample(BaseModel):
timestamp: int = Field(description="Unix timestamp of the sampled reading")
noise_floor_dbm: int = Field(description="Noise floor in dBm")
+22 -2
View File
@@ -68,6 +68,8 @@ async def create_message_from_decrypted(
received_at: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
channel_name: str | None = None,
realtime: bool = True,
) -> int | None:
@@ -81,6 +83,8 @@ async def create_message_from_decrypted(
received_at=received_at,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
channel_name=channel_name,
realtime=realtime,
broadcast_fn=broadcast_event,
@@ -95,6 +99,8 @@ async def create_dm_message_from_decrypted(
received_at: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
outgoing: bool = False,
realtime: bool = True,
) -> int | None:
@@ -107,6 +113,8 @@ async def create_dm_message_from_decrypted(
received_at=received_at,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
outgoing=outgoing,
realtime=realtime,
broadcast_fn=broadcast_event,
@@ -319,7 +327,9 @@ async def process_raw_packet(
# deduplication in create_message_from_decrypted handles adding paths to existing messages.
# This is more reliable than trying to look up the message via raw packet linking.
if payload_type == PayloadType.GROUP_TEXT:
decrypt_result = await _process_group_text(raw_bytes, packet_id, ts, packet_info)
decrypt_result = await _process_group_text(
raw_bytes, packet_id, ts, packet_info, rssi=rssi, snr=snr
)
if decrypt_result:
result.update(decrypt_result)
@@ -330,7 +340,9 @@ async def process_raw_packet(
elif payload_type == PayloadType.TEXT_MESSAGE:
# Try to decrypt direct messages using stored private key and known contacts
decrypt_result = await _process_direct_message(raw_bytes, packet_id, ts, packet_info)
decrypt_result = await _process_direct_message(
raw_bytes, packet_id, ts, packet_info, rssi=rssi, snr=snr
)
if decrypt_result:
result.update(decrypt_result)
@@ -367,6 +379,8 @@ async def _process_group_text(
packet_id: int,
timestamp: int,
packet_info: PacketInfo | None,
rssi: int | None = None,
snr: float | None = None,
) -> dict | None:
"""
Process a GroupText (channel message) packet.
@@ -403,6 +417,8 @@ async def _process_group_text(
received_at=timestamp,
path=packet_info.path.hex() if packet_info else None,
path_len=packet_info.path_length if packet_info else None,
rssi=rssi,
snr=snr,
)
return {
@@ -544,6 +560,8 @@ async def _process_direct_message(
packet_id: int,
timestamp: int,
packet_info: PacketInfo | None,
rssi: int | None = None,
snr: float | None = None,
) -> dict | None:
"""
Process a TEXT_MESSAGE (direct message) packet.
@@ -644,6 +662,8 @@ async def _process_direct_message(
received_at=timestamp,
path=packet_info.path.hex() if packet_info else None,
path_len=packet_info.path_length if packet_info else None,
rssi=rssi,
snr=snr,
outgoing=is_outgoing,
)
+48
View File
@@ -244,3 +244,51 @@ def parse_explicit_hop_route(route_text: str) -> tuple[str, int, int]:
raise ValueError(f"Explicit path exceeds MAX_PATH_SIZE={MAX_PATH_SIZE} bytes")
return "".join(hops), len(hops), hash_size - 1
async def bucket_path_hash_widths(cursor, *, batch_size: int = 500) -> dict[str, int | float]:
"""Bucket raw packet rows by hop hash width and return counts + percentages.
*cursor* must be an already-executed async cursor whose rows have a ``data``
column containing raw packet bytes.
"""
single_byte = 0
double_byte = 0
triple_byte = 0
while True:
rows = await cursor.fetchmany(batch_size)
if not rows:
break
for row in rows:
envelope = parse_packet_envelope(bytes(row["data"]))
if envelope is None:
continue
if envelope.hash_size == 1:
single_byte += 1
elif envelope.hash_size == 2:
double_byte += 1
elif envelope.hash_size == 3:
triple_byte += 1
total = single_byte + double_byte + triple_byte
if total == 0:
return {
"total_packets": 0,
"single_byte": 0,
"double_byte": 0,
"triple_byte": 0,
"single_byte_pct": 0.0,
"double_byte_pct": 0.0,
"triple_byte_pct": 0.0,
}
return {
"total_packets": total,
"single_byte": single_byte,
"double_byte": double_byte,
"triple_byte": triple_byte,
"single_byte_pct": (single_byte / total) * 100,
"double_byte_pct": (double_byte / total) * 100,
"triple_byte_pct": (triple_byte / total) * 100,
}
+188 -91
View File
@@ -28,6 +28,7 @@ from app.repository import (
AppSettingsRepository,
ChannelRepository,
ContactRepository,
RepeaterTelemetryRepository,
)
from app.services.contact_reconciliation import (
promote_prefix_contacts_for_contact,
@@ -155,6 +156,15 @@ ADVERT_CHECK_INTERVAL = 60
# more frequently than this.
MIN_ADVERT_INTERVAL = 3600
# Periodic telemetry collection task handle
_telemetry_collect_task: asyncio.Task | None = None
# Telemetry collection interval (8 hours)
TELEMETRY_COLLECT_INTERVAL = 8 * 3600
# Initial delay before the first telemetry collection cycle (let radio settle)
TELEMETRY_COLLECT_INITIAL_DELAY = 60
# Counter to pause polling during repeater operations (supports nested pauses)
_polling_pause_count: int = 0
@@ -253,70 +263,6 @@ async def should_run_full_periodic_sync(mc: MeshCore) -> bool:
return False
async def sync_and_offload_contacts(mc: MeshCore) -> dict:
"""
Sync contacts from radio to database, then remove them from radio.
Returns counts of synced and removed contacts.
"""
synced = 0
removed = 0
try:
# Get all contacts from radio
result = await mc.commands.get_contacts()
if result is None or result.type == EventType.ERROR:
logger.error(
"Failed to get contacts from radio: %s. "
"If you see this repeatedly, the radio may be visible on the "
"serial/TCP/BLE port but not responding to commands. Check for "
"another process with the serial port open (other RemoteTerm "
"instances, serial monitors, etc.), verify the firmware is "
"up-to-date and in client mode (not repeater), or try a "
"power cycle.",
result,
)
return {"synced": 0, "removed": 0, "error": str(result)}
contacts = result.payload or {}
logger.info("Found %d contacts on radio", len(contacts))
# Sync each contact to database, then remove from radio
for public_key, contact_data in contacts.items():
# Save to database
await ContactRepository.upsert(
ContactUpsert.from_radio_dict(public_key, contact_data, on_radio=False)
)
asyncio.create_task(
_reconcile_contact_messages_background(
public_key,
contact_data.get("adv_name"),
)
)
synced += 1
# Remove from radio
try:
remove_result = await mc.commands.remove_contact(contact_data)
if remove_result.type == EventType.OK:
removed += 1
_evict_removed_contact_from_library_cache(mc, public_key)
else:
logger.warning(
"Failed to remove contact %s: %s", public_key[:12], remove_result.payload
)
except Exception as e:
logger.warning("Error removing contact %s: %s", public_key[:12], e)
logger.info("Synced %d contacts, removed %d from radio", synced, removed)
except Exception as e:
logger.error("Error during contact sync: %s", e)
return {"synced": synced, "removed": removed, "error": str(e)}
return {"synced": synced, "removed": removed}
async def sync_and_offload_channels(mc: MeshCore, max_channels: int | None = None) -> dict:
"""
Sync channels from radio to database, then clear them from radio.
@@ -361,7 +307,7 @@ async def sync_and_offload_channels(mc: MeshCore, max_channels: int | None = Non
except Exception as e:
logger.warning("Error clearing channel %d: %s", idx, e)
logger.info("Synced %d channels, cleared %d from radio", synced, cleared)
logger.debug("Synced %d channels, cleared %d from radio", synced, cleared)
except Exception as e:
logger.error("Error during channel sync: %s", e)
@@ -482,7 +428,6 @@ async def ensure_default_channels() -> None:
async def sync_and_offload_all(mc: MeshCore) -> dict:
"""Run fast startup sync, then background contact reconcile."""
logger.info("Starting full radio sync and offload")
# Contact on_radio is legacy/stale metadata. Clear it during the offload/reload
# cycle so old rows stop claiming radio residency we do not actively track.
@@ -998,10 +943,8 @@ async def sync_radio_time(mc: MeshCore) -> bool:
except Exception:
logger.warning("Reboot command failed", exc_info=True)
elif _clock_reboot_attempted:
logger.warning(
"Clock skew persists after reboot — the radio likely has a "
"hardware RTC that preserved the wrong time. A manual "
"'clkreboot' CLI command is needed to reset it."
logger.debug(
"Clock skew persists after reboot (hardware RTC); ignoring until next session."
)
return False
@@ -1111,7 +1054,7 @@ async def sync_contacts_from_radio(mc: MeshCore) -> dict:
return {"synced": 0, "radio_contacts": {}, "error": str(result)}
contacts = _normalize_radio_contacts_payload(result.payload)
logger.info("Found %d contacts on radio", len(contacts))
logger.debug("Found %d contacts on radio", len(contacts))
for public_key, contact_data in contacts.items():
await ContactRepository.upsert(
@@ -1125,7 +1068,23 @@ async def sync_contacts_from_radio(mc: MeshCore) -> dict:
)
synced += 1
logger.info("Synced %d contacts from radio snapshot", synced)
logger.debug("Synced %d contacts from radio snapshot", synced)
# Import radio-favorited contacts into app favorites
radio_fav_keys = [pk for pk, data in contacts.items() if data.get("flags", 0) & 0x01]
if radio_fav_keys:
try:
imported = 0
for pk in radio_fav_keys:
existing = await ContactRepository.get_by_key(pk)
if existing and not existing.favorite:
await ContactRepository.set_favorite(pk, True)
imported += 1
if imported:
logger.info("Imported %d radio favorite(s) into app favorites", imported)
except Exception as e:
logger.warning("Failed to import radio favorites: %s", e)
return {"synced": synced, "radio_contacts": contacts}
except Exception as e:
logger.error("Error during contact snapshot sync: %s", e)
@@ -1337,26 +1296,9 @@ async def get_contacts_selected_for_radio_sync() -> list[Contact]:
selected_contacts: list[Contact] = []
selected_keys: set[str] = set()
# Favorites first — always loaded up to max_contacts
favorite_contacts_loaded = 0
for favorite in app_settings.favorites:
if favorite.type != "contact":
continue
try:
contact = await ContactRepository.get_by_key_or_prefix(favorite.id)
except AmbiguousPublicKeyPrefixError:
logger.warning(
"Skipping favorite contact '%s': ambiguous key prefix; use full key",
favorite.id,
)
continue
if not contact:
continue
if len(contact.public_key) < 64:
logger.debug(
"Skipping unresolved prefix-only favorite contact '%s' for radio sync",
favorite.id,
)
continue
for contact in await ContactRepository.get_favorites():
key = contact.public_key.lower()
if key in selected_keys:
continue
@@ -1588,3 +1530,158 @@ async def sync_recent_contacts_to_radio(force: bool = False, mc: MeshCore | None
except Exception as e:
logger.error("Error syncing contacts to radio: %s", e, exc_info=True)
return {"loaded": 0, "error": str(e)}
# ---------------------------------------------------------------------------
# Periodic repeater telemetry collection
# ---------------------------------------------------------------------------
async def _collect_repeater_telemetry(mc: MeshCore, contact: Contact) -> bool:
"""Fetch status telemetry from a single repeater and record it.
Returns True on success, False on failure (logged, not raised).
"""
try:
await mc.commands.add_contact(contact.to_radio_dict())
status = await mc.commands.req_status_sync(contact.public_key, timeout=10, min_timeout=5)
except Exception as e:
logger.debug(
"Telemetry collect: radio command failed for %s: %s",
contact.public_key[:12],
e,
)
return False
if status is None:
logger.debug("Telemetry collect: no response from %s", contact.public_key[:12])
return False
# Map to the same field names as the manual repeater status endpoint
data = {
"battery_volts": status.get("bat", 0) / 1000.0,
"tx_queue_len": status.get("tx_queue_len", 0),
"noise_floor_dbm": status.get("noise_floor", 0),
"last_rssi_dbm": status.get("last_rssi", 0),
"last_snr_db": status.get("last_snr", 0.0),
"packets_received": status.get("nb_recv", 0),
"packets_sent": status.get("nb_sent", 0),
"airtime_seconds": status.get("airtime", 0),
"rx_airtime_seconds": status.get("rx_airtime", 0),
"uptime_seconds": status.get("uptime", 0),
"sent_flood": status.get("sent_flood", 0),
"sent_direct": status.get("sent_direct", 0),
"recv_flood": status.get("recv_flood", 0),
"recv_direct": status.get("recv_direct", 0),
"flood_dups": status.get("flood_dups", 0),
"direct_dups": status.get("direct_dups", 0),
"full_events": status.get("full_evts", 0),
}
try:
await RepeaterTelemetryRepository.record(
public_key=contact.public_key,
timestamp=int(time.time()),
data=data,
)
logger.info(
"Telemetry collect: recorded snapshot for %s (%s)",
contact.name or contact.public_key[:12],
contact.public_key[:12],
)
return True
except Exception as e:
logger.warning(
"Telemetry collect: failed to record for %s: %s",
contact.public_key[:12],
e,
)
return False
async def _telemetry_collect_loop() -> None:
"""Background task that collects telemetry from tracked repeaters every 8 hours.
Runs a first cycle after a short initial delay (so newly tracked repeaters
get a sample promptly), then sleeps the full interval between subsequent cycles.
Acquires the radio lock per-repeater (non-blocking) so manual operations can
interleave. Failures are logged and skipped.
"""
first_run = True
while True:
try:
delay = TELEMETRY_COLLECT_INITIAL_DELAY if first_run else TELEMETRY_COLLECT_INTERVAL
await asyncio.sleep(delay)
first_run = False
if not radio_manager.is_connected:
logger.debug("Telemetry collect: radio not connected, skipping cycle")
continue
app_settings = await AppSettingsRepository.get()
tracked = app_settings.tracked_telemetry_repeaters
if not tracked:
continue
logger.info("Telemetry collect: starting cycle for %d repeater(s)", len(tracked))
collected = 0
for pub_key in tracked:
contact = await ContactRepository.get_by_key(pub_key)
if not contact or contact.type != 2:
logger.debug(
"Telemetry collect: skipping %s (not found or not repeater)",
pub_key[:12],
)
continue
try:
async with radio_manager.radio_operation(
"telemetry_collect",
blocking=False,
suspend_auto_fetch=True,
) as mc:
if await _collect_repeater_telemetry(mc, contact):
collected += 1
except RadioOperationBusyError:
logger.debug(
"Telemetry collect: radio busy, skipping %s",
pub_key[:12],
)
logger.info(
"Telemetry collect: cycle complete, %d/%d successful",
collected,
len(tracked),
)
except asyncio.CancelledError:
logger.info("Telemetry collect task cancelled")
break
except Exception as e:
logger.error("Error in telemetry collect loop: %s", e, exc_info=True)
def start_telemetry_collect() -> None:
"""Start the periodic telemetry collection background task."""
global _telemetry_collect_task
if _telemetry_collect_task is None or _telemetry_collect_task.done():
_telemetry_collect_task = asyncio.create_task(_telemetry_collect_loop())
logger.info(
"Started periodic telemetry collection (interval: %ds)",
TELEMETRY_COLLECT_INTERVAL,
)
async def stop_telemetry_collect() -> None:
"""Stop the periodic telemetry collection background task."""
global _telemetry_collect_task
if _telemetry_collect_task and not _telemetry_collect_task.done():
_telemetry_collect_task.cancel()
try:
await _telemetry_collect_task
except asyncio.CancelledError:
pass
_telemetry_collect_task = None
logger.info("Stopped periodic telemetry collection")
+22 -22
View File
@@ -26,7 +26,7 @@ class ChannelRepository:
"""Get a channel by its key (32-char hex string)."""
cursor = await db.conn.execute(
"""
SELECT key, name, is_hashtag, on_radio, flood_scope_override, last_read_at
SELECT key, name, is_hashtag, on_radio, flood_scope_override, path_hash_mode_override, last_read_at, favorite
FROM channels
WHERE key = ?
""",
@@ -40,7 +40,9 @@ class ChannelRepository:
is_hashtag=bool(row["is_hashtag"]),
on_radio=bool(row["on_radio"]),
flood_scope_override=row["flood_scope_override"],
path_hash_mode_override=row["path_hash_mode_override"],
last_read_at=row["last_read_at"],
favorite=bool(row["favorite"]),
)
return None
@@ -48,7 +50,7 @@ class ChannelRepository:
async def get_all() -> list[Channel]:
cursor = await db.conn.execute(
"""
SELECT key, name, is_hashtag, on_radio, flood_scope_override, last_read_at
SELECT key, name, is_hashtag, on_radio, flood_scope_override, path_hash_mode_override, last_read_at, favorite
FROM channels
ORDER BY name
"""
@@ -61,34 +63,22 @@ class ChannelRepository:
is_hashtag=bool(row["is_hashtag"]),
on_radio=bool(row["on_radio"]),
flood_scope_override=row["flood_scope_override"],
path_hash_mode_override=row["path_hash_mode_override"],
last_read_at=row["last_read_at"],
favorite=bool(row["favorite"]),
)
for row in rows
]
@staticmethod
async def get_on_radio() -> list[Channel]:
"""Return channels currently marked as resident on the radio in the database."""
async def set_favorite(key: str, value: bool) -> bool:
"""Set or clear the favorite flag for a channel. Returns True if row was found."""
cursor = await db.conn.execute(
"""
SELECT key, name, is_hashtag, on_radio, flood_scope_override, last_read_at
FROM channels
WHERE on_radio = 1
ORDER BY name
"""
"UPDATE channels SET favorite = ? WHERE key = ?",
(1 if value else 0, key.upper()),
)
rows = await cursor.fetchall()
return [
Channel(
key=row["key"],
name=row["name"],
is_hashtag=bool(row["is_hashtag"]),
on_radio=bool(row["on_radio"]),
flood_scope_override=row["flood_scope_override"],
last_read_at=row["last_read_at"],
)
for row in rows
]
await db.conn.commit()
return cursor.rowcount > 0
@staticmethod
async def delete(key: str) -> None:
@@ -123,6 +113,16 @@ class ChannelRepository:
await db.conn.commit()
return cursor.rowcount > 0
@staticmethod
async def update_path_hash_mode_override(key: str, path_hash_mode_override: int | None) -> bool:
"""Set or clear a channel's path hash mode override."""
cursor = await db.conn.execute(
"UPDATE channels SET path_hash_mode_override = ? WHERE key = ?",
(path_hash_mode_override, key.upper()),
)
await db.conn.commit()
return cursor.rowcount > 0
@staticmethod
async def mark_all_read(timestamp: int) -> None:
"""Mark all channels as read at the given timestamp."""
+22 -6
View File
@@ -170,6 +170,7 @@ class ContactRepository:
lon=row["lon"],
last_seen=row["last_seen"],
on_radio=bool(row["on_radio"]),
favorite=bool(row["favorite"]) if "favorite" in available_columns else False,
last_contacted=row["last_contacted"],
last_read_at=row["last_read_at"],
first_seen=row["first_seen"],
@@ -392,15 +393,30 @@ class ContactRepository:
)
await db.conn.commit()
@staticmethod
async def get_favorites() -> list[Contact]:
"""Return all contacts marked as favorite."""
cursor = await db.conn.execute(
"SELECT * FROM contacts WHERE favorite = 1 AND LENGTH(public_key) = 64"
)
rows = await cursor.fetchall()
return [ContactRepository._row_to_contact(row) for row in rows]
@staticmethod
async def set_favorite(public_key: str, value: bool) -> None:
"""Set or clear the favorite flag for a contact."""
await db.conn.execute(
"UPDATE contacts SET favorite = ? WHERE public_key = ?",
(1 if value else 0, public_key.lower()),
)
await db.conn.commit()
@staticmethod
async def delete(public_key: str) -> None:
normalized = public_key.lower()
await db.conn.execute(
"DELETE FROM contact_name_history WHERE public_key = ?", (normalized,)
)
await db.conn.execute(
"DELETE FROM contact_advert_paths WHERE public_key = ?", (normalized,)
)
# contact_name_history and contact_advert_paths cascade via FK.
# Messages are intentionally preserved so history re-surfaces
# if the contact is re-added later.
await db.conn.execute("DELETE FROM contacts WHERE public_key = ?", (normalized,))
await db.conn.commit()
+45 -16
View File
@@ -29,8 +29,7 @@ class MessageRepository:
def _contact_activity_filter(public_key: str) -> tuple[str, list[Any]]:
lower_key = public_key.lower()
return (
"((type = 'PRIV' AND LOWER(conversation_key) = ?)"
" OR (type = 'CHAN' AND LOWER(sender_key) = ?))",
"((type = 'PRIV' AND conversation_key = ?) OR (type = 'CHAN' AND sender_key = ?))",
[lower_key, lower_key],
)
@@ -58,6 +57,8 @@ class MessageRepository:
sender_timestamp: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
txt_type: int = 0,
signature: str | None = None,
outgoing: bool = False,
@@ -79,8 +80,15 @@ class MessageRepository:
entry: dict = {"path": path, "received_at": received_at}
if path_len is not None:
entry["path_len"] = path_len
if rssi is not None:
entry["rssi"] = rssi
if snr is not None:
entry["snr"] = snr
paths_json = json.dumps([entry])
# Normalize sender_key to lowercase so queries can match without LOWER().
normalized_sender_key = sender_key.lower() if sender_key else sender_key
cursor = await db.conn.execute(
"""
INSERT OR IGNORE INTO messages (type, conversation_key, text, sender_timestamp,
@@ -99,7 +107,7 @@ class MessageRepository:
signature,
outgoing,
sender_name,
sender_key,
normalized_sender_key,
),
)
await db.conn.commit()
@@ -114,6 +122,8 @@ class MessageRepository:
path: str,
received_at: int | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
) -> list[MessagePath]:
"""Add a new path to an existing message.
@@ -127,6 +137,10 @@ class MessageRepository:
entry: dict = {"path": path, "received_at": ts}
if path_len is not None:
entry["path_len"] = path_len
if rssi is not None:
entry["rssi"] = rssi
if snr is not None:
entry["snr"] = snr
new_entry = json.dumps(entry)
await db.conn.execute(
"""UPDATE messages SET paths = json_insert(
@@ -259,10 +273,10 @@ class MessageRepository:
if MessageRepository._looks_like_hex_prefix(value):
if len(value) == 32:
clause += " OR UPPER(messages.conversation_key) = ?"
clause += " OR messages.conversation_key = ?"
params.append(value.upper())
else:
clause += " OR UPPER(messages.conversation_key) LIKE ? ESCAPE '\\'"
clause += " OR messages.conversation_key LIKE ? ESCAPE '\\'"
params.append(f"{MessageRepository._escape_like(value.upper())}%")
clause += "))"
@@ -281,13 +295,13 @@ class MessageRepository:
priv_key_clause: str
chan_key_clause: str
if len(value) == 64:
priv_key_clause = "LOWER(messages.conversation_key) = ?"
chan_key_clause = "LOWER(sender_key) = ?"
priv_key_clause = "messages.conversation_key = ?"
chan_key_clause = "sender_key = ?"
params.extend([lower_value, lower_value])
else:
escaped_prefix = f"{MessageRepository._escape_like(lower_value)}%"
priv_key_clause = "LOWER(messages.conversation_key) LIKE ? ESCAPE '\\'"
chan_key_clause = "LOWER(sender_key) LIKE ? ESCAPE '\\'"
priv_key_clause = "messages.conversation_key LIKE ? ESCAPE '\\'"
chan_key_clause = "sender_key LIKE ? ESCAPE '\\'"
params.extend([escaped_prefix, escaped_prefix])
clause += (
@@ -311,12 +325,12 @@ class MessageRepository:
if blocked_keys:
placeholders = ",".join("?" for _ in blocked_keys)
blocked_matchers.append(
f"({prefix}type = 'PRIV' AND LOWER({prefix}conversation_key) IN ({placeholders}))"
f"({prefix}type = 'PRIV' AND {prefix}conversation_key IN ({placeholders}))"
)
params.extend(blocked_keys)
blocked_matchers.append(
f"({prefix}type = 'CHAN' AND {prefix}sender_key IS NOT NULL"
f" AND LOWER({prefix}sender_key) IN ({placeholders}))"
f" AND {prefix}sender_key IN ({placeholders}))"
)
params.extend(blocked_keys)
@@ -383,9 +397,9 @@ class MessageRepository:
query = (
f"SELECT {MessageRepository._message_select('messages')} FROM messages "
"LEFT JOIN contacts ON messages.type = 'PRIV' "
"AND LOWER(messages.conversation_key) = LOWER(contacts.public_key) "
"AND messages.conversation_key = contacts.public_key "
"LEFT JOIN channels ON messages.type = 'CHAN' "
"AND UPPER(messages.conversation_key) = UPPER(channels.key) "
"AND messages.conversation_key = channels.key "
"WHERE 1=1"
)
params: list[Any] = []
@@ -673,7 +687,7 @@ class MessageRepository:
ELSE 0
END) > 0 as has_mention
FROM messages m
JOIN contacts ct ON m.conversation_key = ct.public_key
LEFT JOIN contacts ct ON m.conversation_key = ct.public_key
WHERE m.type = 'PRIV' AND m.outgoing = 0
AND m.received_at > COALESCE(ct.last_read_at, 0)
{blocked_sql}
@@ -784,12 +798,14 @@ class MessageRepository:
@staticmethod
async def get_channel_stats(conversation_key: str) -> dict:
"""Get channel message statistics: time-windowed counts, first message, unique senders, top senders.
"""Get channel message statistics: time-windowed counts, first message, unique senders, top senders, path hash widths.
Returns a dict with message_counts, first_message_at, unique_sender_count, top_senders_24h.
Returns a dict with message_counts, first_message_at, unique_sender_count, top_senders_24h, path_hash_width_24h.
"""
import time as _time
from app.path_utils import bucket_path_hash_widths
now = int(_time.time())
t_1h = now - 3600
t_24h = now - 86400
@@ -841,11 +857,24 @@ class MessageRepository:
for r in top_rows
]
# Path hash width distribution for last 24h (in-Python parse of raw packet envelopes)
cursor3 = await db.conn.execute(
"""
SELECT rp.data FROM raw_packets rp
JOIN messages m ON rp.message_id = m.id
WHERE m.type = 'CHAN' AND m.conversation_key = ?
AND rp.timestamp >= ?
""",
(conversation_key, t_24h),
)
path_hash_width_24h = await bucket_path_hash_widths(cursor3)
return {
"message_counts": message_counts,
"first_message_at": row["first_message_at"],
"unique_sender_count": row["unique_sender_count"] or 0,
"top_senders_24h": top_senders,
"path_hash_width_24h": path_hash_width_24h,
}
@staticmethod
+26 -50
View File
@@ -1,5 +1,4 @@
import logging
import sqlite3
import time
from collections.abc import AsyncIterator
from hashlib import sha256
@@ -35,46 +34,23 @@ class RawPacketRepository:
# For malformed packets, hash the full data
payload_hash = sha256(data).digest()
# Check if this payload already exists
cursor = await db.conn.execute(
"INSERT OR IGNORE INTO raw_packets (timestamp, data, payload_hash) VALUES (?, ?, ?)",
(ts, data, payload_hash),
)
await db.conn.commit()
if cursor.rowcount > 0:
assert cursor.lastrowid is not None
return (cursor.lastrowid, True)
# Duplicate payload — look up the existing row.
cursor = await db.conn.execute(
"SELECT id FROM raw_packets WHERE payload_hash = ?", (payload_hash,)
)
existing = await cursor.fetchone()
if existing:
# Duplicate - return existing packet ID
logger.debug(
"Duplicate payload detected (hash=%s..., existing_id=%d)",
payload_hash.hex()[:12],
existing["id"],
)
return (existing["id"], False)
# New packet - insert with hash
try:
cursor = await db.conn.execute(
"INSERT INTO raw_packets (timestamp, data, payload_hash) VALUES (?, ?, ?)",
(ts, data, payload_hash),
)
await db.conn.commit()
assert cursor.lastrowid is not None # INSERT always returns a row ID
return (cursor.lastrowid, True)
except sqlite3.IntegrityError:
# Race condition: another insert with same payload_hash happened between
# our SELECT and INSERT. This is expected for duplicate packets arriving
# close together. Query again to get the existing ID.
logger.debug(
"Duplicate packet detected via race condition (payload_hash=%s), dropping",
payload_hash.hex()[:16],
)
cursor = await db.conn.execute(
"SELECT id FROM raw_packets WHERE payload_hash = ?", (payload_hash,)
)
existing = await cursor.fetchone()
if existing:
return (existing["id"], False)
# This shouldn't happen, but if it does, re-raise
raise
assert existing is not None
return (existing["id"], False)
@staticmethod
async def get_undecrypted_count() -> int:
@@ -95,13 +71,22 @@ class RawPacketRepository:
return row["oldest"] if row and row["oldest"] is not None else None
@staticmethod
async def get_all_undecrypted() -> list[tuple[int, bytes, int]]:
"""Get all undecrypted packets as (id, data, timestamp) tuples."""
async def stream_all_undecrypted(
batch_size: int = UNDECRYPTED_PACKET_BATCH_SIZE,
) -> AsyncIterator[tuple[int, bytes, int]]:
"""Yield all undecrypted packets as (id, data, timestamp) in bounded batches."""
cursor = await db.conn.execute(
"SELECT id, data, timestamp FROM raw_packets WHERE message_id IS NULL ORDER BY timestamp ASC"
)
rows = await cursor.fetchall()
return [(row["id"], bytes(row["data"]), row["timestamp"]) for row in rows]
try:
while True:
rows = await cursor.fetchmany(batch_size)
if not rows:
break
for row in rows:
yield (row["id"], bytes(row["data"]), row["timestamp"])
finally:
await cursor.close()
@staticmethod
async def stream_undecrypted_text_messages(
@@ -187,12 +172,3 @@ class RawPacketRepository:
cursor = await db.conn.execute("DELETE FROM raw_packets WHERE message_id IS NOT NULL")
await db.conn.commit()
return cursor.rowcount
@staticmethod
async def get_undecrypted_text_messages() -> list[tuple[int, bytes, int]]:
"""Get all undecrypted TEXT_MESSAGE packets as (id, data, timestamp) tuples.
Filters raw packets to only include those with PayloadType.TEXT_MESSAGE (0x02).
These are direct messages that can be decrypted with contact ECDH keys.
"""
return [packet async for packet in RawPacketRepository.stream_undecrypted_text_messages()]
+34 -139
View File
@@ -1,11 +1,11 @@
import json
import logging
import time
from typing import Any, Literal
from typing import Any
from app.database import db
from app.models import AppSettings, Favorite
from app.path_utils import parse_packet_envelope
from app.models import AppSettings
from app.path_utils import bucket_path_hash_widths
logger = logging.getLogger(__name__)
@@ -26,10 +26,11 @@ class AppSettingsRepository:
"""
cursor = await db.conn.execute(
"""
SELECT max_radio_contacts, favorites, auto_decrypt_dm_on_advert,
sidebar_sort_order, last_message_times, preferences_migrated,
SELECT max_radio_contacts, auto_decrypt_dm_on_advert,
last_message_times,
advert_interval, last_advert_time, flood_scope,
blocked_keys, blocked_names, discovery_blocked_types
blocked_keys, blocked_names, discovery_blocked_types,
tracked_telemetry_repeaters, auto_resend_channel
FROM app_settings WHERE id = 1
"""
)
@@ -39,20 +40,6 @@ class AppSettingsRepository:
# Should not happen after migration, but handle gracefully
return AppSettings()
# Parse favorites JSON
favorites = []
if row["favorites"]:
try:
favorites_data = json.loads(row["favorites"])
favorites = [Favorite(**f) for f in favorites_data]
except (json.JSONDecodeError, TypeError, KeyError) as e:
logger.warning(
"Failed to parse favorites JSON, using empty list: %s (data=%r)",
e,
row["favorites"][:100] if row["favorites"] else None,
)
favorites = []
# Parse last_message_times JSON
last_message_times: dict[str, int] = {}
if row["last_message_times"]:
@@ -89,40 +76,48 @@ class AppSettingsRepository:
except (json.JSONDecodeError, TypeError):
discovery_blocked_types = []
# Validate sidebar_sort_order (fallback to "recent" if invalid)
sort_order = row["sidebar_sort_order"]
if sort_order not in ("recent", "alpha"):
sort_order = "recent"
# Parse tracked_telemetry_repeaters JSON
tracked_telemetry_repeaters: list[str] = []
try:
raw_tracked = row["tracked_telemetry_repeaters"]
if raw_tracked:
tracked_telemetry_repeaters = json.loads(raw_tracked)
except (json.JSONDecodeError, TypeError, KeyError):
tracked_telemetry_repeaters = []
# Parse auto_resend_channel boolean
try:
auto_resend_channel = bool(row["auto_resend_channel"])
except (KeyError, TypeError):
auto_resend_channel = False
return AppSettings(
max_radio_contacts=row["max_radio_contacts"],
favorites=favorites,
auto_decrypt_dm_on_advert=bool(row["auto_decrypt_dm_on_advert"]),
sidebar_sort_order=sort_order,
last_message_times=last_message_times,
preferences_migrated=bool(row["preferences_migrated"]),
advert_interval=row["advert_interval"] or 0,
last_advert_time=row["last_advert_time"] or 0,
flood_scope=row["flood_scope"] or "",
blocked_keys=blocked_keys,
blocked_names=blocked_names,
discovery_blocked_types=discovery_blocked_types,
tracked_telemetry_repeaters=tracked_telemetry_repeaters,
auto_resend_channel=auto_resend_channel,
)
@staticmethod
async def update(
max_radio_contacts: int | None = None,
favorites: list[Favorite] | None = None,
auto_decrypt_dm_on_advert: bool | None = None,
sidebar_sort_order: str | None = None,
last_message_times: dict[str, int] | None = None,
preferences_migrated: bool | None = None,
advert_interval: int | None = None,
last_advert_time: int | None = None,
flood_scope: str | None = None,
blocked_keys: list[str] | None = None,
blocked_names: list[str] | None = None,
discovery_blocked_types: list[int] | None = None,
tracked_telemetry_repeaters: list[str] | None = None,
auto_resend_channel: bool | None = None,
) -> AppSettings:
"""Update app settings. Only provided fields are updated."""
updates = []
@@ -132,27 +127,14 @@ class AppSettingsRepository:
updates.append("max_radio_contacts = ?")
params.append(max_radio_contacts)
if favorites is not None:
updates.append("favorites = ?")
favorites_json = json.dumps([f.model_dump() for f in favorites])
params.append(favorites_json)
if auto_decrypt_dm_on_advert is not None:
updates.append("auto_decrypt_dm_on_advert = ?")
params.append(1 if auto_decrypt_dm_on_advert else 0)
if sidebar_sort_order is not None:
updates.append("sidebar_sort_order = ?")
params.append(sidebar_sort_order)
if last_message_times is not None:
updates.append("last_message_times = ?")
params.append(json.dumps(last_message_times))
if preferences_migrated is not None:
updates.append("preferences_migrated = ?")
params.append(1 if preferences_migrated else 0)
if advert_interval is not None:
updates.append("advert_interval = ?")
params.append(advert_interval)
@@ -177,6 +159,14 @@ class AppSettingsRepository:
updates.append("discovery_blocked_types = ?")
params.append(json.dumps(discovery_blocked_types))
if tracked_telemetry_repeaters is not None:
updates.append("tracked_telemetry_repeaters = ?")
params.append(json.dumps(tracked_telemetry_repeaters))
if auto_resend_channel is not None:
updates.append("auto_resend_channel = ?")
params.append(1 if auto_resend_channel else 0)
if updates:
query = f"UPDATE app_settings SET {', '.join(updates)} WHERE id = 1"
await db.conn.execute(query, params)
@@ -184,27 +174,6 @@ class AppSettingsRepository:
return await AppSettingsRepository.get()
@staticmethod
async def add_favorite(fav_type: Literal["channel", "contact"], fav_id: str) -> AppSettings:
"""Add a favorite, avoiding duplicates."""
settings = await AppSettingsRepository.get()
# Check if already favorited
if any(f.type == fav_type and f.id == fav_id for f in settings.favorites):
return settings
new_favorites = settings.favorites + [Favorite(type=fav_type, id=fav_id)]
return await AppSettingsRepository.update(favorites=new_favorites)
@staticmethod
async def remove_favorite(fav_type: Literal["channel", "contact"], fav_id: str) -> AppSettings:
"""Remove a favorite."""
settings = await AppSettingsRepository.get()
new_favorites = [
f for f in settings.favorites if not (f.type == fav_type and f.id == fav_id)
]
return await AppSettingsRepository.update(favorites=new_favorites)
@staticmethod
async def toggle_blocked_key(key: str) -> AppSettings:
"""Toggle a public key in the blocked list. Keys are normalized to lowercase."""
@@ -226,39 +195,6 @@ class AppSettingsRepository:
new_names = settings.blocked_names + [name]
return await AppSettingsRepository.update(blocked_names=new_names)
@staticmethod
async def migrate_preferences_from_frontend(
favorites: list[dict],
sort_order: str,
last_message_times: dict[str, int],
) -> tuple[AppSettings, bool]:
"""Migrate all preferences from frontend localStorage.
This is a one-time migration. If already migrated, returns current settings
without overwriting. Returns (settings, did_migrate) tuple.
"""
settings = await AppSettingsRepository.get()
if settings.preferences_migrated:
# Already migrated, don't overwrite
return settings, False
# Convert frontend favorites format to Favorite objects
new_favorites = []
for f in favorites:
if f.get("type") in ("channel", "contact") and f.get("id"):
new_favorites.append(Favorite(type=f["type"], id=f["id"]))
# Update with migrated preferences and mark as migrated
settings = await AppSettingsRepository.update(
favorites=new_favorites,
sidebar_sort_order=sort_order if sort_order in ("recent", "alpha") else "recent",
last_message_times=last_message_times,
preferences_migrated=True,
)
return settings, True
class StatisticsRepository:
@staticmethod
@@ -346,48 +282,7 @@ class StatisticsRepository:
"SELECT data FROM raw_packets WHERE timestamp >= ?",
(now - SECONDS_24H,),
)
single_byte = 0
double_byte = 0
triple_byte = 0
while True:
rows = await cursor.fetchmany(RAW_PACKET_STATS_BATCH_SIZE)
if not rows:
break
for row in rows:
envelope = parse_packet_envelope(bytes(row["data"]))
if envelope is None:
continue
if envelope.hash_size == 1:
single_byte += 1
elif envelope.hash_size == 2:
double_byte += 1
elif envelope.hash_size == 3:
triple_byte += 1
total_packets = single_byte + double_byte + triple_byte
if total_packets == 0:
return {
"total_packets": 0,
"single_byte": 0,
"double_byte": 0,
"triple_byte": 0,
"single_byte_pct": 0.0,
"double_byte_pct": 0.0,
"triple_byte_pct": 0.0,
}
return {
"total_packets": total_packets,
"single_byte": single_byte,
"double_byte": double_byte,
"triple_byte": triple_byte,
"single_byte_pct": (single_byte / total_packets) * 100,
"double_byte_pct": (double_byte / total_packets) * 100,
"triple_byte_pct": (triple_byte / total_packets) * 100,
}
return await bucket_path_hash_widths(cursor, batch_size=RAW_PACKET_STATS_BATCH_SIZE)
@staticmethod
async def get_all() -> dict:
+39 -3
View File
@@ -60,6 +60,15 @@ class ChannelFloodScopeOverrideRequest(BaseModel):
)
class ChannelPathHashModeOverrideRequest(BaseModel):
path_hash_mode_override: int | None = Field(
default=None,
ge=0,
le=2,
description="Path hash mode override (0=1-byte, 1=2-byte, 2=3-byte, null = use radio default)",
)
def _derive_channel_identity(
requested_name: str,
request_key: str | None = None,
@@ -122,8 +131,7 @@ def _normalize_bulk_hashtag_name(name: str) -> str | None:
async def _run_historical_channel_decryption_for_channels(
channels: list[tuple[bytes, str, str]],
) -> None:
packets = await RawPacketRepository.get_all_undecrypted()
total = len(packets)
total = await RawPacketRepository.get_undecrypted_count()
decrypted_count = 0
matched_channel_names: set[str] = set()
@@ -137,7 +145,11 @@ async def _run_historical_channel_decryption_for_channels(
len(channels),
)
for packet_id, packet_data, packet_timestamp in packets:
async for (
packet_id,
packet_data,
packet_timestamp,
) in RawPacketRepository.stream_all_undecrypted():
packet_info = parse_packet(packet_data)
path_hex = packet_info.path.hex() if packet_info else None
path_len = packet_info.path_length if packet_info else None
@@ -203,6 +215,7 @@ async def get_channel_detail(key: str) -> ChannelDetail:
first_message_at=stats["first_message_at"],
unique_sender_count=stats["unique_sender_count"],
top_senders_24h=[ChannelTopSender(**s) for s in stats["top_senders_24h"]],
path_hash_width_24h=stats["path_hash_width_24h"],
)
@@ -345,6 +358,29 @@ async def set_channel_flood_scope_override(
return refreshed
@router.post("/{key}/path-hash-mode-override", response_model=Channel)
async def set_channel_path_hash_mode_override(
key: str, request: ChannelPathHashModeOverrideRequest
) -> Channel:
"""Set or clear a per-channel path hash mode override."""
channel = await ChannelRepository.get_by_key(key)
if not channel:
raise HTTPException(status_code=404, detail="Channel not found")
updated = await ChannelRepository.update_path_hash_mode_override(
channel.key, request.path_hash_mode_override
)
if not updated:
raise HTTPException(status_code=500, detail="Failed to update path-hash-mode override")
refreshed = await ChannelRepository.get_by_key(channel.key)
if refreshed is None:
raise HTTPException(status_code=500, detail="Channel disappeared after update")
broadcast_event("channel", refreshed.model_dump())
return refreshed
@router.delete("/{key}")
async def delete_channel(key: str) -> dict:
"""Delete a channel from the database by key.
+2 -3
View File
@@ -8,7 +8,6 @@ from fastapi import APIRouter, BackgroundTasks, HTTPException, Query
from meshcore import EventType
from pydantic import BaseModel, Field
from app.dependencies import require_connected
from app.models import (
Contact,
ContactActiveRoom,
@@ -428,7 +427,7 @@ async def request_trace(public_key: str) -> TraceResponse:
(no intermediate repeaters). This uses TRACE's dedicated width flags rather
than the radio's normal path_hash_mode setting.
"""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
@@ -487,7 +486,7 @@ async def request_trace(public_key: str) -> TraceResponse:
@router.post("/{public_key}/path-discovery", response_model=PathDiscoveryResponse)
async def request_path_discovery(public_key: str) -> PathDiscoveryResponse:
"""Discover the current forward and return paths to a known contact."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
pubkey_prefix = contact.public_key[:12]
+3 -4
View File
@@ -3,7 +3,6 @@ import time
from fastapi import APIRouter, HTTPException, Query
from app.dependencies import require_connected
from app.event_handlers import track_pending_ack
from app.models import (
Message,
@@ -89,7 +88,7 @@ async def list_messages(
@router.post("/direct", response_model=Message)
async def send_direct_message(request: SendDirectMessageRequest) -> Message:
"""Send a direct message to a contact."""
require_connected()
radio_manager.require_connected()
# First check our database for the contact
from app.repository import ContactRepository
@@ -136,7 +135,7 @@ TEMP_RADIO_SLOT = 0
@router.post("/channel", response_model=Message)
async def send_channel_message(request: SendChannelMessageRequest) -> Message:
"""Send a message to a channel."""
require_connected()
radio_manager.require_connected()
# Get channel info from our database
from app.repository import ChannelRepository
@@ -189,7 +188,7 @@ async def resend_channel_message(
When new_timestamp=True: resend with a fresh timestamp so repeaters treat it as a
new packet. Creates a new message row in the database. No time window restriction.
"""
require_connected()
radio_manager.require_connected()
from app.repository import ChannelRepository
+6 -3
View File
@@ -49,8 +49,7 @@ async def _run_historical_channel_decryption(
channel_key_bytes: bytes, channel_key_hex: str, display_name: str | None = None
) -> None:
"""Background task to decrypt historical packets with a channel key."""
packets = await RawPacketRepository.get_all_undecrypted()
total = len(packets)
total = await RawPacketRepository.get_undecrypted_count()
decrypted_count = 0
if total == 0:
@@ -59,7 +58,11 @@ async def _run_historical_channel_decryption(
logger.info("Starting historical channel decryption of %d packets", total)
for packet_id, packet_data, packet_timestamp in packets:
async for (
packet_id,
packet_data,
packet_timestamp,
) in RawPacketRepository.stream_all_undecrypted():
result = try_decrypt_packet_with_channel_key(packet_data, channel_key_bytes)
if result is not None:
+7 -11
View File
@@ -9,7 +9,6 @@ from fastapi import APIRouter, HTTPException
from meshcore import EventType
from pydantic import BaseModel, Field
from app.dependencies import require_connected
from app.models import (
CONTACT_TYPE_REPEATER,
ContactUpsert,
@@ -24,6 +23,7 @@ from app.models import (
from app.radio_sync import send_advertisement as do_send_advertisement
from app.radio_sync import sync_radio_time
from app.repository import ContactRepository
from app.routers.server_control import _monotonic
from app.services.contact_reconciliation import (
promote_prefix_contacts_for_contact,
reconcile_contact_messages,
@@ -136,10 +136,6 @@ class RadioAdvertiseRequest(BaseModel):
)
def _monotonic() -> float:
return time.monotonic()
def _better_signal(first: float | None, second: float | None) -> float | None:
if first is None:
return second
@@ -338,7 +334,7 @@ async def _resolve_trace_hops(
@router.get("/config", response_model=RadioConfigResponse)
async def get_radio_config() -> RadioConfigResponse:
"""Get the current radio configuration."""
mc = require_connected()
mc = radio_manager.require_connected()
info = mc.self_info
if not info:
@@ -370,7 +366,7 @@ async def get_radio_config() -> RadioConfigResponse:
@router.patch("/config", response_model=RadioConfigResponse)
async def update_radio_config(update: RadioConfigUpdate) -> RadioConfigResponse:
"""Update radio configuration. Only provided fields will be updated."""
require_connected()
radio_manager.require_connected()
async with radio_manager.radio_operation("update_radio_config") as mc:
try:
@@ -392,7 +388,7 @@ async def update_radio_config(update: RadioConfigUpdate) -> RadioConfigResponse:
@router.put("/private-key")
async def set_private_key(update: PrivateKeyUpdate) -> dict:
"""Set the radio's private key. This is write-only."""
require_connected()
radio_manager.require_connected()
try:
key_bytes = bytes.fromhex(update.private_key)
@@ -426,7 +422,7 @@ async def send_advertisement(request: RadioAdvertiseRequest | None = None) -> di
Returns:
status: "ok" if sent successfully
"""
require_connected()
radio_manager.require_connected()
mode: RadioAdvertMode = request.mode if request is not None else "flood"
logger.info("Sending %s advertisement", mode.replace("_", "-"))
@@ -442,7 +438,7 @@ async def send_advertisement(request: RadioAdvertiseRequest | None = None) -> di
@router.post("/discover", response_model=RadioDiscoveryResponse)
async def discover_mesh(request: RadioDiscoveryRequest) -> RadioDiscoveryResponse:
"""Run a short node-discovery sweep from the local radio."""
require_connected()
radio_manager.require_connected()
target_bits = _DISCOVERY_TARGET_BITS[request.target]
tag = random.randint(1, 0xFFFFFFFF)
@@ -509,7 +505,7 @@ async def discover_mesh(request: RadioDiscoveryRequest) -> RadioDiscoveryRespons
@router.post("/trace", response_model=RadioTraceResponse)
async def trace_path(request: RadioTraceRequest) -> RadioTraceResponse:
"""Send a multi-hop trace loop through known repeaters and back to the local radio."""
require_connected()
radio_manager.require_connected()
trace_nodes, requested_hashes = await _resolve_trace_hops(request.hops, request.hop_hash_bytes)
tag = random.randint(1, 0xFFFFFFFF)
+10 -16
View File
@@ -3,7 +3,6 @@ import time
from fastapi import APIRouter, HTTPException
from app.dependencies import require_connected
from app.models import (
CONTACT_TYPE_REPEATER,
AclEntry,
@@ -28,7 +27,6 @@ from app.repository import ContactRepository, RepeaterTelemetryRepository
from app.routers.contacts import _ensure_on_radio, _resolve_contact_or_404
from app.routers.server_control import (
batch_cli_fetch,
extract_response_text,
prepare_authenticated_contact_connection,
require_server_capable_contact,
send_contact_cli_command,
@@ -48,10 +46,6 @@ router = APIRouter(prefix="/contacts", tags=["repeaters"])
REPEATER_LOGIN_RESPONSE_TIMEOUT_SECONDS = 5.0
def _extract_response_text(event) -> str:
return extract_response_text(event)
async def prepare_repeater_connection(mc, contact: Contact, password: str) -> RepeaterLoginResponse:
return await prepare_authenticated_contact_connection(
mc,
@@ -80,7 +74,7 @@ def _require_repeater(contact: Contact) -> None:
@router.post("/{public_key}/repeater/login", response_model=RepeaterLoginResponse)
async def repeater_login(public_key: str, request: RepeaterLoginRequest) -> RepeaterLoginResponse:
"""Attempt repeater login and report whether auth was confirmed."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -95,7 +89,7 @@ async def repeater_login(public_key: str, request: RepeaterLoginRequest) -> Repe
@router.post("/{public_key}/repeater/status", response_model=RepeaterStatusResponse)
async def repeater_status(public_key: str) -> RepeaterStatusResponse:
"""Fetch status telemetry from a repeater (single attempt, 10s timeout)."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -170,7 +164,7 @@ async def repeater_telemetry_history(public_key: str) -> list[TelemetryHistoryEn
@router.post("/{public_key}/repeater/lpp-telemetry", response_model=RepeaterLppTelemetryResponse)
async def repeater_lpp_telemetry(public_key: str) -> RepeaterLppTelemetryResponse:
"""Fetch CayenneLPP sensor telemetry from a repeater (single attempt, 10s timeout)."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -199,7 +193,7 @@ async def repeater_lpp_telemetry(public_key: str) -> RepeaterLppTelemetryRespons
@router.post("/{public_key}/repeater/neighbors", response_model=RepeaterNeighborsResponse)
async def repeater_neighbors(public_key: str) -> RepeaterNeighborsResponse:
"""Fetch neighbors from a repeater (single attempt, 10s timeout)."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -233,7 +227,7 @@ async def repeater_neighbors(public_key: str) -> RepeaterNeighborsResponse:
@router.post("/{public_key}/repeater/acl", response_model=RepeaterAclResponse)
async def repeater_acl(public_key: str) -> RepeaterAclResponse:
"""Fetch ACL from a repeater (single attempt, 10s timeout)."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -274,7 +268,7 @@ async def _batch_cli_fetch(
@router.post("/{public_key}/repeater/node-info", response_model=RepeaterNodeInfoResponse)
async def repeater_node_info(public_key: str) -> RepeaterNodeInfoResponse:
"""Fetch repeater identity/location info via a small CLI batch."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -294,7 +288,7 @@ async def repeater_node_info(public_key: str) -> RepeaterNodeInfoResponse:
@router.post("/{public_key}/repeater/radio-settings", response_model=RepeaterRadioSettingsResponse)
async def repeater_radio_settings(public_key: str) -> RepeaterRadioSettingsResponse:
"""Fetch radio settings from a repeater via radio/config CLI commands."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -318,7 +312,7 @@ async def repeater_radio_settings(public_key: str) -> RepeaterRadioSettingsRespo
)
async def repeater_advert_intervals(public_key: str) -> RepeaterAdvertIntervalsResponse:
"""Fetch advertisement intervals from a repeater via CLI commands."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -336,7 +330,7 @@ async def repeater_advert_intervals(public_key: str) -> RepeaterAdvertIntervalsR
@router.post("/{public_key}/repeater/owner-info", response_model=RepeaterOwnerInfoResponse)
async def repeater_owner_info(public_key: str) -> RepeaterOwnerInfoResponse:
"""Fetch owner info and guest password from a repeater via CLI commands."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_repeater(contact)
@@ -354,7 +348,7 @@ async def repeater_owner_info(public_key: str) -> RepeaterOwnerInfoResponse:
@router.post("/{public_key}/command", response_model=CommandResponse)
async def send_repeater_command(public_key: str, request: CommandRequest) -> CommandResponse:
"""Send a CLI command to a repeater or room server."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
require_server_capable_contact(contact)
+4 -5
View File
@@ -1,6 +1,5 @@
from fastapi import APIRouter, HTTPException
from app.dependencies import require_connected
from app.models import (
CONTACT_TYPE_ROOM,
AclEntry,
@@ -28,7 +27,7 @@ def _require_room(contact) -> None:
@router.post("/{public_key}/room/login", response_model=RepeaterLoginResponse)
async def room_login(public_key: str, request: RepeaterLoginRequest) -> RepeaterLoginResponse:
"""Attempt room-server login and report whether auth was confirmed."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_room(contact)
@@ -48,7 +47,7 @@ async def room_login(public_key: str, request: RepeaterLoginRequest) -> Repeater
@router.post("/{public_key}/room/status", response_model=RepeaterStatusResponse)
async def room_status(public_key: str) -> RepeaterStatusResponse:
"""Fetch status telemetry from a room server."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_room(contact)
@@ -85,7 +84,7 @@ async def room_status(public_key: str) -> RepeaterStatusResponse:
@router.post("/{public_key}/room/lpp-telemetry", response_model=RepeaterLppTelemetryResponse)
async def room_lpp_telemetry(public_key: str) -> RepeaterLppTelemetryResponse:
"""Fetch CayenneLPP telemetry from a room server."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_room(contact)
@@ -114,7 +113,7 @@ async def room_lpp_telemetry(public_key: str) -> RepeaterLppTelemetryResponse:
@router.post("/{public_key}/room/acl", response_model=RepeaterAclResponse)
async def room_acl(public_key: str) -> RepeaterAclResponse:
"""Fetch ACL entries from a room server."""
require_connected()
radio_manager.require_connected()
contact = await _resolve_contact_or_404(public_key)
_require_room(contact)
+18 -11
View File
@@ -230,20 +230,27 @@ async def batch_cli_fetch(
operation_name: str,
commands: list[tuple[str, str]],
) -> dict[str, str | None]:
"""Send a batch of CLI commands to a server-capable contact and collect responses."""
"""Send a batch of CLI commands to a server-capable contact and collect responses.
Each command acquires and releases the radio lock independently so that
other operations (sends, syncs) can slip in between commands.
"""
results: dict[str, str | None] = {field: None for _, field in commands}
async with radio_manager.radio_operation(
operation_name,
pause_polling=True,
suspend_auto_fetch=True,
) as mc:
await _ensure_on_radio(mc, contact)
await asyncio.sleep(1.0)
for index, (cmd, field) in enumerate(commands):
if index > 0:
# Yield briefly so queued operations can acquire the lock.
await asyncio.sleep(0.25)
for index, (cmd, field) in enumerate(commands):
if index > 0:
await asyncio.sleep(1.0)
async with radio_manager.radio_operation(
operation_name,
pause_polling=True,
suspend_auto_fetch=True,
) as mc:
# Re-ensure contact is loaded each iteration; another operation
# may have evicted it while we didn't hold the lock.
await _ensure_on_radio(mc, contact)
await asyncio.sleep(1.0) # settle after add_contact
send_result = await mc.commands.send_cmd(contact.public_key, cmd)
if send_result.type == EventType.ERROR:
+94 -75
View File
@@ -2,16 +2,18 @@ import asyncio
import logging
from typing import Literal
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, Field
from app.models import AppSettings
from app.models import CONTACT_TYPE_REPEATER, AppSettings
from app.region_scope import normalize_region_scope
from app.repository import AppSettingsRepository
from app.repository import AppSettingsRepository, ChannelRepository, ContactRepository
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/settings", tags=["settings"])
MAX_TRACKED_TELEMETRY_REPEATERS = 8
class AppSettingsUpdate(BaseModel):
max_radio_contacts: int | None = Field(
@@ -27,10 +29,6 @@ class AppSettingsUpdate(BaseModel):
default=None,
description="Whether to attempt historical DM decryption on new contact advertisement",
)
sidebar_sort_order: Literal["recent", "alpha"] | None = Field(
default=None,
description="Sidebar sort order: 'recent' or 'alpha'",
)
advert_interval: int | None = Field(
default=None,
ge=0,
@@ -55,6 +53,10 @@ class AppSettingsUpdate(BaseModel):
"advertisements should not create new contacts"
),
)
auto_resend_channel: bool | None = Field(
default=None,
description="Auto-resend channel messages once if no echo heard within 2 seconds",
)
class BlockKeyRequest(BaseModel):
@@ -70,24 +72,23 @@ class FavoriteRequest(BaseModel):
id: str = Field(description="Channel key or contact public key")
class MigratePreferencesRequest(BaseModel):
favorites: list[FavoriteRequest] = Field(
default_factory=list,
description="List of favorites from localStorage",
)
sort_order: str = Field(
default="recent",
description="Sort order preference from localStorage",
)
last_message_times: dict[str, int] = Field(
default_factory=dict,
description="Map of conversation state keys to timestamps from localStorage",
)
class FavoriteToggleResponse(BaseModel):
type: Literal["channel", "contact"]
id: str
favorite: bool
class MigratePreferencesResponse(BaseModel):
migrated: bool = Field(description="Whether migration occurred (false if already migrated)")
settings: AppSettings = Field(description="Current settings after migration attempt")
class TrackedTelemetryRequest(BaseModel):
public_key: str = Field(description="Public key of the repeater to toggle tracking")
class TrackedTelemetryResponse(BaseModel):
tracked_telemetry_repeaters: list[str] = Field(
description="Current list of tracked repeater public keys"
)
names: dict[str, str] = Field(
description="Map of public key to display name for tracked repeaters"
)
@router.get("", response_model=AppSettings)
@@ -111,10 +112,6 @@ async def update_settings(update: AppSettingsUpdate) -> AppSettings:
logger.info("Updating auto_decrypt_dm_on_advert to %s", update.auto_decrypt_dm_on_advert)
kwargs["auto_decrypt_dm_on_advert"] = update.auto_decrypt_dm_on_advert
if update.sidebar_sort_order is not None:
logger.info("Updating sidebar_sort_order to %s", update.sidebar_sort_order)
kwargs["sidebar_sort_order"] = update.sidebar_sort_order
if update.advert_interval is not None:
# Enforce minimum 1-hour interval; 0 means disabled
interval = update.advert_interval
@@ -135,6 +132,10 @@ async def update_settings(update: AppSettingsUpdate) -> AppSettings:
valid = [t for t in update.discovery_blocked_types if t in (1, 2, 3, 4)]
kwargs["discovery_blocked_types"] = sorted(set(valid))
# Auto-resend channel
if update.auto_resend_channel is not None:
kwargs["auto_resend_channel"] = update.auto_resend_channel
# Flood scope
flood_scope_changed = False
if update.flood_scope is not None:
@@ -162,27 +163,30 @@ async def update_settings(update: AppSettingsUpdate) -> AppSettings:
return await AppSettingsRepository.get()
@router.post("/favorites/toggle", response_model=AppSettings)
async def toggle_favorite(request: FavoriteRequest) -> AppSettings:
@router.post("/favorites/toggle", response_model=FavoriteToggleResponse)
async def toggle_favorite(request: FavoriteRequest) -> FavoriteToggleResponse:
"""Toggle a conversation's favorite status."""
settings = await AppSettingsRepository.get()
is_favorited = any(f.type == request.type and f.id == request.id for f in settings.favorites)
if request.type == "contact":
contact = await ContactRepository.get_by_key(request.id)
if not contact:
raise HTTPException(status_code=404, detail="Contact not found")
new_value = not contact.favorite
await ContactRepository.set_favorite(request.id, new_value)
logger.info("%s contact favorite: %s", "Added" if new_value else "Removed", request.id[:12])
# When newly favorited, load to radio immediately for DM ACK support
if new_value:
from app.radio_sync import ensure_contact_on_radio
if is_favorited:
logger.info("Removing favorite: %s %s", request.type, request.id[:12])
result = await AppSettingsRepository.remove_favorite(request.type, request.id)
asyncio.create_task(ensure_contact_on_radio(request.id, force=True))
else:
logger.info("Adding favorite: %s %s", request.type, request.id[:12])
result = await AppSettingsRepository.add_favorite(request.type, request.id)
channel = await ChannelRepository.get_by_key(request.id)
if not channel:
raise HTTPException(status_code=404, detail="Channel not found")
new_value = not channel.favorite
await ChannelRepository.set_favorite(request.id, new_value)
logger.info("%s channel favorite: %s", "Added" if new_value else "Removed", request.id[:12])
# When a contact is newly favorited, load just that contact to the radio
# immediately so DM ACK support does not wait for the next maintenance cycle.
if request.type == "contact" and not is_favorited:
from app.radio_sync import ensure_contact_on_radio
asyncio.create_task(ensure_contact_on_radio(request.id, force=True))
return result
return FavoriteToggleResponse(type=request.type, id=request.id, favorite=new_value)
@router.post("/blocked-keys/toggle", response_model=AppSettings)
@@ -199,41 +203,56 @@ async def toggle_blocked_name(request: BlockNameRequest) -> AppSettings:
return await AppSettingsRepository.toggle_blocked_name(request.name)
@router.post("/migrate", response_model=MigratePreferencesResponse)
async def migrate_preferences(request: MigratePreferencesRequest) -> MigratePreferencesResponse:
"""Migrate all preferences from frontend localStorage to database.
@router.post("/tracked-telemetry/toggle", response_model=TrackedTelemetryResponse)
async def toggle_tracked_telemetry(request: TrackedTelemetryRequest) -> TrackedTelemetryResponse:
"""Toggle periodic telemetry collection for a repeater.
This is a one-time migration. If preferences have already been migrated,
this endpoint will not overwrite them and will return migrated=false.
Call this on frontend startup to ensure preferences are moved to the database.
After successful migration, the frontend should clear localStorage preferences.
Migrates:
- favorites (remoteterm-favorites)
- sort_order (remoteterm-sortOrder)
- last_message_times (remoteterm-lastMessageTime)
Max 8 repeaters may be tracked. Returns 409 if the limit is reached and
the requested repeater is not already tracked.
"""
# Convert to dict format for the repository method
frontend_favorites = [{"type": f.type, "id": f.id} for f in request.favorites]
key = request.public_key.lower()
settings = await AppSettingsRepository.get()
current = settings.tracked_telemetry_repeaters
settings, did_migrate = await AppSettingsRepository.migrate_preferences_from_frontend(
favorites=frontend_favorites,
sort_order=request.sort_order,
last_message_times=request.last_message_times,
)
async def _resolve_names(keys: list[str]) -> dict[str, str]:
names: dict[str, str] = {}
for k in keys:
contact = await ContactRepository.get_by_key(k)
names[k] = contact.name if contact and contact.name else k[:12]
return names
if did_migrate:
logger.info(
"Migrated preferences from frontend: %d favorites, sort_order=%s, %d message times",
len(frontend_favorites),
request.sort_order,
len(request.last_message_times),
if key in current:
# Remove
new_list = [k for k in current if k != key]
logger.info("Removing repeater %s from tracked telemetry", key[:12])
await AppSettingsRepository.update(tracked_telemetry_repeaters=new_list)
return TrackedTelemetryResponse(
tracked_telemetry_repeaters=new_list,
names=await _resolve_names(new_list),
)
else:
logger.debug("Preferences already migrated, skipping")
return MigratePreferencesResponse(
migrated=did_migrate,
settings=settings,
# Validate it's a repeater
contact = await ContactRepository.get_by_key(key)
if not contact:
raise HTTPException(status_code=404, detail="Contact not found")
if contact.type != CONTACT_TYPE_REPEATER:
raise HTTPException(status_code=400, detail="Contact is not a repeater")
if len(current) >= MAX_TRACKED_TELEMETRY_REPEATERS:
names = await _resolve_names(current)
raise HTTPException(
status_code=409,
detail={
"message": f"Limit of {MAX_TRACKED_TELEMETRY_REPEATERS} tracked repeaters reached",
"tracked_telemetry_repeaters": current,
"names": names,
},
)
new_list = current + [key]
logger.info("Adding repeater %s to tracked telemetry", key[:12])
await AppSettingsRepository.update(tracked_telemetry_repeaters=new_list)
return TrackedTelemetryResponse(
tracked_telemetry_repeaters=new_list,
names=await _resolve_names(new_list),
)
+1 -6
View File
@@ -1,12 +1,7 @@
"""Shared direct-message ACK application logic."""
from collections.abc import Callable
from typing import Any
from app.services import dm_ack_tracker
from app.services.messages import increment_ack_and_broadcast
BroadcastFn = Callable[..., Any]
from app.services.messages import BroadcastFn, increment_ack_and_broadcast
async def apply_dm_ack_code(ack_code: str, *, broadcast_fn: BroadcastFn) -> bool:
+17 -5
View File
@@ -1,9 +1,8 @@
import asyncio
import logging
import time
from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING
from app.models import CONTACT_TYPE_REPEATER, CONTACT_TYPE_ROOM, Contact, ContactUpsert, Message
from app.repository import (
@@ -14,6 +13,7 @@ from app.repository import (
)
from app.services.contact_reconciliation import claim_prefix_messages_for_contact
from app.services.messages import (
BroadcastFn,
broadcast_message,
build_message_model,
build_message_paths,
@@ -27,8 +27,6 @@ if TYPE_CHECKING:
from app.decoder import DecryptedDirectMessage
logger = logging.getLogger(__name__)
BroadcastFn = Callable[..., Any]
_decrypted_dm_store_lock = asyncio.Lock()
@@ -144,6 +142,8 @@ async def _store_direct_message(
received_at: int,
path: str | None,
path_len: int | None,
rssi: int | None = None,
snr: float | None = None,
outgoing: bool,
txt_type: int,
signature: str | None,
@@ -170,6 +170,8 @@ async def _store_direct_message(
path=path,
received_at=received_at,
path_len=path_len,
rssi=rssi,
snr=snr,
broadcast_fn=broadcast_fn,
)
return None
@@ -189,6 +191,8 @@ async def _store_direct_message(
path=path,
received_at=received_at,
path_len=path_len,
rssi=rssi,
snr=snr,
broadcast_fn=broadcast_fn,
)
return None
@@ -201,6 +205,8 @@ async def _store_direct_message(
received_at=received_at,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
txt_type=txt_type,
signature=signature,
outgoing=outgoing,
@@ -218,6 +224,8 @@ async def _store_direct_message(
path=path,
received_at=received_at,
path_len=path_len,
rssi=rssi,
snr=snr,
broadcast_fn=broadcast_fn,
)
return None
@@ -232,7 +240,7 @@ async def _store_direct_message(
text=text,
sender_timestamp=sender_timestamp,
received_at=received_at,
paths=build_message_paths(path, received_at, path_len),
paths=build_message_paths(path, received_at, path_len, rssi=rssi, snr=snr),
txt_type=txt_type,
signature=signature,
sender_key=sender_key,
@@ -261,6 +269,8 @@ async def ingest_decrypted_direct_message(
received_at: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
outgoing: bool = False,
realtime: bool = True,
broadcast_fn: BroadcastFn,
@@ -311,6 +321,8 @@ async def ingest_decrypted_direct_message(
received_at=received,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
outgoing=outgoing,
txt_type=decrypted.txt_type,
signature=signature,
+184 -4
View File
@@ -2,6 +2,7 @@
import asyncio
import logging
import time as _time
from collections.abc import Callable
from typing import Any
@@ -9,10 +10,17 @@ from fastapi import HTTPException
from meshcore import EventType
from app.models import ResendChannelMessageResponse
from app.radio import RadioOperationBusyError
from app.region_scope import normalize_region_scope
from app.repository import AppSettingsRepository, ContactRepository, MessageRepository
from app.repository import (
AppSettingsRepository,
ChannelRepository,
ContactRepository,
MessageRepository,
)
from app.services import dm_ack_tracker
from app.services.messages import (
BroadcastFn,
broadcast_message,
build_stored_outgoing_channel_message,
create_outgoing_channel_message,
@@ -26,13 +34,20 @@ NO_RADIO_RESPONSE_AFTER_SEND_DETAIL = (
"Send command was issued to the radio, but no response was heard back. "
"The message may or may not have sent successfully."
)
BroadcastFn = Callable[..., Any]
TrackAckFn = Callable[[str, int, int], bool]
NowFn = Callable[[], float]
OutgoingReservationKey = tuple[str, str, str]
RetryTaskScheduler = Callable[[Any], Any]
# Channel echo watchdog: delay before checking for echoes
ECHO_WATCHDOG_DELAY_SECONDS = 2.0
# Byte-perfect resend window (must match router's RESEND_WINDOW_SECONDS)
RESEND_WINDOW_SECONDS = 30
# Temp radio slot used by the router for channel sends
WATCHDOG_TEMP_RADIO_SLOT = 0
_pending_outgoing_timestamp_reservations: dict[OutgoingReservationKey, set[int]] = {}
_outgoing_timestamp_reservations_lock = asyncio.Lock()
@@ -122,7 +137,7 @@ async def send_channel_message_with_effective_scope(
error_broadcast_fn: BroadcastFn,
app_settings_repository=AppSettingsRepository,
) -> Any:
"""Send a channel message, temporarily overriding flood scope when configured."""
"""Send a channel message, temporarily overriding flood scope and/or path hash mode."""
override_scope = normalize_region_scope(channel.flood_scope_override)
baseline_scope = ""
@@ -151,6 +166,36 @@ async def send_channel_message_with_effective_scope(
),
)
# Path hash mode per-channel override
override_phm = channel.path_hash_mode_override
baseline_phm = radio_manager.path_hash_mode
apply_phm = (
override_phm is not None
and radio_manager.path_hash_mode_supported
and override_phm != baseline_phm
)
if apply_phm:
logger.info(
"Temporarily applying channel path_hash_mode override for %s: %d",
channel.name,
override_phm,
)
phm_result = await mc.commands.set_path_hash_mode(override_phm)
if phm_result is not None and phm_result.type == EventType.ERROR:
logger.warning(
"Failed to apply channel path_hash_mode override for %s: %s",
channel.name,
phm_result.payload,
)
raise HTTPException(
status_code=500,
detail=(
f"Failed to apply path hash mode override before {action_label}: "
f"{phm_result.payload}"
),
)
try:
channel_slot, needs_configure, evicted_channel_key = radio_manager.plan_channel_send_slot(
channel_key,
@@ -254,6 +299,46 @@ async def send_channel_message_with_effective_scope(
),
)
if apply_phm:
restored = False
for attempt in range(3):
try:
restore_phm = await mc.commands.set_path_hash_mode(baseline_phm)
if restore_phm is not None and restore_phm.type == EventType.ERROR:
logger.warning(
"Attempt %d/3: failed to restore path_hash_mode after sending to %s: %s",
attempt + 1,
channel.name,
restore_phm.payload,
)
else:
radio_manager.path_hash_mode = baseline_phm
logger.debug(
"Restored baseline path_hash_mode after channel send: %d",
baseline_phm,
)
restored = True
break
except Exception:
logger.exception(
"Attempt %d/3: exception restoring path_hash_mode after sending to %s",
attempt + 1,
channel.name,
)
if not restored:
logger.error(
"All 3 attempts to restore path_hash_mode failed for %s",
channel.name,
)
error_broadcast_fn(
"Path hash mode restore failed",
(
f"Sent to {channel.name}, but restoring path hash mode failed "
f"after 3 attempts. The radio is still using a non-default hop "
f"width. Set it back manually in Radio settings."
),
)
def _extract_expected_ack_code(result: Any) -> str | None:
if result is None or result.type == EventType.ERROR:
@@ -550,6 +635,85 @@ async def send_direct_message_to_contact(
return message
async def _channel_echo_watchdog(
message_id: int,
radio_manager,
broadcast_fn: BroadcastFn,
error_broadcast_fn: BroadcastFn,
) -> None:
"""One-shot watchdog: if no echo heard after delay, attempt one byte-perfect resend.
Spawned as a fire-and-forget task after a channel send when auto_resend_channel is enabled.
Uses non-blocking radio lock so it never stalls user actions.
"""
try:
await asyncio.sleep(ECHO_WATCHDOG_DELAY_SECONDS)
msg = await MessageRepository.get_by_id(message_id)
if not msg:
return
if msg.acked > 0:
logger.debug(
"Echo watchdog: message %d already has %d echo(s), skipping", message_id, msg.acked
)
return
if msg.sender_timestamp is None:
return
elapsed = int(_time.time()) - msg.sender_timestamp
if elapsed > RESEND_WINDOW_SECONDS:
logger.debug(
"Echo watchdog: message %d outside resend window (%ds)", message_id, elapsed
)
return
channel = await ChannelRepository.get_by_key(msg.conversation_key)
if not channel:
return
logger.info(
"Echo watchdog: no echo for message %d after %.0fs, attempting byte-perfect resend",
message_id,
ECHO_WATCHDOG_DELAY_SECONDS,
)
try:
key_bytes = bytes.fromhex(msg.conversation_key)
except ValueError:
return
timestamp_bytes = msg.sender_timestamp.to_bytes(4, "little")
# Strip sender name prefix to get the raw text for the radio
async with radio_manager.radio_operation("echo_watchdog_resend", blocking=False) as mc:
radio_name = mc.self_info.get("name", "") if mc.self_info else ""
text_to_send = msg.text
if radio_name and text_to_send.startswith(f"{radio_name}: "):
text_to_send = text_to_send[len(f"{radio_name}: ") :]
result = await send_channel_message_with_effective_scope(
mc=mc,
channel=channel,
channel_key=msg.conversation_key,
key_bytes=key_bytes,
text=text_to_send,
timestamp_bytes=timestamp_bytes,
action_label="echo watchdog resend",
radio_manager=radio_manager,
temp_radio_slot=WATCHDOG_TEMP_RADIO_SLOT,
error_broadcast_fn=error_broadcast_fn,
)
if result is not None and result.type != EventType.ERROR:
logger.info("Echo watchdog: resent message %d successfully", message_id)
else:
logger.debug("Echo watchdog: resend got no/error result for message %d", message_id)
except RadioOperationBusyError:
logger.debug("Echo watchdog: radio busy, skipping resend for message %d", message_id)
except Exception:
logger.debug("Echo watchdog: resend failed for message %d", message_id, exc_info=True)
async def send_channel_message_to_channel(
*,
channel,
@@ -658,6 +822,22 @@ async def send_channel_message_to_channel(
message_repository=message_repository,
)
broadcast_message(message=outgoing_message, broadcast_fn=broadcast_fn)
# Spawn echo watchdog if auto-resend is enabled
try:
settings = await AppSettingsRepository.get()
if settings.auto_resend_channel:
asyncio.create_task(
_channel_echo_watchdog(
message_id=outgoing_message.id,
radio_manager=radio_manager,
broadcast_fn=broadcast_fn,
error_broadcast_fn=error_broadcast_fn,
)
)
except Exception:
pass # Never let watchdog setup failure break the send
return outgoing_message
+27 -3
View File
@@ -37,10 +37,16 @@ def build_message_paths(
path: str | None,
received_at: int,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
) -> list[MessagePath] | None:
"""Build the single-path list used by message payloads."""
return (
[MessagePath(path=path or "", received_at=received_at, path_len=path_len)]
[
MessagePath(
path=path or "", received_at=received_at, path_len=path_len, rssi=rssi, snr=snr
)
]
if path is not None
else None
)
@@ -166,6 +172,8 @@ async def reconcile_duplicate_message(
path: str | None,
received_at: int,
path_len: int | None,
rssi: int | None = None,
snr: float | None = None,
broadcast_fn: BroadcastFn,
) -> None:
logger.debug(
@@ -177,7 +185,9 @@ async def reconcile_duplicate_message(
)
if path is not None:
paths = await MessageRepository.add_path(existing_msg.id, path, received_at, path_len)
paths = await MessageRepository.add_path(
existing_msg.id, path, received_at, path_len, rssi=rssi, snr=snr
)
else:
paths = existing_msg.paths or []
@@ -214,6 +224,8 @@ async def handle_duplicate_message(
path: str | None,
received_at: int,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
broadcast_fn: BroadcastFn,
) -> None:
"""Handle a duplicate message by updating paths/acks on the existing record."""
@@ -239,6 +251,8 @@ async def handle_duplicate_message(
path=path,
received_at=received_at,
path_len=path_len,
rssi=rssi,
snr=snr,
broadcast_fn=broadcast_fn,
)
@@ -253,6 +267,8 @@ async def create_message_from_decrypted(
received_at: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
channel_name: str | None = None,
realtime: bool = True,
broadcast_fn: BroadcastFn,
@@ -276,6 +292,8 @@ async def create_message_from_decrypted(
received_at=received,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
sender_name=sender,
sender_key=resolved_sender_key,
)
@@ -291,6 +309,8 @@ async def create_message_from_decrypted(
path=path,
received_at=received,
path_len=path_len,
rssi=rssi,
snr=snr,
broadcast_fn=broadcast_fn,
)
return None
@@ -312,7 +332,7 @@ async def create_message_from_decrypted(
text=text,
sender_timestamp=timestamp,
received_at=received,
paths=build_message_paths(path, received, path_len),
paths=build_message_paths(path, received, path_len, rssi=rssi, snr=snr),
sender_name=sender,
sender_key=resolved_sender_key,
channel_name=channel_name,
@@ -334,6 +354,8 @@ async def create_dm_message_from_decrypted(
received_at: int | None = None,
path: str | None = None,
path_len: int | None = None,
rssi: int | None = None,
snr: float | None = None,
outgoing: bool = False,
realtime: bool = True,
broadcast_fn: BroadcastFn,
@@ -348,6 +370,8 @@ async def create_dm_message_from_decrypted(
received_at=received_at,
path=path,
path_len=path_len,
rssi=rssi,
snr=snr,
outgoing=outgoing,
realtime=realtime,
broadcast_fn=broadcast_fn,
+10 -1
View File
@@ -33,6 +33,7 @@ async def run_post_connect_setup(radio_manager) -> None:
start_message_polling,
start_periodic_advert,
start_periodic_sync,
start_telemetry_collect,
sync_and_offload_all,
sync_radio_time,
)
@@ -214,7 +215,14 @@ async def run_post_connect_setup(radio_manager) -> None:
# Sync contacts/channels from radio to DB and clear radio
logger.info("Syncing and offloading radio data...")
result = await sync_and_offload_all(mc)
logger.info("Sync complete: %s", result)
c = result.get("contacts", {})
ch = result.get("channels", {})
logger.info(
"Sync complete: %d contacts synced, %d channels synced, %d channels cleared",
c.get("synced", 0),
ch.get("synced", 0),
ch.get("cleared", 0),
)
# Send advertisement to announce our presence (if enabled and not throttled)
if await send_advertisement(mc):
@@ -241,6 +249,7 @@ async def run_post_connect_setup(radio_manager) -> None:
start_periodic_sync()
start_periodic_advert()
start_message_polling()
start_telemetry_collect()
radio_manager._setup_complete = True
finally:
Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 109 KiB

+13 -3
View File
@@ -350,15 +350,13 @@ LocalStorage migration helpers for favorites; canonical favorites are server-sid
- `max_radio_contacts`
- `favorites`
- `auto_decrypt_dm_on_advert`
- `sidebar_sort_order`
- `last_message_times`
- `preferences_migrated`
- `advert_interval`
- `last_advert_time`
- `flood_scope`
- `blocked_keys`, `blocked_names`
- `blocked_keys`, `blocked_names`, `discovery_blocked_types`
The backend still carries `sidebar_sort_order` for compatibility and old preference migration, but the current sidebar UI stores sort order per section (`Channels`, `Contacts`, `Repeaters`) in frontend localStorage rather than treating it as one global server-backed setting.
Note: MQTT, bot, and community MQTT settings were migrated to the `fanout_configs` table (managed via `/api/fanout`). They are no longer part of `AppSettings`.
@@ -436,6 +434,18 @@ The `SearchView` component (`components/SearchView.tsx`) provides full-text sear
UI styling is mostly utility-class driven (Tailwind-style classes in JSX) plus shared globals in `index.css` and `styles.css`.
Do not rely on old class-only layout assumptions.
### Canonical style reference
`SettingsLocalSection.tsx` contains a **ThemePreview** component with a collapsible "Canonical style reference" section. This is the authoritative catalog of text sizes, button variants, badge patterns, and interactive elements used throughout the app. **When adding or modifying UI, match the patterns shown there rather than inventing new ones.**
Key conventions documented in the reference:
- **Text sizes** use `rem`-based Tailwind values so they scale with the user's font-size slider. Do not use hard-locked `px` values (e.g., `text-[10px]`). The canonical sizes are `text-[0.625rem]` (10px), `text-[0.6875rem]` (11px), `text-[0.8125rem]` (13px), plus standard Tailwind `text-xs`/`text-sm`/`text-base`/`text-lg`/`text-xl`.
- **Section labels** use `text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium`.
- **Buttons** use the shadcn `<Button>` component. Semantic color overrides (danger, warning, success) use `variant="outline"` with `className="border-{color}/50 text-{color} hover:bg-{color}/10"`.
- **Badges/tags** use `text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded` with `bg-muted` (neutral) or `bg-primary/10` (active).
- **Clickable text** (copy-to-clipboard, navigational links) uses `role="button" tabIndex={0}` with `cursor-pointer hover:text-primary transition-colors`.
## Security Posture (intentional)
- No authentication UI.
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "remoteterm-meshcore-frontend",
"private": true,
"version": "3.7.1",
"version": "3.8.0",
"type": "module",
"scripts": {
"dev": "vite",
+43 -9
View File
@@ -18,6 +18,7 @@ import {
useUnreadTitle,
useRawPacketStatsSession,
} from './hooks';
import { toast } from './components/ui/sonner';
import { AppShell } from './components/AppShell';
import type { MessageInputHandle } from './components/MessageInput';
import { DistanceUnitProvider } from './contexts/DistanceUnitContext';
@@ -150,12 +151,11 @@ export function App() {
const {
appSettings,
favorites,
fetchAppSettings,
handleSaveAppSettings,
handleToggleFavorite,
handleToggleBlockedKey,
handleToggleBlockedName,
handleToggleTrackedTelemetry,
} = useAppSettings();
// Keep user's name in ref for mention detection in WebSocket callback
@@ -203,6 +203,38 @@ export function App() {
removeConversationMessagesRef.current(conversationId),
});
const handleToggleFavorite = useCallback(
async (type: 'channel' | 'contact', id: string) => {
// Optimistically toggle the favorite flag
if (type === 'contact') {
setContacts((prev) =>
prev.map((c) => (c.public_key === id ? { ...c, favorite: !c.favorite } : c))
);
} else {
setChannels((prev) =>
prev.map((c) => (c.key === id ? { ...c, favorite: !c.favorite } : c))
);
}
try {
await api.toggleFavorite(type, id);
} catch {
// Revert on failure
if (type === 'contact') {
setContacts((prev) =>
prev.map((c) => (c.public_key === id ? { ...c, favorite: !c.favorite } : c))
);
} else {
setChannels((prev) =>
prev.map((c) => (c.key === id ? { ...c, favorite: !c.favorite } : c))
);
}
toast.error('Failed to update favorite');
}
},
[setContacts, setChannels]
);
// useConversationRouter is called second — it receives channels/contacts as inputs
const {
activeConversation,
@@ -289,8 +321,8 @@ export function App() {
markAllRead,
refreshUnreads,
} = useUnreadCounts(channels, contacts, activeConversation);
useFaviconBadge(unreadCounts, mentions, favorites);
useUnreadTitle(unreadCounts, favorites);
useFaviconBadge(unreadCounts, mentions, channels);
useUnreadTitle(unreadCounts, contacts, channels);
useEffect(() => {
if (activeConversation?.type !== 'channel') {
@@ -397,6 +429,7 @@ export function App() {
handleSendMessage,
handleResendChannelMessage,
handleSetChannelFloodScopeOverride,
handleSetChannelPathHashModeOverride,
handleSenderClick,
handleTrace,
handlePathDiscovery,
@@ -489,8 +522,6 @@ export function App() {
onMarkAllRead: () => {
void markAllRead();
},
favorites,
legacySortOrder: appSettings?.sidebar_sort_order,
isConversationNotificationsEnabled,
blockedKeys: appSettings?.blocked_keys ?? [],
blockedNames: appSettings?.blocked_names ?? [],
@@ -506,8 +537,8 @@ export function App() {
rawPacketStatsSession,
config,
health,
favorites,
messages: sortedMessages,
preSorted: activeContactIsRoom,
messagesLoading,
loadingOlder,
hasOlderMessages,
@@ -527,6 +558,7 @@ export function App() {
onDeleteContact: handleDeleteContact,
onDeleteChannel: handleDeleteChannel,
onSetChannelFloodScopeOverride: handleSetChannelFloodScopeOverride,
onSetChannelPathHashModeOverride: handleSetChannelPathHashModeOverride,
onOpenContactInfo: handleOpenContactInfo,
onOpenChannelInfo: handleOpenChannelInfo,
onSenderClick: handleSenderClick,
@@ -553,6 +585,8 @@ export function App() {
);
}
},
trackedTelemetryRepeaters: appSettings?.tracked_telemetry_repeaters ?? [],
onToggleTrackedTelemetry: handleToggleTrackedTelemetry,
};
const searchProps = {
contacts,
@@ -586,6 +620,8 @@ export function App() {
const keySet = new Set(deletedKeys.map((k) => k.toLowerCase()));
setContacts((prev) => prev.filter((c) => !keySet.has(c.public_key.toLowerCase())));
},
trackedTelemetryRepeaters: appSettings?.tracked_telemetry_repeaters ?? [],
onToggleTrackedTelemetry: handleToggleTrackedTelemetry,
};
const crackerProps = {
packets: rawPackets,
@@ -607,7 +643,6 @@ export function App() {
onClose: handleCloseContactInfo,
contacts,
config,
favorites,
onToggleFavorite: handleToggleFavorite,
onNavigateToChannel: handleNavigateToChannel,
onSearchMessagesByKey: (publicKey: string) => {
@@ -625,7 +660,6 @@ export function App() {
channelKey: infoPaneChannelKey,
onClose: handleCloseChannelInfo,
channels,
favorites,
onToggleFavorite: handleToggleFavorite,
};
+15 -11
View File
@@ -9,13 +9,10 @@ import type {
ContactAnalytics,
ContactAdvertPathSummary,
FanoutConfig,
Favorite,
HealthStatus,
MaintenanceResult,
Message,
MessagesAroundResponse,
MigratePreferencesRequest,
MigratePreferencesResponse,
RawPacket,
RadioAdvertMode,
RadioConfig,
@@ -36,6 +33,7 @@ import type {
RepeaterRadioSettingsResponse,
RepeaterStatusResponse,
TelemetryHistoryEntry,
TrackedTelemetryResponse,
StatisticsResponse,
TraceResponse,
UnreadCounts,
@@ -210,6 +208,12 @@ export const api = {
body: JSON.stringify({ flood_scope_override: floodScopeOverride }),
}),
setChannelPathHashModeOverride: (key: string, pathHashModeOverride: number | null) =>
fetchJson<Channel>(`/channels/${key}/path-hash-mode-override`, {
method: 'POST',
body: JSON.stringify({ path_hash_mode_override: pathHashModeOverride }),
}),
// Messages
getMessages: (
params?: {
@@ -321,18 +325,18 @@ export const api = {
body: JSON.stringify({ name }),
}),
// Favorites
toggleFavorite: (type: Favorite['type'], id: string) =>
fetchJson<AppSettings>('/settings/favorites/toggle', {
// Tracked telemetry
toggleTrackedTelemetry: (publicKey: string) =>
fetchJson<TrackedTelemetryResponse>('/settings/tracked-telemetry/toggle', {
method: 'POST',
body: JSON.stringify({ type, id }),
body: JSON.stringify({ public_key: publicKey }),
}),
// Preferences migration (one-time, from localStorage to database)
migratePreferences: (request: MigratePreferencesRequest) =>
fetchJson<MigratePreferencesResponse>('/settings/migrate', {
// Favorites
toggleFavorite: (type: 'channel' | 'contact', id: string) =>
fetchJson<{ type: string; id: string; favorite: boolean }>('/settings/favorites/toggle', {
method: 'POST',
body: JSON.stringify(request),
body: JSON.stringify({ type, id }),
}),
// Fanout
+3 -3
View File
@@ -135,7 +135,7 @@ export function AppShell({
aria-label="Settings"
>
<div className="flex justify-between items-center px-3 py-2.5 border-b border-border">
<h2 className="text-[10px] uppercase tracking-wider text-muted-foreground font-medium">
<h2 className="text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium">
Settings
</h2>
<button
@@ -158,7 +158,7 @@ export function AppShell({
type="button"
disabled={disabled}
className={cn(
'w-full px-3 py-2 text-left text-[13px] border-l-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:cursor-not-allowed disabled:opacity-50',
'w-full px-3 py-2 text-left text-[0.8125rem] border-l-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset disabled:cursor-not-allowed disabled:opacity-50',
!disabled && 'hover:bg-accent',
settingsSection === section && !disabled && 'bg-accent border-l-primary'
)}
@@ -299,7 +299,7 @@ export function AppShell({
<Suspense
fallback={
<div className="flex items-center justify-center h-full text-muted-foreground">
Loading cracker...
Loading channel finder...
</div>
}
>
@@ -49,11 +49,13 @@ export function BulkAddChannelResultModal({
{result && (
<div className="grid grid-cols-2 gap-3 text-sm">
<div className="rounded-md border border-border/70 bg-muted/30 px-3 py-2">
<div className="text-xs uppercase tracking-wide text-muted-foreground">Created</div>
<div className="text-[0.625rem] uppercase tracking-wider font-medium text-muted-foreground">
Created
</div>
<div className="mt-1 font-medium">{createdChannels.length}</div>
</div>
<div className="rounded-md border border-border/70 bg-muted/30 px-3 py-2">
<div className="text-xs uppercase tracking-wide text-muted-foreground">
<div className="text-[0.625rem] uppercase tracking-wider font-medium text-muted-foreground">
Already Present
</div>
<div className="mt-1 font-medium">{result.existing_count}</div>
+94 -9
View File
@@ -1,18 +1,17 @@
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip } from 'recharts';
import { Star } from 'lucide-react';
import { api } from '../api';
import { formatTime } from '../utils/messageParser';
import { isFavorite } from '../utils/favorites';
import { handleKeyboardActivate } from '../utils/a11y';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from './ui/sheet';
import { toast } from './ui/sonner';
import type { Channel, ChannelDetail, Favorite } from '../types';
import type { Channel, ChannelDetail, PathHashWidthStats } from '../types';
interface ChannelInfoPaneProps {
channelKey: string | null;
onClose: () => void;
channels: Channel[];
favorites: Favorite[];
onToggleFavorite: (type: 'channel' | 'contact', id: string) => void;
}
@@ -20,7 +19,6 @@ export function ChannelInfoPane({
channelKey,
onClose,
channels,
favorites,
onToggleFavorite,
}: ChannelInfoPaneProps) {
const [detail, setDetail] = useState<ChannelDetail | null>(null);
@@ -106,11 +104,11 @@ export function ChannelInfoPane({
</span>
)}
<div className="flex items-center gap-2 mt-1.5">
<span className="text-[10px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
{channel.is_hashtag ? 'Hashtag' : 'Private Key'}
</span>
{channel.on_radio && (
<span className="text-[10px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium">
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium">
On Radio
</span>
)}
@@ -124,7 +122,7 @@ export function ChannelInfoPane({
className="text-sm flex items-center gap-2 hover:text-primary transition-colors"
onClick={() => onToggleFavorite('channel', channel.key)}
>
{isFavorite(favorites, 'channel', channel.key) ? (
{channel.favorite ? (
<>
<Star className="h-4.5 w-4.5 fill-current text-favorite" aria-hidden="true" />
<span>Remove from favorites</span>
@@ -179,6 +177,14 @@ export function ChannelInfoPane({
</div>
)}
{/* Hop Byte Widths (24h) */}
{detail && detail.path_hash_width_24h.total_packets > 0 && (
<div className="px-5 py-3 border-b border-border">
<SectionLabel>Hop Byte Widths (24h)</SectionLabel>
<HopWidthChart stats={detail.path_hash_width_24h} />
</div>
)}
{/* Top Senders 24h */}
{detail && detail.top_senders_24h.length > 0 && (
<div className="px-5 py-3">
@@ -212,7 +218,7 @@ export function ChannelInfoPane({
function SectionLabel({ children }: { children: React.ReactNode }) {
return (
<h3 className="text-[10px] uppercase tracking-wider text-muted-foreground font-medium mb-1.5">
<h3 className="text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium mb-1.5">
{children}
</h3>
);
@@ -226,3 +232,82 @@ function InfoItem({ label, value }: { label: string; value: string }) {
</div>
);
}
const HOP_WIDTH_SEGMENTS = [
{ key: 'single_byte', label: '1-byte', color: '#22c55e' },
{ key: 'double_byte', label: '2-byte', color: '#0ea5e9' },
{ key: 'triple_byte', label: '3-byte', color: '#8b5cf6' },
] as const;
const TOOLTIP_STYLE = {
contentStyle: {
backgroundColor: 'hsl(var(--popover))',
border: '1px solid hsl(var(--border))',
borderRadius: '6px',
fontSize: '11px',
color: 'hsl(var(--popover-foreground))',
},
} as const;
function HopWidthChart({ stats }: { stats: PathHashWidthStats }) {
const data = useMemo(
() =>
HOP_WIDTH_SEGMENTS.map(({ key, label, color }) => ({
name: label,
value: stats[key] as number,
color,
})).filter((d) => d.value > 0),
[stats]
);
return (
<div className="flex items-center gap-3">
<div className="flex-shrink-0" style={{ width: 90, height: 90 }}>
<ResponsiveContainer width="100%" height="100%">
<PieChart>
<Pie
data={data}
dataKey="value"
cx="50%"
cy="50%"
innerRadius={22}
outerRadius={40}
strokeWidth={1.5}
stroke="hsl(var(--background))"
>
{data.map((d) => (
<Cell key={d.name} fill={d.color} />
))}
</Pie>
<RechartsTooltip
{...TOOLTIP_STYLE}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
formatter={(value: any, name: any) => {
const v = typeof value === 'number' ? value : Number(value);
return [`${v.toLocaleString()} pkt${v !== 1 ? 's' : ''}`, name];
}}
/>
</PieChart>
</ResponsiveContainer>
</div>
<div className="flex-1 space-y-1">
{data.map((d) => (
<div key={d.name} className="flex items-center gap-1.5">
<span
className="w-2 h-2 rounded-full flex-shrink-0"
style={{ backgroundColor: d.color }}
/>
<span className="text-[0.6875rem] text-muted-foreground flex-1">{d.name}</span>
<span className="text-[0.6875rem] font-medium tabular-nums">
{d.value.toLocaleString()}
</span>
</div>
))}
<p className="text-[0.625rem] text-muted-foreground pt-0.5">
{stats.total_packets.toLocaleString()} total
</p>
</div>
</div>
);
}
@@ -0,0 +1,132 @@
import { useEffect, useState } from 'react';
import { Button } from './ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from './ui/dialog';
import { Label } from './ui/label';
const PATH_HASH_MODE_LABELS: Record<number, string> = {
0: '1-byte',
1: '2-byte',
2: '3-byte',
};
interface ChannelPathHashModeOverrideModalProps {
open: boolean;
onClose: () => void;
channelName: string;
currentOverride: number | null;
radioDefault: number;
onSetOverride: (value: number | null) => void;
}
export function ChannelPathHashModeOverrideModal({
open,
onClose,
channelName,
currentOverride,
radioDefault,
onSetOverride,
}: ChannelPathHashModeOverrideModalProps) {
const [selected, setSelected] = useState<number | null>(null);
useEffect(() => {
if (open) {
setSelected(currentOverride);
}
}, [currentOverride, open]);
const radioDefaultLabel = PATH_HASH_MODE_LABELS[radioDefault] ?? `${radioDefault}`;
const options: { value: number | null; label: string; description: string }[] = [
{
value: null,
label: `Radio default (${radioDefaultLabel})`,
description: 'Use the radio-wide path hash mode setting',
},
{
value: 0,
label: '1-byte hop identifiers',
description: 'Least repeater disambiguation, up to 63 hops',
},
{
value: 1,
label: '2-byte hop identifiers',
description: 'Better repeater disambiguation, up to 32 hops',
},
{
value: 2,
label: '3-byte hop identifiers',
description: 'Best repeater disambiguation, up to 21 hops',
},
];
return (
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
<DialogContent className="sm:max-w-[520px]">
<DialogHeader>
<DialogTitle>Path Hop Width Override</DialogTitle>
<DialogDescription>
Override the path hash mode for this channel. Wider hop identifiers improve repeater
disambiguation but extend send time and will prevent users on old (&lt;1.14) firmware
from receiving the message.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div className="rounded-md border border-border bg-muted/20 p-3 text-sm">
<div className="font-medium">{channelName}</div>
<div className="mt-1 text-muted-foreground">
Current override:{' '}
{currentOverride != null
? (PATH_HASH_MODE_LABELS[currentOverride] ?? `mode ${currentOverride}`)
: `none (using radio default: ${radioDefaultLabel})`}
</div>
</div>
<div className="space-y-2">
<Label>Hop width for this channel</Label>
<div className="space-y-1.5">
{options.map((opt) => (
<button
key={String(opt.value)}
type="button"
className={`w-full rounded-md border px-3 py-2 text-left text-sm transition-colors ${
selected === opt.value
? 'border-primary bg-primary/10 text-foreground'
: 'border-border hover:bg-accent'
}`}
onClick={() => setSelected(opt.value)}
>
<div className="font-medium">{opt.label}</div>
<div className="text-xs text-muted-foreground">{opt.description}</div>
</button>
))}
</div>
</div>
</div>
<DialogFooter className="gap-2 sm:block sm:space-x-0">
<Button
type="button"
className="w-full"
onClick={() => {
onSetOverride(selected);
onClose();
}}
>
{selected == null
? `Use radio default for ${channelName}`
: `Use ${PATH_HASH_MODE_LABELS[selected]} hops for ${channelName}`}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
+57 -26
View File
@@ -1,10 +1,10 @@
import { useEffect, useState } from 'react';
import { Bell, Globe2, Info, Route, Star, Trash2 } from 'lucide-react';
import { Bell, ChevronsLeftRight, Globe2, Info, Route, Star, Trash2 } from 'lucide-react';
import { toast } from './ui/sonner';
import { DirectTraceIcon } from './DirectTraceIcon';
import { ContactPathDiscoveryModal } from './ContactPathDiscoveryModal';
import { ChannelFloodScopeOverrideModal } from './ChannelFloodScopeOverrideModal';
import { isFavorite } from '../utils/favorites';
import { ChannelPathHashModeOverrideModal } from './ChannelPathHashModeOverrideModal';
import { handleKeyboardActivate } from '../utils/a11y';
import { isPublicChannelKey } from '../utils/publicChannel';
import { stripRegionScopePrefix } from '../utils/regionScope';
@@ -12,14 +12,7 @@ import { isPrefixOnlyContact } from '../utils/pubkey';
import { cn } from '../lib/utils';
import { ContactAvatar } from './ContactAvatar';
import { ContactStatusInfo } from './ContactStatusInfo';
import type {
Channel,
Contact,
Conversation,
Favorite,
PathDiscoveryResponse,
RadioConfig,
} from '../types';
import type { Channel, Contact, Conversation, PathDiscoveryResponse, RadioConfig } from '../types';
import { CONTACT_TYPE_ROOM } from '../types';
interface ChatHeaderProps {
@@ -27,7 +20,6 @@ interface ChatHeaderProps {
contacts: Contact[];
channels: Channel[];
config: RadioConfig | null;
favorites: Favorite[];
notificationsSupported: boolean;
notificationsEnabled: boolean;
notificationsPermission: NotificationPermission | 'unsupported';
@@ -36,6 +28,7 @@ interface ChatHeaderProps {
onToggleNotifications: () => void;
onToggleFavorite: (type: 'channel' | 'contact', id: string) => void;
onSetChannelFloodScopeOverride?: (key: string, floodScopeOverride: string) => void;
onSetChannelPathHashModeOverride?: (key: string, pathHashModeOverride: number | null) => void;
onDeleteChannel: (key: string) => void;
onDeleteContact: (publicKey: string) => void;
onOpenContactInfo?: (publicKey: string) => void;
@@ -47,7 +40,6 @@ export function ChatHeader({
contacts,
channels,
config,
favorites,
notificationsSupported,
notificationsEnabled,
notificationsPermission,
@@ -56,6 +48,7 @@ export function ChatHeader({
onToggleNotifications,
onToggleFavorite,
onSetChannelFloodScopeOverride,
onSetChannelPathHashModeOverride,
onDeleteChannel,
onDeleteContact,
onOpenContactInfo,
@@ -64,11 +57,13 @@ export function ChatHeader({
const [showKey, setShowKey] = useState(false);
const [pathDiscoveryOpen, setPathDiscoveryOpen] = useState(false);
const [channelOverrideOpen, setChannelOverrideOpen] = useState(false);
const [pathHashModeOverrideOpen, setPathHashModeOverrideOpen] = useState(false);
useEffect(() => {
setShowKey(false);
setPathDiscoveryOpen(false);
setChannelOverrideOpen(false);
setPathHashModeOverrideOpen(false);
}, [conversation.id]);
const activeChannel =
@@ -81,6 +76,12 @@ export function ChatHeader({
? stripRegionScopePrefix(activeFloodScopeOverride)
: null;
const activeFloodScopeDisplay = activeFloodScopeOverride ? activeFloodScopeOverride : null;
const activePathHashModeOverride =
conversation.type === 'channel' ? (activeChannel?.path_hash_mode_override ?? null) : null;
const showPathHashModeOverride =
conversation.type === 'channel' &&
onSetChannelPathHashModeOverride &&
config?.path_hash_mode_supported;
const isPrivateChannel = conversation.type === 'channel' && !activeChannel?.is_hashtag;
const activeContact =
conversation.type === 'contact'
@@ -94,12 +95,18 @@ export function ChatHeader({
const titleClickable =
(conversation.type === 'contact' && onOpenContactInfo) ||
(conversation.type === 'channel' && onOpenChannelInfo);
const isFav =
conversation.type === 'contact'
? (activeContact?.favorite ?? false)
: conversation.type === 'channel'
? (activeChannel?.favorite ?? false)
: false;
const favoriteTitle =
conversation.type === 'contact'
? isFavorite(favorites, 'contact', conversation.id)
? isFav
? 'Remove from favorites. Favorite contacts stay loaded on the radio for ACK support.'
: 'Add to favorites. Favorite contacts stay loaded on the radio for ACK support.'
: isFavorite(favorites, conversation.type as 'channel' | 'contact', conversation.id)
: isFav
? 'Remove from favorites'
: 'Add to favorites';
@@ -108,6 +115,11 @@ export function ChatHeader({
setChannelOverrideOpen(true);
};
const handleEditPathHashModeOverride = () => {
if (conversation.type !== 'channel' || !onSetChannelPathHashModeOverride) return;
setPathHashModeOverrideOpen(true);
};
const handleOpenConversationInfo = () => {
if (conversation.type === 'contact' && onOpenContactInfo) {
onOpenContactInfo(conversation.id);
@@ -182,7 +194,7 @@ export function ChatHeader({
</h2>
{isPrivateChannel && !showKey ? (
<button
className="min-w-0 flex-shrink text-[11px] font-mono text-muted-foreground transition-colors hover:text-primary"
className="min-w-0 flex-shrink text-[0.6875rem] font-mono text-muted-foreground transition-colors hover:text-primary"
onClick={(e) => {
e.stopPropagation();
setShowKey(true);
@@ -193,7 +205,7 @@ export function ChatHeader({
</button>
) : (
<span
className="min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground transition-colors hover:text-primary"
className="min-w-0 flex-1 truncate font-mono text-[0.6875rem] text-muted-foreground transition-colors hover:text-primary"
role="button"
tabIndex={0}
onKeyDown={handleKeyboardActivate}
@@ -228,7 +240,7 @@ export function ChatHeader({
className="h-3.5 w-3.5 flex-shrink-0 text-[hsl(var(--region-override))]"
aria-hidden="true"
/>
<span className="min-w-0 truncate text-[11px] font-medium text-[hsl(var(--region-override))]">
<span className="min-w-0 truncate text-[0.6875rem] font-medium text-[hsl(var(--region-override))]">
{activeFloodScopeDisplay}
</span>
</button>
@@ -237,7 +249,7 @@ export function ChatHeader({
</span>
</span>
{conversation.type === 'contact' && activeContact && (
<div className="col-span-2 row-start-2 min-w-0 text-[11px] text-muted-foreground min-[1100px]:col-span-1 min-[1100px]:col-start-2 min-[1100px]:row-start-1">
<div className="col-span-2 row-start-2 min-w-0 text-[0.6875rem] text-muted-foreground min-[1100px]:col-span-1 min-[1100px]:col-start-2 min-[1100px]:row-start-1">
<ContactStatusInfo
contact={activeContact}
ourLat={config?.lat ?? null}
@@ -299,7 +311,7 @@ export function ChatHeader({
aria-hidden="true"
/>
{notificationsEnabled && (
<span className="hidden md:inline text-[11px] font-medium text-status-connected">
<span className="hidden md:inline text-[0.6875rem] font-medium text-status-connected">
Notifications On
</span>
)}
@@ -317,12 +329,25 @@ export function ChatHeader({
aria-hidden="true"
/>
{activeFloodScopeDisplay && (
<span className="hidden text-[11px] font-medium text-[hsl(var(--region-override))] sm:inline">
<span className="hidden text-[0.6875rem] font-medium text-[hsl(var(--region-override))] sm:inline">
{activeFloodScopeDisplay}
</span>
)}
</button>
)}
{showPathHashModeOverride && (
<button
className="flex shrink-0 items-center gap-1 rounded px-1 py-1 text-lg leading-none transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
onClick={handleEditPathHashModeOverride}
title="Set path hop width override"
aria-label="Set path hop width override"
>
<ChevronsLeftRight
className={`h-4 w-4 ${activePathHashModeOverride != null ? 'text-status-connected' : 'text-muted-foreground'}`}
aria-hidden="true"
/>
</button>
)}
{(conversation.type === 'channel' || conversation.type === 'contact') && (
<button
className="p-1 rounded hover:bg-accent text-lg leading-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
@@ -330,13 +355,9 @@ export function ChatHeader({
onToggleFavorite(conversation.type as 'channel' | 'contact', conversation.id)
}
title={favoriteTitle}
aria-label={
isFavorite(favorites, conversation.type as 'channel' | 'contact', conversation.id)
? 'Remove from favorites'
: 'Add to favorites'
}
aria-label={isFav ? 'Remove from favorites' : 'Add to favorites'}
>
{isFavorite(favorites, conversation.type as 'channel' | 'contact', conversation.id) ? (
{isFav ? (
<Star className="h-4 w-4 fill-current text-favorite" aria-hidden="true" />
) : (
<Star className="h-4 w-4 text-muted-foreground" aria-hidden="true" />
@@ -379,6 +400,16 @@ export function ChatHeader({
onSetOverride={(value) => onSetChannelFloodScopeOverride(conversation.id, value)}
/>
)}
{showPathHashModeOverride && (
<ChannelPathHashModeOverrideModal
open={pathHashModeOverrideOpen}
onClose={() => setPathHashModeOverrideOpen(false)}
channelName={conversation.name}
currentOverride={activePathHashModeOverride}
radioDefault={config?.path_hash_mode ?? 0}
onSetOverride={(value) => onSetChannelPathHashModeOverride(conversation.id, value)}
/>
)}
</header>
);
}
+5 -9
View File
@@ -29,7 +29,6 @@ import {
} from '../utils/pathUtils';
import { isPublicChannelKey } from '../utils/publicChannel';
import { getMapFocusHash } from '../utils/urlHash';
import { isFavorite } from '../utils/favorites';
import { handleKeyboardActivate } from '../utils/a11y';
import { ContactAvatar } from './ContactAvatar';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from './ui/sheet';
@@ -42,7 +41,6 @@ import type {
ContactAnalytics,
ContactAnalyticsHourlyBucket,
ContactAnalyticsWeeklyBucket,
Favorite,
RadioConfig,
} from '../types';
@@ -67,7 +65,6 @@ interface ContactInfoPaneProps {
onClose: () => void;
contacts: Contact[];
config: RadioConfig | null;
favorites: Favorite[];
onToggleFavorite: (type: 'channel' | 'contact', id: string) => void;
onNavigateToChannel?: (channelKey: string) => void;
onSearchMessagesByKey?: (publicKey: string) => void;
@@ -84,7 +81,6 @@ export function ContactInfoPane({
onClose,
contacts,
config,
favorites,
onToggleFavorite,
onNavigateToChannel,
onSearchMessagesByKey,
@@ -292,7 +288,7 @@ export function ContactInfoPane({
{contact.public_key}
</span>
<div className="flex items-center gap-2 mt-1.5">
<span className="text-[10px] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
{CONTACT_TYPE_LABELS[contact.type] ?? 'Unknown'}
</span>
</div>
@@ -384,7 +380,7 @@ export function ContactInfoPane({
onClick={() => onToggleFavorite('contact', contact.public_key)}
title="Favorite contacts stay loaded on the radio for ACK support"
>
{isFavorite(favorites, 'contact', contact.public_key) ? (
{contact.favorite ? (
<>
<Star className="h-4.5 w-4.5 fill-current text-favorite" aria-hidden="true" />
<span>Remove from favorites</span>
@@ -568,7 +564,7 @@ export function ContactInfoPane({
function SectionLabel({ children }: { children: React.ReactNode }) {
return (
<h3 className="text-[10px] uppercase tracking-wider text-muted-foreground font-medium mb-1.5">
<h3 className="text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium mb-1.5">
{children}
</h3>
);
@@ -729,7 +725,7 @@ function ActivityChartsSection({ analytics }: { analytics: ContactAnalytics | nu
</div>
)}
<p className="text-[11px] text-muted-foreground">
<p className="text-[0.6875rem] text-muted-foreground">
Hourly lines compare the last 24 hours against 7-day and all-time averages for the same hour
slots.
{!analytics.includes_direct_messages &&
@@ -821,7 +817,7 @@ function ActivityLineChart<T extends ContactAnalyticsHourlyBucket | ContactAnaly
{legendItems && (
<Legend
content={() => (
<div className="flex flex-wrap justify-center gap-x-3 gap-y-1 mt-1 text-[11px] text-muted-foreground">
<div className="flex flex-wrap justify-center gap-x-3 gap-y-1 mt-1 text-[0.6875rem] text-muted-foreground">
{legendItems.map((item) => (
<span key={item.label} className="inline-flex items-center gap-1.5">
<span
@@ -74,12 +74,12 @@ function RouteCard({
<div className="rounded-md border border-border bg-muted/20 p-3">
<div className="flex items-center justify-between gap-3">
<h4 className="text-sm font-semibold">{label}</h4>
<span className="text-[11px] text-muted-foreground">
<span className="text-[0.6875rem] text-muted-foreground">
{formatRouteLabel(route.path_len, true)}
</span>
</div>
<p className="mt-2 text-sm">{chain}</p>
<div className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted-foreground">
<div className="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[0.6875rem] text-muted-foreground">
<span>Raw: {rawPath}</span>
<span>{formatPathHashMode(route.path_hash_mode)}</span>
</div>
+21 -6
View File
@@ -10,7 +10,6 @@ import type {
Channel,
Contact,
Conversation,
Favorite,
HealthStatus,
Message,
PathDiscoveryResponse,
@@ -42,8 +41,8 @@ interface ConversationPaneProps {
notificationsSupported: boolean;
notificationsEnabled: boolean;
notificationsPermission: NotificationPermission | 'unsupported';
favorites: Favorite[];
messages: Message[];
preSorted?: boolean;
messagesLoading: boolean;
loadingOlder: boolean;
hasOlderMessages: boolean;
@@ -62,6 +61,10 @@ interface ConversationPaneProps {
onDeleteContact: (publicKey: string) => Promise<void>;
onDeleteChannel: (key: string) => Promise<void>;
onSetChannelFloodScopeOverride: (channelKey: string, floodScopeOverride: string) => Promise<void>;
onSetChannelPathHashModeOverride?: (
channelKey: string,
pathHashModeOverride: number | null
) => Promise<void>;
onOpenContactInfo: (publicKey: string, fromChannel?: boolean) => void;
onOpenChannelInfo: (channelKey: string) => void;
onSenderClick: (sender: string) => void;
@@ -74,6 +77,8 @@ interface ConversationPaneProps {
onDismissUnreadMarker: () => void;
onSendMessage: (text: string) => Promise<void>;
onToggleNotifications: () => void;
trackedTelemetryRepeaters: string[];
onToggleTrackedTelemetry: (publicKey: string) => Promise<void>;
}
function LoadingPane({ label }: { label: string }) {
@@ -112,8 +117,8 @@ export function ConversationPane({
notificationsSupported,
notificationsEnabled,
notificationsPermission,
favorites,
messages,
preSorted,
messagesLoading,
loadingOlder,
hasOlderMessages,
@@ -129,6 +134,7 @@ export function ConversationPane({
onDeleteContact,
onDeleteChannel,
onSetChannelFloodScopeOverride,
onSetChannelPathHashModeOverride,
onOpenContactInfo,
onOpenChannelInfo,
onSenderClick,
@@ -141,6 +147,8 @@ export function ConversationPane({
onDismissUnreadMarker,
onSendMessage,
onToggleNotifications,
trackedTelemetryRepeaters,
onToggleTrackedTelemetry,
}: ConversationPaneProps) {
const [roomAuthenticated, setRoomAuthenticated] = useState(false);
const activeContactIsRepeater = useMemo(() => {
@@ -180,7 +188,12 @@ export function ConversationPane({
</h2>
<div className="flex-1 overflow-hidden">
<Suspense fallback={<LoadingPane label="Loading map..." />}>
<MapView contacts={contacts} focusedKey={activeConversation.mapFocusKey} />
<MapView
contacts={contacts}
focusedKey={activeConversation.mapFocusKey}
rawPackets={rawPackets}
config={config}
/>
</Suspense>
</div>
</>
@@ -221,7 +234,6 @@ export function ConversationPane({
key={activeConversation.id}
conversation={activeConversation}
contacts={contacts}
favorites={favorites}
notificationsSupported={notificationsSupported}
notificationsEnabled={notificationsEnabled}
notificationsPermission={notificationsPermission}
@@ -234,6 +246,8 @@ export function ConversationPane({
onToggleFavorite={onToggleFavorite}
onDeleteContact={onDeleteContact}
onOpenContactInfo={onOpenContactInfo}
trackedTelemetryRepeaters={trackedTelemetryRepeaters}
onToggleTrackedTelemetry={onToggleTrackedTelemetry}
/>
</Suspense>
);
@@ -248,7 +262,6 @@ export function ConversationPane({
contacts={contacts}
channels={channels}
config={config}
favorites={favorites}
notificationsSupported={notificationsSupported}
notificationsEnabled={notificationsEnabled}
notificationsPermission={notificationsPermission}
@@ -257,6 +270,7 @@ export function ConversationPane({
onToggleNotifications={onToggleNotifications}
onToggleFavorite={onToggleFavorite}
onSetChannelFloodScopeOverride={onSetChannelFloodScopeOverride}
onSetChannelPathHashModeOverride={onSetChannelPathHashModeOverride}
onDeleteChannel={onDeleteChannel}
onDeleteContact={onDeleteContact}
onOpenContactInfo={onOpenContactInfo}
@@ -275,6 +289,7 @@ export function ConversationPane({
<MessageList
key={activeConversation.id}
messages={messages}
preSorted={preSorted}
contacts={contacts}
channels={channels}
loading={messagesLoading}
+33 -12
View File
@@ -98,7 +98,7 @@ export function CrackerPanel({
.catch((err) => {
console.error('Failed to load wordlist:', err);
toast.error('Failed to load wordlist', {
description: 'Cracking will not be available',
description: 'Channel finder will not be available',
});
});
}, [visible, wordlistLoaded]);
@@ -356,7 +356,7 @@ export function CrackerPanel({
}
} catch (err) {
console.error('Failed to create channel or decrypt historical:', err);
toast.error('Failed to save cracked channel', {
toast.error('Failed to save found channel', {
description:
err instanceof Error ? err.message : 'Channel discovered but could not be saved',
});
@@ -409,7 +409,10 @@ export function CrackerPanel({
const handleStart = () => {
if (!gpuAvailable) {
toast.error('WebGPU not available', {
description: 'Cracking requires Chrome 113+ or Edge 113+ with WebGPU support.',
description:
typeof window !== 'undefined' && !window.isSecureContext
? 'WebGPU requires HTTPS when not on localhost. Set up a certificate or configure your browser to treat this origin as secure.'
: 'Channel finder requires Chrome 113+ or Edge 113+ with WebGPU support.',
});
return;
}
@@ -537,7 +540,7 @@ export function CrackerPanel({
Pending: <span className="text-foreground font-medium">{pendingCount}</span>
</span>
<span className="text-muted-foreground">
Cracked: <span className="text-success font-medium">{crackedCount}</span>
Found: <span className="text-success font-medium">{crackedCount}</span>
</span>
<span className="text-muted-foreground">
Failed: <span className="text-destructive font-medium">{failedCount}</span>
@@ -581,7 +584,7 @@ export function CrackerPanel({
aria-valuenow={Math.round(progress.percent)}
aria-valuemin={0}
aria-valuemax={100}
aria-label="Cracking progress"
aria-label="Channel finder progress"
>
<div
className="h-full bg-primary transition-all duration-200"
@@ -593,8 +596,26 @@ export function CrackerPanel({
{/* GPU status */}
{gpuAvailable === false && (
<div className="text-sm text-destructive" role="alert">
WebGPU not available. Cracking requires Chrome 113+ or Edge 113+.
<div className="text-sm text-destructive space-y-1.5" role="alert">
<p>WebGPU not available.</p>
{typeof window !== 'undefined' && !window.isSecureContext ? (
<div className="rounded-md border border-destructive/30 bg-destructive/5 p-2.5 text-xs text-destructive/90">
<p className="font-medium mb-1">WebGPU requires HTTPS when not on localhost.</p>
<p>To enable it:</p>
<ul className="list-disc ml-4 mt-1 space-y-0.5">
<li>
Set up a TLS certificate (see the HTTPS section of README_ADVANCED.md, or re-run
the Docker setup script which can generate one automatically)
</li>
<li>
Or configure your browser to treat this origin as secure (sometimes called
&ldquo;insecure origins treated as secure&rdquo; in browser flags)
</li>
</ul>
</div>
) : (
<p>Channel finder requires Chrome 113+ or Edge 113+ with WebGPU support.</p>
)}
</div>
)}
{!wordlistLoaded && gpuAvailable !== false && (
@@ -603,10 +624,10 @@ export function CrackerPanel({
</div>
)}
{/* Cracked channels list */}
{/* Found channels list */}
{crackedChannels.length > 0 && (
<div>
<div className="text-xs text-muted-foreground mb-1">Cracked Channels:</div>
<div className="text-xs text-muted-foreground mb-1">Found Channels:</div>
<div className="space-y-1">
{crackedChannels.map((channel, i) => (
<div
@@ -630,8 +651,8 @@ export function CrackerPanel({
force payloads as they arrive, testing channel names up to the specified length to discover
active channels on the local mesh (GroupText packets may not be hashtag messages; we have no
way of knowing but try as if they are).
<strong> Retry failed at n+1</strong> will let the cracker return to the failed queue and
pick up messages it couldn't crack, attempting them at one longer length.
<strong> Retry failed at n+1</strong> will return to the failed queue and pick up messages
it couldn't find a key for, attempting them at one longer length.
<strong> Try word pairs</strong> will also try every combination of two dictionary words
concatenated together (e.g. "hello" + "world" = "#helloworld") after the single-word
dictionary pass; this can substantially increase search time and also result in
@@ -639,7 +660,7 @@ export function CrackerPanel({
<strong> Decrypt historical</strong> will run an async job on any channel name it finds to
see if any historically captured packets will decrypt with that key.
<strong> Turbo mode</strong> will push your GPU to the max (target dispatch time of 10s) and
may allow accelerated cracking and/or system instability.
may allow accelerated searching and/or system instability.
</p>
</div>
);
+643 -65
View File
@@ -1,16 +1,47 @@
import { Fragment, useEffect, useState, useMemo, useRef, useCallback } from 'react';
import { MapContainer, TileLayer, CircleMarker, Popup, useMap } from 'react-leaflet';
import { MapContainer, TileLayer, CircleMarker, Popup, useMap, Polyline } from 'react-leaflet';
import type { LatLngBoundsExpression, CircleMarker as LeafletCircleMarker } from 'leaflet';
import L from 'leaflet';
import 'leaflet/dist/leaflet.css';
import type { Contact } from '../types';
import type { Contact, RadioConfig, RawPacket } from '../types';
import { formatTime } from '../utils/messageParser';
import { isValidLocation } from '../utils/pathUtils';
import { CONTACT_TYPE_REPEATER } from '../types';
import {
parsePacket,
getPacketLabel,
PARTICLE_COLOR_MAP,
dedupeConsecutive,
} from '../utils/visualizerUtils';
import { getRawPacketObservationKey } from '../utils/rawPacketIdentity';
interface MapViewProps {
contacts: Contact[];
/** Public key of contact to focus on and open popup */
focusedKey?: string | null;
rawPackets?: RawPacket[];
config?: RadioConfig | null;
}
// --- Tile layer presets ---
const TILE_LIGHT = {
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
background: '#1a1a2e',
};
const TILE_DARK = {
url: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png',
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="https://carto.com/">CARTO</a>',
background: '#0d0d0d',
};
function getSavedDarkMap(): boolean {
try {
return localStorage.getItem('remoteterm-dark-map') === 'true';
} catch {
return false;
}
}
const MAP_RECENCY_COLORS = {
@@ -22,7 +53,16 @@ const MAP_RECENCY_COLORS = {
const MAP_MARKER_STROKE = '#0f172a';
const MAP_REPEATER_RING = '#f8fafc';
// Calculate marker color based on how recently the contact was heard
// --- Packet visualization constants ---
const THREE_DAYS_SEC = 3 * 24 * 60 * 60;
const PARTICLE_LIFETIME_MS = 3000;
const PARTICLE_TAIL_LENGTH = 0.25; // fraction of progress to trail behind
const PARTICLE_RADIUS = 8;
const PARTICLE_TAIL_WIDTH = 5;
const MAX_MAP_PARTICLES = 200;
// --- Helpers ---
function getMarkerColor(lastSeen: number | null | undefined): string {
if (lastSeen == null) return MAP_RECENCY_COLORS.old;
const now = Date.now() / 1000;
@@ -36,7 +76,85 @@ function getMarkerColor(lastSeen: number | null | undefined): string {
return MAP_RECENCY_COLORS.old;
}
// Component to handle map bounds fitting
/** Resolve a hop token to a single contact with GPS, or null. */
function resolveHopToGps(hopToken: string, prefixIndex: Map<string, Contact[]>): Contact | null {
const matches = prefixIndex.get(hopToken.toLowerCase());
if (!matches || matches.length !== 1) return null;
const c = matches[0];
return isValidLocation(c.lat, c.lon) ? c : null;
}
/** Resolve a contact by display name (for GroupText senders). */
function resolveNameToGps(name: string, nameIndex: Map<string, Contact>): Contact | null {
const c = nameIndex.get(name);
if (!c) return null;
return isValidLocation(c.lat, c.lon) ? c : null;
}
/** Collect public keys of all unambiguously resolved GPS-bearing contacts from a parsed packet. */
function resolvePacketContacts(
parsed: ReturnType<typeof parsePacket>,
prefixIndex: Map<string, Contact[]>,
nameIndex: Map<string, Contact>,
myLatLon: [number, number] | null,
config?: RadioConfig | null
): Set<string> {
const keys = new Set<string>();
if (!parsed) return keys;
// Source by pubkey prefix
const sourcePrefixes = parsed.advertPubkey
? [parsed.advertPubkey.slice(0, 12).toLowerCase()]
: parsed.srcHash
? [parsed.srcHash.toLowerCase()]
: [];
for (const prefix of sourcePrefixes) {
const matches = prefixIndex.get(prefix);
if (matches?.length === 1 && isValidLocation(matches[0].lat, matches[0].lon)) {
keys.add(matches[0].public_key);
}
}
// Source by name (GroupText sender)
if (parsed.groupTextSender) {
const c = resolveNameToGps(parsed.groupTextSender, nameIndex);
if (c) keys.add(c.public_key);
}
// Intermediate hops
for (const hop of parsed.pathBytes) {
if (hop.length < 4) continue;
const matches = prefixIndex.get(hop.toLowerCase());
if (matches?.length === 1 && isValidLocation(matches[0].lat, matches[0].lon)) {
keys.add(matches[0].public_key);
}
}
// Self
if (myLatLon && config?.public_key) {
keys.add(config.public_key.toLowerCase());
}
// Destination
if (parsed.dstHash) {
const matches = prefixIndex.get(parsed.dstHash.toLowerCase());
if (matches?.length === 1 && isValidLocation(matches[0].lat, matches[0].lon)) {
keys.add(matches[0].public_key);
}
}
return keys;
}
interface MapParticle {
id: number;
path: [number, number][]; // lat/lon waypoints
color: string;
startedAt: number;
}
// --- Map bounds handler ---
function MapBoundsHandler({
contacts,
focusedContact,
@@ -48,7 +166,6 @@ function MapBoundsHandler({
const [hasInitialized, setHasInitialized] = useState(false);
useEffect(() => {
// If we have a focused contact, center on it immediately (even if already initialized)
if (focusedContact && focusedContact.lat != null && focusedContact.lon != null) {
map.setView([focusedContact.lat, focusedContact.lon], 12);
setHasInitialized(true);
@@ -59,20 +176,17 @@ function MapBoundsHandler({
const fitToContacts = () => {
if (contacts.length === 0) {
// No contacts with location - show world view
map.setView([20, 0], 2);
setHasInitialized(true);
return;
}
if (contacts.length === 1) {
// Single contact - center on it
map.setView([contacts[0].lat!, contacts[0].lon!], 10);
setHasInitialized(true);
return;
}
// Multiple contacts - fit bounds
const bounds: LatLngBoundsExpression = contacts.map(
(c) => [c.lat!, c.lon!] as [number, number]
);
@@ -80,22 +194,18 @@ function MapBoundsHandler({
setHasInitialized(true);
};
// Try geolocation first
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(
(position) => {
// Success - center on user location with reasonable zoom
map.setView([position.coords.latitude, position.coords.longitude], 8);
setHasInitialized(true);
},
() => {
// Geolocation denied/failed - fit to contacts
fitToContacts();
},
{ timeout: 5000, maximumAge: 300000 }
);
} else {
// No geolocation support - fit to contacts
fitToContacts();
}
}, [map, contacts, hasInitialized, focusedContact]);
@@ -103,18 +213,404 @@ function MapBoundsHandler({
return null;
}
export function MapView({ contacts, focusedKey }: MapViewProps) {
const [sevenDaysAgo] = useState(() => Date.now() / 1000 - 7 * 24 * 60 * 60);
// --- Canvas particle overlay ---
// Filter to contacts with GPS coordinates, heard within the last 7 days.
// Always include the focused contact so "view on map" links work for older nodes.
function ParticleOverlay({ particles }: { particles: MapParticle[] }) {
const map = useMap();
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const animRef = useRef<number>(0);
useEffect(() => {
const container = map.getContainer();
const canvas = document.createElement('canvas');
canvas.style.position = 'absolute';
canvas.style.top = '0';
canvas.style.left = '0';
canvas.style.pointerEvents = 'none';
canvas.style.zIndex = '450'; // above tiles, below popups
container.appendChild(canvas);
canvasRef.current = canvas;
const resize = () => {
const size = map.getSize();
canvas.width = size.x * window.devicePixelRatio;
canvas.height = size.y * window.devicePixelRatio;
canvas.style.width = `${size.x}px`;
canvas.style.height = `${size.y}px`;
};
resize();
map.on('resize', resize);
map.on('zoom', resize);
return () => {
cancelAnimationFrame(animRef.current);
map.off('resize', resize);
map.off('zoom', resize);
container.removeChild(canvas);
canvasRef.current = null;
};
}, [map]);
useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) return;
const ctx = canvas.getContext('2d');
if (!ctx) return;
const draw = () => {
const now = Date.now();
const dpr = window.devicePixelRatio;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.scale(dpr, dpr);
for (const particle of particles) {
const elapsed = now - particle.startedAt;
if (elapsed < 0 || elapsed > PARTICLE_LIFETIME_MS) continue;
const progress = elapsed / PARTICLE_LIFETIME_MS;
const path = particle.path;
if (path.length < 2) continue;
// Calculate total path length in pixels for even speed
const pixelPath = path.map((ll) => map.latLngToContainerPoint(L.latLng(ll[0], ll[1])));
const segLengths: number[] = [];
let totalLen = 0;
for (let i = 1; i < pixelPath.length; i++) {
const dx = pixelPath[i].x - pixelPath[i - 1].x;
const dy = pixelPath[i].y - pixelPath[i - 1].y;
const len = Math.sqrt(dx * dx + dy * dy);
segLengths.push(len);
totalLen += len;
}
if (totalLen === 0) continue;
// Interpolate head position
const headDist = progress * totalLen;
const tailDist = Math.max(0, headDist - PARTICLE_TAIL_LENGTH * totalLen);
const pointAtDist = (d: number): { x: number; y: number } => {
let accum = 0;
for (let i = 0; i < segLengths.length; i++) {
if (accum + segLengths[i] >= d) {
const t = segLengths[i] > 0 ? (d - accum) / segLengths[i] : 0;
return {
x: pixelPath[i].x + (pixelPath[i + 1].x - pixelPath[i].x) * t,
y: pixelPath[i].y + (pixelPath[i + 1].y - pixelPath[i].y) * t,
};
}
accum += segLengths[i];
}
const last = pixelPath[pixelPath.length - 1];
return { x: last.x, y: last.y };
};
const head = pointAtDist(headDist);
const tail = pointAtDist(tailDist);
// Draw tail as a gradient line from transparent to opaque
const grad = ctx.createLinearGradient(tail.x, tail.y, head.x, head.y);
grad.addColorStop(0, particle.color + '00');
grad.addColorStop(1, particle.color + 'cc');
ctx.beginPath();
ctx.moveTo(tail.x, tail.y);
// Sample intermediate points along the tail for curved paths
const steps = 8;
for (let s = 1; s <= steps; s++) {
const d = tailDist + ((headDist - tailDist) * s) / steps;
const pt = pointAtDist(d);
ctx.lineTo(pt.x, pt.y);
}
ctx.strokeStyle = grad;
ctx.lineWidth = PARTICLE_TAIL_WIDTH;
ctx.lineCap = 'round';
ctx.stroke();
// Draw head blob with glow
const fade = progress > 0.8 ? 1 - (progress - 0.8) / 0.2 : 1;
const alpha = Math.round(fade * 230)
.toString(16)
.padStart(2, '0');
// Outer glow
ctx.beginPath();
ctx.arc(head.x, head.y, PARTICLE_RADIUS + 4, 0, Math.PI * 2);
ctx.fillStyle =
particle.color +
Math.round(fade * 40)
.toString(16)
.padStart(2, '0');
ctx.fill();
// Core blob
ctx.beginPath();
ctx.arc(head.x, head.y, PARTICLE_RADIUS, 0, Math.PI * 2);
ctx.fillStyle = particle.color + alpha;
ctx.shadowColor = particle.color;
ctx.shadowBlur = 12 * fade;
ctx.fill();
ctx.shadowBlur = 0;
// Bright center
ctx.beginPath();
ctx.arc(head.x, head.y, PARTICLE_RADIUS * 0.4, 0, Math.PI * 2);
ctx.fillStyle = '#ffffff' + alpha;
ctx.fill();
}
ctx.restore();
animRef.current = requestAnimationFrame(draw);
};
animRef.current = requestAnimationFrame(draw);
return () => cancelAnimationFrame(animRef.current);
}, [map, particles]);
// Redraw on map move/zoom
useEffect(() => {
const redraw = () => {}; // Animation loop already redraws every frame
map.on('move', redraw);
map.on('zoom', redraw);
return () => {
map.off('move', redraw);
map.off('zoom', redraw);
};
}, [map]);
return null;
}
// --- Main component ---
export function MapView({ contacts, focusedKey, rawPackets, config }: MapViewProps) {
const [sevenDaysAgo] = useState(() => Date.now() / 1000 - 7 * 24 * 60 * 60);
const [darkMap, setDarkMap] = useState(getSavedDarkMap);
const tile = darkMap ? TILE_DARK : TILE_LIGHT;
// Sync with settings changes from other components
useEffect(() => {
const onStorage = (e: StorageEvent) => {
if (e.key === 'remoteterm-dark-map') setDarkMap(e.newValue === 'true');
};
window.addEventListener('storage', onStorage);
return () => window.removeEventListener('storage', onStorage);
}, []);
const [showPackets, setShowPackets] = useState(false);
const [discoveryMode, setDiscoveryMode] = useState(false);
const [discoveredKeys, setDiscoveredKeys] = useState<Set<string>>(new Set());
const [particles, setParticles] = useState<MapParticle[]>([]);
const particleIdRef = useRef(0);
const seenObservationsRef = useRef(new Set<string>());
// Build prefix index and name index for hop resolution
const { prefixIndex, nameIndex } = useMemo(() => {
const prefix = new Map<string, Contact[]>();
const name = new Map<string, Contact>();
for (const c of contacts) {
const pubkey = c.public_key.toLowerCase();
for (let len = 1; len <= 12 && len <= pubkey.length; len++) {
const p = pubkey.slice(0, len);
const arr = prefix.get(p);
if (arr) arr.push(c);
else prefix.set(p, [c]);
}
if (c.name && !name.has(c.name)) name.set(c.name, c);
}
return { prefixIndex: prefix, nameIndex: name };
}, [contacts]);
// Self GPS
const myLatLon = useMemo<[number, number] | null>(() => {
if (!config || !isValidLocation(config.lat, config.lon)) return null;
return [config.lat, config.lon];
}, [config]);
// Determine time window for packet visualization
const threeDaysAgoSec = useMemo(() => Date.now() / 1000 - THREE_DAYS_SEC, []);
// Filter contacts for map display
const mappableContacts = useMemo(() => {
if (showPackets && discoveryMode) {
// Discovery mode: only show nodes that have appeared in resolved packets
return contacts.filter(
(c) => isValidLocation(c.lat, c.lon) && discoveredKeys.has(c.public_key)
);
}
if (showPackets) {
// Packet mode: show only last 3 days
return contacts.filter(
(c) =>
isValidLocation(c.lat, c.lon) &&
(c.public_key === focusedKey || (c.last_seen != null && c.last_seen > threeDaysAgoSec))
);
}
return contacts.filter(
(c) =>
isValidLocation(c.lat, c.lon) &&
(c.public_key === focusedKey || (c.last_seen != null && c.last_seen > sevenDaysAgo))
);
}, [contacts, focusedKey, sevenDaysAgo]);
}, [
contacts,
focusedKey,
sevenDaysAgo,
threeDaysAgoSec,
showPackets,
discoveryMode,
discoveredKeys,
]);
// Resolve a path of hop tokens to geographic waypoints (only unambiguous + has GPS)
const resolvePacketPath = useCallback(
(parsed: ReturnType<typeof parsePacket>): [number, number][] | null => {
if (!parsed) return null;
const waypoints: [number, number][] = [];
// Source: advertPubkey, srcHash, or groupTextSender resolved by name
let sourceContact: Contact | null = null;
if (parsed.advertPubkey) {
const prefix = parsed.advertPubkey.slice(0, 12).toLowerCase();
const matches = prefixIndex.get(prefix);
if (matches?.length === 1 && isValidLocation(matches[0].lat, matches[0].lon)) {
sourceContact = matches[0];
}
} else if (parsed.srcHash) {
sourceContact = resolveHopToGps(parsed.srcHash, prefixIndex);
} else if (parsed.groupTextSender) {
sourceContact = resolveNameToGps(parsed.groupTextSender, nameIndex);
}
if (sourceContact) {
waypoints.push([sourceContact.lat!, sourceContact.lon!]);
}
// Intermediate hops (path bytes)
for (const hop of parsed.pathBytes) {
// Only resolve 2+ byte hops (4+ hex chars) to avoid ambiguous 1-byte hops
if (hop.length < 4) continue;
const contact = resolveHopToGps(hop, prefixIndex);
if (contact) {
waypoints.push([contact.lat!, contact.lon!]);
}
}
// Destination: self (our radio), or dstHash
if (myLatLon) {
waypoints.push(myLatLon);
} else if (parsed.dstHash) {
const dest = resolveHopToGps(parsed.dstHash, prefixIndex);
if (dest) {
waypoints.push([dest.lat!, dest.lon!]);
}
}
// Dedupe consecutive identical waypoints
const deduped = dedupeConsecutive(waypoints.map((w) => `${w[0]},${w[1]}`));
if (deduped.length < 2) return null;
return deduped.map((s) => {
const [lat, lon] = s.split(',').map(Number);
return [lat, lon] as [number, number];
});
},
[prefixIndex, nameIndex, myLatLon]
);
// Process new packets into particles and track discovered contacts
useEffect(() => {
if (!showPackets || !rawPackets?.length) return;
const now = Date.now();
const newParticles: MapParticle[] = [];
const newDiscovered = new Set<string>();
for (const pkt of rawPackets) {
// Skip old packets
if (pkt.timestamp < threeDaysAgoSec) continue;
// Deduplicate by observation
const obsKey = getRawPacketObservationKey(pkt);
if (seenObservationsRef.current.has(obsKey)) continue;
const parsed = parsePacket(pkt.data);
if (!parsed) continue;
// Discover contacts from this packet regardless of whether a full path resolves
const resolvedContacts = resolvePacketContacts(
parsed,
prefixIndex,
nameIndex,
myLatLon,
config
);
const path = resolvePacketPath(parsed);
// Only mark as seen if we got something useful; otherwise a later run
// with updated contacts/config can retry this observation.
if (resolvedContacts.size === 0 && !path) continue;
seenObservationsRef.current.add(obsKey);
for (const key of resolvedContacts) newDiscovered.add(key);
if (path) {
newParticles.push({
id: particleIdRef.current++,
path,
color: PARTICLE_COLOR_MAP[getPacketLabel(parsed.payloadType)],
startedAt: now,
});
}
}
if (newDiscovered.size > 0) {
setDiscoveredKeys((prev) => {
const next = new Set(prev);
for (const k of newDiscovered) next.add(k);
return next.size !== prev.size ? next : prev;
});
}
if (newParticles.length === 0) return;
setParticles((prev) => {
const combined = [...prev, ...newParticles];
// Prune expired and cap total
const alive = combined.filter((p) => now - p.startedAt < PARTICLE_LIFETIME_MS);
return alive.slice(-MAX_MAP_PARTICLES);
});
}, [
rawPackets,
showPackets,
resolvePacketPath,
threeDaysAgoSec,
prefixIndex,
nameIndex,
myLatLon,
config,
]);
// Prune expired particles periodically
useEffect(() => {
if (!showPackets) return;
const interval = setInterval(() => {
const now = Date.now();
setParticles((prev) => prev.filter((p) => now - p.startedAt < PARTICLE_LIFETIME_MS));
}, 1000);
return () => clearInterval(interval);
}, [showPackets]);
// Reset discovered set when exiting discovery mode
useEffect(() => {
if (!discoveryMode) setDiscoveredKeys(new Set());
}, [discoveryMode]);
// Clear state when toggling off
useEffect(() => {
if (!showPackets) {
setParticles([]);
setDiscoveredKeys(new Set());
setDiscoveryMode(false);
seenObservationsRef.current.clear();
}
}, [showPackets]);
// Find the focused contact by key
const focusedContact = useMemo(() => {
@@ -124,18 +620,17 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
const includesFocusedOutsideWindow =
focusedContact != null &&
(focusedContact.last_seen == null || focusedContact.last_seen <= sevenDaysAgo);
(focusedContact.last_seen == null ||
focusedContact.last_seen <= (showPackets ? threeDaysAgoSec : sevenDaysAgo));
// Track marker refs to open popup programmatically
const markerRefs = useRef<Record<string, LeafletCircleMarker | null>>({});
// Store ref for a marker
const setMarkerRef = useCallback((key: string, ref: LeafletCircleMarker | null) => {
if (ref === null) {
delete markerRefs.current[key];
return;
}
markerRefs.current[key] = ref;
}, []);
@@ -148,10 +643,8 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
}
}, [mappableContacts]);
// Open popup for focused contact after map is ready
useEffect(() => {
if (focusedContact && markerRefs.current[focusedContact.public_key]) {
// Small delay to ensure map has finished rendering
const timer = setTimeout(() => {
markerRefs.current[focusedContact.public_key]?.openPopup();
}, 100);
@@ -159,48 +652,104 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
}
}, [focusedContact]);
// Gather unique link paths for static route lines when packet viz is on
const routeLines = useMemo(() => {
if (!showPackets) return [];
const seen = new Set<string>();
const lines: { path: [number, number][]; color: string }[] = [];
for (const p of particles) {
const key = p.path.map((w) => `${w[0]},${w[1]}`).join('|');
if (seen.has(key)) continue;
seen.add(key);
lines.push({ path: p.path, color: p.color });
}
return lines;
}, [showPackets, particles]);
const timeWindowLabel = showPackets ? '3 days' : '7 days';
const infoLabel =
showPackets && discoveryMode
? `${mappableContacts.length} node${mappableContacts.length !== 1 ? 's' : ''} discovered from live traffic`
: `Showing ${mappableContacts.length} contact${mappableContacts.length !== 1 ? 's' : ''} heard in the last ${timeWindowLabel}${includesFocusedOutsideWindow ? ' plus the focused contact' : ''}`;
return (
<div className="flex flex-col h-full">
{/* Info bar */}
<div className="px-4 py-2 bg-muted/50 text-xs text-muted-foreground flex items-center justify-between">
<span>
Showing {mappableContacts.length} contact{mappableContacts.length !== 1 ? 's' : ''} heard
in the last 7 days
{includesFocusedOutsideWindow ? ' plus the focused contact' : ''}
</span>
<span>{infoLabel}</span>
<div className="flex items-center gap-3">
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.recent }}
aria-hidden="true"
/>{' '}
&lt;1h
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.today }}
aria-hidden="true"
/>{' '}
&lt;1d
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.stale }}
aria-hidden="true"
/>{' '}
&lt;3d
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.old }}
aria-hidden="true"
/>{' '}
older
</span>
{!showPackets && (
<>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.recent }}
aria-hidden="true"
/>{' '}
&lt;1h
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.today }}
aria-hidden="true"
/>{' '}
&lt;1d
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.stale }}
aria-hidden="true"
/>{' '}
&lt;3d
</span>
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full"
style={{ backgroundColor: MAP_RECENCY_COLORS.old }}
aria-hidden="true"
/>{' '}
older
</span>
</>
)}
{showPackets && (
<>
<span className="flex items-center gap-1">
<span
className="w-2 h-2 rounded-full"
style={{ backgroundColor: PARTICLE_COLOR_MAP['AD'] }}
aria-hidden="true"
/>
Ad
</span>
<span className="flex items-center gap-1">
<span
className="w-2 h-2 rounded-full"
style={{ backgroundColor: PARTICLE_COLOR_MAP['GT'] }}
aria-hidden="true"
/>
Ch
</span>
<span className="flex items-center gap-1">
<span
className="w-2 h-2 rounded-full"
style={{ backgroundColor: PARTICLE_COLOR_MAP['DM'] }}
aria-hidden="true"
/>
DM
</span>
<span className="flex items-center gap-1">
<span
className="w-2 h-2 rounded-full"
style={{ backgroundColor: PARTICLE_COLOR_MAP['ACK'] }}
aria-hidden="true"
/>
ACK
</span>
</>
)}
<span className="flex items-center gap-1">
<span
className="w-3 h-3 rounded-full border-2"
@@ -209,10 +758,30 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
/>{' '}
repeater
</span>
<label className="flex items-center gap-1.5 cursor-pointer ml-2">
<input
type="checkbox"
checked={showPackets}
onChange={(e) => setShowPackets(e.target.checked)}
className="rounded border-border"
/>
<span className="text-[0.6875rem]">Visualize packets</span>
</label>
{showPackets && (
<label className="flex items-center gap-1.5 cursor-pointer">
<input
type="checkbox"
checked={discoveryMode}
onChange={(e) => setDiscoveryMode(e.target.checked)}
className="rounded border-border"
/>
<span className="text-[0.6875rem]">Discover nodes</span>
</label>
)}
</div>
</div>
{/* Map - z-index constrained to stay below modals/sheets */}
{/* Map */}
<div
className="flex-1 relative"
style={{ zIndex: 0 }}
@@ -223,14 +792,21 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
center={[20, 0]}
zoom={2}
className="h-full w-full"
style={{ background: '#1a1a2e' }}
style={{ background: tile.background }}
>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<TileLayer key={tile.url} attribution={tile.attribution} url={tile.url} />
<MapBoundsHandler contacts={mappableContacts} focusedContact={focusedContact} />
{/* Faint route lines for active packet paths */}
{showPackets &&
routeLines.map((line, i) => (
<Polyline
key={i}
positions={line.path}
pathOptions={{ color: line.color, weight: 1, opacity: 0.15, dashArray: '4 6' }}
/>
))}
{mappableContacts.map((contact) => {
const isRepeater = contact.type === CONTACT_TYPE_REPEATER;
const color = getMarkerColor(contact.last_seen);
@@ -275,6 +851,8 @@ export function MapView({ contacts, focusedKey }: MapViewProps) {
</Fragment>
);
})}
{showPackets && <ParticleOverlay particles={particles} />}
</MapContainer>
</div>
</div>
+31 -10
View File
@@ -47,6 +47,7 @@ interface MessageListProps {
loadingNewer?: boolean;
onLoadNewer?: () => void;
onJumpToBottom?: () => void;
preSorted?: boolean;
}
// URL regex for linkifying plain text
@@ -219,8 +220,8 @@ function HopCountBadge({ paths, onClick, variant }: HopCountBadgeProps) {
const className =
variant === 'header'
? 'font-normal text-muted-foreground ml-1 text-[11px] cursor-pointer hover:text-primary hover:underline'
: 'text-[10px] text-muted-foreground ml-1 cursor-pointer hover:text-primary hover:underline';
? 'font-normal text-muted-foreground ml-1 text-[0.6875rem] cursor-pointer hover:text-primary hover:underline'
: 'text-[0.625rem] text-muted-foreground ml-1 cursor-pointer hover:text-primary hover:underline';
return (
<span
@@ -283,6 +284,7 @@ export function MessageList({
loadingNewer = false,
onLoadNewer,
onJumpToBottom,
preSorted = false,
}: MessageListProps) {
const listRef = useRef<HTMLDivElement>(null);
const prevMessagesLengthRef = useRef<number>(0);
@@ -298,6 +300,9 @@ export function MessageList({
const [resendableIds, setResendableIds] = useState<Set<number>>(new Set());
const resendTimersRef = useRef<Map<number, ReturnType<typeof setTimeout>>>(new Map());
const packetCacheRef = useRef<Map<number, RawPacket>>(new Map());
const packetSignalOverrideRef = useRef<{ rssi: number | null; snr: number | null } | undefined>(
undefined
);
const [packetInspectorSource, setPacketInspectorSource] = useState<
| { kind: 'packet'; packet: RawPacket }
| { kind: 'loading'; message: string }
@@ -323,6 +328,13 @@ export function MessageList({
const prevConvKeyRef = useRef<string | null>(null);
const handleAnalyzePacket = useCallback(async (message: Message) => {
// Extract signal from the first path if available
const firstPath = message.paths?.[0];
packetSignalOverrideRef.current =
firstPath && (firstPath.rssi != null || firstPath.snr != null)
? { rssi: firstPath.rssi ?? null, snr: firstPath.snr ?? null }
: undefined;
if (message.packet_id == null) {
setPacketInspectorSource({
kind: 'unavailable',
@@ -486,8 +498,11 @@ export function MessageList({
// Note: Deduplication is handled by useConversationMessages.observeMessage()
// and the database UNIQUE constraint on (type, conversation_key, text, sender_timestamp)
const sortedMessages = useMemo(
() => [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id),
[messages]
() =>
preSorted
? messages
: [...messages].sort((a, b) => a.received_at - b.received_at || a.id - b.id),
[messages, preSorted]
);
const unreadMarkerIndex = useMemo(() => {
if (unreadMarkerLastReadAt === undefined) {
@@ -960,7 +975,7 @@ export function MessageList({
)}
>
{showAvatar && (
<div className="text-[13px] font-semibold text-foreground mb-0.5">
<div className="text-[0.8125rem] font-semibold text-foreground mb-0.5">
{canClickSender ? (
<span
className="cursor-pointer hover:text-primary transition-colors"
@@ -975,8 +990,8 @@ export function MessageList({
) : (
displaySender
)}
<span className="font-normal text-muted-foreground ml-2 text-[11px]">
{formatTime(msg.sender_timestamp || msg.received_at)}
<span className="font-normal text-muted-foreground ml-2 text-[0.6875rem]">
{formatTime(msg.received_at)}
</span>
{!msg.outgoing && msg.paths && msg.paths.length > 0 && (
<HopCountBadge
@@ -1003,8 +1018,8 @@ export function MessageList({
))}
{!showAvatar && (
<>
<span className="text-[10px] text-muted-foreground ml-2">
{formatTime(msg.sender_timestamp || msg.received_at)}
<span className="text-[0.625rem] text-muted-foreground ml-2">
{formatTime(msg.received_at)}
</span>
{!msg.outgoing && msg.paths && msg.paths.length > 0 && (
<HopCountBadge
@@ -1175,12 +1190,18 @@ export function MessageList({
{packetInspectorSource && (
<RawPacketInspectorDialog
open={packetInspectorSource !== null}
onOpenChange={(isOpen) => !isOpen && setPacketInspectorSource(null)}
onOpenChange={(isOpen) => {
if (!isOpen) {
setPacketInspectorSource(null);
packetSignalOverrideRef.current = undefined;
}
}}
channels={channels}
source={packetInspectorSource}
title="Analyze Packet"
description="On-demand raw packet analysis for a message-backed archival packet."
notice={ANALYZE_PACKET_NOTICE}
signalOverride={packetSignalOverrideRef.current}
/>
)}
</div>
+16 -5
View File
@@ -103,14 +103,25 @@ export function PathModal({
) : null}
{/* Raw path summary */}
<div className="text-sm">
<div className="text-sm space-y-1">
{paths.map((p, index) => {
const hops = parsePathHops(p.path, p.path_len);
const rawPath = hops.length > 0 ? hops.join('->') : 'direct';
const hasSignal = p.rssi != null || p.snr != null;
return (
<div key={index}>
<span className="text-foreground/70 font-semibold">Path {index + 1}:</span>{' '}
<span className="font-mono text-muted-foreground">{rawPath}</span>
<div>
<span className="text-foreground/70 font-semibold">Path {index + 1}:</span>{' '}
<span className="font-mono text-muted-foreground">{rawPath}</span>
</div>
{hasSignal && (
<div className="text-[0.6875rem] text-muted-foreground ml-4">
Last hop (as heard by you):{' '}
{p.rssi != null && <span>{p.rssi} dBm RSSI</span>}
{p.rssi != null && p.snr != null && <span> · </span>}
{p.snr != null && <span>{p.snr.toFixed(1)} dB SNR</span>}
</div>
)}
</div>
);
})}
@@ -221,7 +232,7 @@ export function PathModal({
>
<span className="flex flex-col items-center leading-tight">
<span> Resend</span>
<span className="text-[10px] font-normal opacity-80">
<span className="text-[0.625rem] font-normal opacity-80">
Only repeated by new repeaters
</span>
</span>
@@ -237,7 +248,7 @@ export function PathModal({
>
<span className="flex flex-col items-center leading-tight">
<span> Resend as new</span>
<span className="text-[10px] font-normal opacity-80">
<span className="text-[0.625rem] font-normal opacity-80">
Will appear as duplicate to receivers
</span>
</span>
@@ -35,6 +35,11 @@ type RawPacketInspectorDialogSource =
message: string;
};
interface SignalOverride {
rssi: number | null;
snr: number | null;
}
interface RawPacketInspectorDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
@@ -43,10 +48,12 @@ interface RawPacketInspectorDialogProps {
title: string;
description: string;
notice?: ReactNode;
signalOverride?: SignalOverride;
}
interface RawPacketInspectionPanelProps {
packet: RawPacket;
signalOverride?: SignalOverride;
channels: Channel[];
}
@@ -125,15 +132,21 @@ function formatTimestamp(timestamp: number): string {
});
}
function formatSignal(packet: RawPacket): string {
const parts: string[] = [];
if (packet.rssi !== null) {
parts.push(`${packet.rssi} dBm RSSI`);
}
if (packet.snr !== null) {
parts.push(`${packet.snr.toFixed(1)} dB SNR`);
}
return parts.length > 0 ? parts.join(' · ') : 'No signal sample';
function formatSignal(
packet: RawPacket,
signalOverride?: SignalOverride
): { lines: string[]; label: string } {
const rssi = signalOverride?.rssi ?? packet.rssi;
const snr = signalOverride?.snr ?? packet.snr;
const lines: string[] = [];
if (rssi !== null) lines.push(`${rssi} dBm RSSI`);
if (snr !== null) lines.push(`${snr.toFixed(1)} dB SNR`);
const isOverride =
signalOverride != null && (signalOverride.rssi != null || signalOverride.snr != null);
return {
lines: lines.length > 0 ? lines : ['No signal sample'],
label: isOverride ? 'Last Hop Signal' : 'Signal',
};
}
function formatByteRange(field: PacketByteField): string {
@@ -312,7 +325,7 @@ function CompactMetaCard({
}) {
return (
<div className="rounded-lg border border-border/70 bg-card/70 p-2.5">
<div className="text-[10px] uppercase tracking-[0.18em] text-muted-foreground">{label}</div>
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground">{label}</div>
<div className="mt-1 text-sm font-medium leading-tight text-foreground">{primary}</div>
{secondary ? (
<div className="mt-1 text-xs leading-tight text-muted-foreground">{secondary}</div>
@@ -340,7 +353,7 @@ function FullPacketHex({
const byteRuns = useMemo(() => buildByteRuns(bytes, byteOwners), [byteOwners, bytes]);
return (
<div className="font-mono text-[15px] leading-7 text-foreground">
<div className="font-mono text-[0.9375rem] leading-7 text-foreground">
{byteRuns.map((run, index) => {
const fieldId = run.fieldId;
const palette = fieldId ? colorMap.get(fieldId) : null;
@@ -446,7 +459,9 @@ function FieldBox({
<div className="flex flex-col items-start gap-2 sm:flex-row sm:justify-between">
<div className="min-w-0">
<div className="text-base font-semibold leading-tight text-foreground">{field.name}</div>
<div className="mt-0.5 text-[11px] text-muted-foreground">{formatByteRange(field)}</div>
<div className="mt-0.5 text-[0.6875rem] text-muted-foreground">
{formatByteRange(field)}
</div>
</div>
<div
className={cn(
@@ -464,7 +479,7 @@ function FieldBox({
{field.decryptedMessage ? (
<div className="mt-2 rounded border border-border/50 bg-background/40 p-2">
<div className="text-[10px] uppercase tracking-[0.16em] text-muted-foreground">
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground">
{field.name === 'Ciphertext' ? 'Plaintext' : 'Decoded value'}
</div>
<PlaintextContent text={field.decryptedMessage} />
@@ -486,11 +501,13 @@ function FieldBox({
<div className="text-sm font-medium leading-tight text-foreground">
{part.field}
</div>
<div className="mt-0.5 text-[11px] text-muted-foreground">Bits {part.bits}</div>
<div className="mt-0.5 text-[0.6875rem] text-muted-foreground">
Bits {part.bits}
</div>
</div>
<div className="text-right">
<div className="font-mono text-sm text-foreground">{part.binary}</div>
<div className="mt-0.5 text-[11px] text-muted-foreground">{part.value}</div>
<div className="mt-0.5 text-[0.6875rem] text-muted-foreground">{part.value}</div>
</div>
</div>
</div>
@@ -565,7 +582,11 @@ function FieldSection({
);
}
export function RawPacketInspectionPanel({ packet, channels }: RawPacketInspectionPanelProps) {
export function RawPacketInspectionPanel({
packet,
channels,
signalOverride,
}: RawPacketInspectionPanelProps) {
const decoderOptions = useMemo(() => createDecoderOptions(channels), [channels]);
const groupTextCandidates = useMemo(
() => buildGroupTextResolutionCandidates(channels),
@@ -598,7 +619,7 @@ export function RawPacketInspectionPanel({ packet, channels }: RawPacketInspecti
<section className="rounded-lg border border-border/70 bg-card/70 p-3">
<div className="flex flex-wrap items-start justify-between gap-2">
<div className="min-w-0">
<div className="text-[10px] uppercase tracking-[0.18em] text-muted-foreground">
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground">
Summary
</div>
<div className="mt-1 text-base font-semibold leading-tight text-foreground">
@@ -611,7 +632,7 @@ export function RawPacketInspectionPanel({ packet, channels }: RawPacketInspecti
</div>
{packetContext ? (
<div className="mt-2 rounded-md border border-border/60 bg-background/35 px-2.5 py-2">
<div className="text-[10px] uppercase tracking-[0.18em] text-muted-foreground">
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground">
{packetContext.title}
</div>
<div className="mt-1 text-sm font-medium leading-tight text-foreground">
@@ -637,11 +658,24 @@ export function RawPacketInspectionPanel({ packet, channels }: RawPacketInspecti
primary={`${inspection.routeTypeName} · ${inspection.payloadTypeName}`}
secondary={`${inspection.payloadVersionName} · ${formatPathMode(inspection.decoded?.pathHashSize, inspection.pathTokens.length)}`}
/>
<CompactMetaCard
label="Signal"
primary={formatSignal(packet)}
secondary={packetContext ? null : undefined}
/>
{(() => {
const sig = formatSignal(packet, signalOverride);
return (
<div className="rounded-lg border border-border/70 bg-card/70 p-2.5">
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground">
{sig.label}
</div>
{sig.lines.map((line, i) => (
<div
key={i}
className={`${i === 0 ? 'mt-1' : 'mt-0.5'} text-sm font-medium leading-tight text-foreground`}
>
{line}
</div>
))}
</div>
);
})()}
</section>
</div>
@@ -711,6 +745,7 @@ export function RawPacketInspectorDialog({
title,
description,
notice,
signalOverride,
}: RawPacketInspectorDialogProps) {
const [packetInput, setPacketInput] = useState('');
@@ -735,7 +770,13 @@ export function RawPacketInspectorDialog({
let body: ReactNode;
if (source.kind === 'packet') {
body = <RawPacketInspectionPanel packet={source.packet} channels={channels} />;
body = (
<RawPacketInspectionPanel
packet={source.packet}
channels={channels}
signalOverride={signalOverride}
/>
);
} else if (source.kind === 'paste') {
body = (
<>
@@ -211,7 +211,9 @@ function getCoverageMessage(
function StatTile({ label, value, detail }: { label: string; value: string; detail?: string }) {
return (
<div className="break-inside-avoid rounded-lg border border-border/70 bg-card/80 p-3">
<div className="text-[11px] uppercase tracking-wide text-muted-foreground">{label}</div>
<div className="text-[0.625rem] uppercase tracking-wider font-medium text-muted-foreground">
{label}
</div>
<div className="mt-1 text-xl font-semibold tabular-nums text-foreground">{value}</div>
{detail ? <div className="mt-1 text-xs text-muted-foreground">{detail}</div> : null}
</div>
@@ -329,7 +331,7 @@ function NeighborList({
: `Last seen ${new Date(item.lastSeen * 1000).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`}
</div>
{!isNeighborIdentityResolvable(item, contacts) ? (
<div className="text-[11px] text-warning">Identity not resolvable</div>
<div className="text-[0.6875rem] text-warning">Identity not resolvable</div>
) : null}
</div>
{mode !== 'signal' ? (
@@ -363,7 +365,7 @@ function TimelineChart({ bins }: { bins: PacketTimelineBin[] }) {
<section className="mb-4 break-inside-avoid rounded-lg border border-border/70 bg-card/70 p-3">
<div className="flex items-center justify-between gap-3">
<h3 className="text-sm font-semibold text-foreground">Traffic Timeline</h3>
<div className="flex flex-wrap justify-end gap-2 text-[11px] text-muted-foreground">
<div className="flex flex-wrap justify-end gap-2 text-[0.6875rem] text-muted-foreground">
{typeOrder.map((type, i) => (
<span key={type} className="inline-flex items-center gap-1">
<span
@@ -513,7 +515,7 @@ export function RawPacketFeedView({
<div className="break-inside-avoid rounded-lg border border-border/70 bg-card/70 p-3">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<div className="text-[11px] uppercase tracking-wide text-muted-foreground">
<div className="text-[0.625rem] uppercase tracking-wider font-medium text-muted-foreground">
Coverage
</div>
<div
+8 -5
View File
@@ -101,7 +101,7 @@ export function RawPacketList({ packets, channels, onPacketClick }: RawPacketLis
<div className="flex items-center gap-2">
{/* Route type badge */}
<span
className={`text-[10px] font-mono px-1.5 py-0.5 rounded ${getRouteTypeColor(decoded.routeType)}`}
className={`text-[0.625rem] font-mono px-1.5 py-0.5 rounded ${getRouteTypeColor(decoded.routeType)}`}
title={decoded.routeType}
>
{getRouteTypeLabel(decoded.routeType)}
@@ -117,26 +117,29 @@ export function RawPacketList({ packets, channels, onPacketClick }: RawPacketLis
{/* Summary */}
<span
className={cn('text-[13px]', packet.decrypted ? 'text-primary' : 'text-foreground')}
className={cn(
'text-[0.8125rem]',
packet.decrypted ? 'text-primary' : 'text-foreground'
)}
>
{decoded.summary}
</span>
{/* Time */}
<span className="text-muted-foreground ml-auto text-[12px] tabular-nums">
<span className="text-muted-foreground ml-auto text-xs tabular-nums">
{formatTime(packet.timestamp)}
</span>
</div>
{/* Signal info */}
{(packet.snr !== null || packet.rssi !== null) && (
<div className="text-[11px] text-muted-foreground mt-0.5 tabular-nums">
<div className="text-[0.6875rem] text-muted-foreground mt-0.5 tabular-nums">
{formatSignalInfo(packet)}
</div>
)}
{/* Raw hex data (always visible) */}
<div className="font-mono text-[10px] break-all text-muted-foreground mt-1.5 p-1.5 bg-background/60 rounded">
<div className="font-mono text-[0.625rem] break-all text-muted-foreground mt-1.5 p-1.5 bg-background/60 rounded">
{packet.data.toUpperCase()}
</div>
</>
+17 -16
View File
@@ -9,17 +9,10 @@ import { RepeaterLogin } from './RepeaterLogin';
import { ServerLoginStatusBanner } from './ServerLoginStatusBanner';
import { useRememberedServerPassword } from '../hooks/useRememberedServerPassword';
import { useRepeaterDashboard } from '../hooks/useRepeaterDashboard';
import { isFavorite } from '../utils/favorites';
import { handleKeyboardActivate } from '../utils/a11y';
import { isValidLocation } from '../utils/pathUtils';
import { ContactStatusInfo } from './ContactStatusInfo';
import type {
Contact,
Conversation,
Favorite,
PathDiscoveryResponse,
TelemetryHistoryEntry,
} from '../types';
import type { Contact, Conversation, PathDiscoveryResponse, TelemetryHistoryEntry } from '../types';
import { cn } from '../lib/utils';
import { TelemetryPane } from './repeater/RepeaterTelemetryPane';
import { NeighborsPane } from './repeater/RepeaterNeighborsPane';
@@ -41,7 +34,6 @@ export { formatDuration, formatClockDrift } from './repeater/repeaterPaneShared'
interface RepeaterDashboardProps {
conversation: Conversation;
contacts: Contact[];
favorites: Favorite[];
notificationsSupported: boolean;
notificationsEnabled: boolean;
notificationsPermission: NotificationPermission | 'unsupported';
@@ -54,12 +46,13 @@ interface RepeaterDashboardProps {
onToggleFavorite: (type: 'channel' | 'contact', id: string) => void;
onDeleteContact: (publicKey: string) => void;
onOpenContactInfo?: (publicKey: string) => void;
trackedTelemetryRepeaters: string[];
onToggleTrackedTelemetry: (publicKey: string) => Promise<void>;
}
export function RepeaterDashboard({
conversation,
contacts,
favorites,
notificationsSupported,
notificationsEnabled,
notificationsPermission,
@@ -72,6 +65,8 @@ export function RepeaterDashboard({
onToggleFavorite,
onDeleteContact,
onOpenContactInfo,
trackedTelemetryRepeaters,
onToggleTrackedTelemetry,
}: RepeaterDashboardProps) {
const [pathDiscoveryOpen, setPathDiscoveryOpen] = useState(false);
const contact = contacts.find((c) => c.public_key === conversation.id) ?? null;
@@ -130,7 +125,7 @@ export function RepeaterDashboard({
setTelemetryHistory(liveHistory);
}, [paneData.status?.telemetry_history]);
const isFav = isFavorite(favorites, 'contact', conversation.id);
const isFav = contact?.favorite ?? false;
const handleRepeaterLogin = async (nextPassword: string) => {
await login(nextPassword);
@@ -177,7 +172,7 @@ export function RepeaterDashboard({
)}
</h2>
<span
className="min-w-0 flex-1 truncate font-mono text-[11px] text-muted-foreground transition-colors hover:text-primary"
className="min-w-0 flex-1 truncate font-mono text-[0.6875rem] text-muted-foreground transition-colors hover:text-primary"
role="button"
tabIndex={0}
onKeyDown={handleKeyboardActivate}
@@ -193,7 +188,7 @@ export function RepeaterDashboard({
</span>
</span>
{contact && (
<div className="col-span-2 row-start-2 min-w-0 text-[11px] text-muted-foreground min-[1100px]:col-span-1 min-[1100px]:col-start-2 min-[1100px]:row-start-1">
<div className="col-span-2 row-start-2 min-w-0 text-[0.6875rem] text-muted-foreground min-[1100px]:col-span-1 min-[1100px]:col-start-2 min-[1100px]:row-start-1">
<ContactStatusInfo contact={contact} ourLat={radioLat} ourLon={radioLon} />
</div>
)}
@@ -204,7 +199,7 @@ export function RepeaterDashboard({
size="sm"
onClick={loadAll}
disabled={anyLoading}
className="h-7 px-2 text-[11px] leading-none border-success text-success hover:bg-success/10 hover:text-success sm:h-8 sm:px-3 sm:text-xs"
className="h-7 px-2 text-[0.6875rem] leading-none border-success text-success hover:bg-success/10 hover:text-success sm:h-8 sm:px-3 sm:text-xs"
>
{anyLoading ? 'Loading...' : 'Load All'}
</Button>
@@ -250,7 +245,7 @@ export function RepeaterDashboard({
aria-hidden="true"
/>
{notificationsEnabled && (
<span className="hidden md:inline text-[11px] font-medium text-status-connected">
<span className="hidden md:inline text-[0.6875rem] font-medium text-status-connected">
Notifications On
</span>
)}
@@ -396,7 +391,13 @@ export function RepeaterDashboard({
/>
{/* Telemetry history chart — full width, below console */}
<TelemetryHistoryPane entries={telemetryHistory} />
<TelemetryHistoryPane
entries={telemetryHistory}
publicKey={conversation.id}
contacts={contacts}
trackedTelemetryRepeaters={trackedTelemetryRepeaters}
onToggleTrackedTelemetry={onToggleTrackedTelemetry}
/>
</div>
)}
</div>
+4 -4
View File
@@ -290,7 +290,7 @@ export function SearchView({
<div className="flex items-center gap-2 mb-1">
<span
className={cn(
'text-[10px] font-medium px-1.5 py-0.5 rounded',
'text-[0.625rem] font-medium px-1.5 py-0.5 rounded',
result.type === 'CHAN'
? 'bg-primary/20 text-primary'
: 'bg-secondary text-secondary-foreground'
@@ -298,12 +298,12 @@ export function SearchView({
>
{typeBadge}
</span>
<span className="text-[12px] font-medium text-foreground truncate">{convName}</span>
<span className="text-[11px] text-muted-foreground ml-auto flex-shrink-0">
<span className="text-xs font-medium text-foreground truncate">{convName}</span>
<span className="text-[0.6875rem] text-muted-foreground ml-auto flex-shrink-0">
{formatTime(result.received_at)}
</span>
</div>
<div className="text-[13px] text-foreground/80 line-clamp-2 break-words">
<div className="text-[0.8125rem] text-foreground/80 line-clamp-2 break-words">
{result.sender_name && !result.outgoing && (
<span className="text-muted-foreground">{result.sender_name}: </span>
)}
@@ -50,6 +50,8 @@ interface SettingsModalBaseProps {
onToggleBlockedName?: (name: string) => void;
contacts?: Contact[];
onBulkDeleteContacts?: (deletedKeys: string[]) => void;
trackedTelemetryRepeaters?: string[];
onToggleTrackedTelemetry?: (publicKey: string) => Promise<void>;
}
export type SettingsModalProps = SettingsModalBaseProps &
@@ -85,6 +87,8 @@ export function SettingsModal(props: SettingsModalProps) {
onToggleBlockedName,
contacts,
onBulkDeleteContacts,
trackedTelemetryRepeaters,
onToggleTrackedTelemetry,
} = props;
const externalSidebarNav = props.externalSidebarNav === true;
const desktopSection = props.externalSidebarNav ? props.desktopSection : undefined;
@@ -246,6 +250,8 @@ export function SettingsModal(props: SettingsModalProps) {
onToggleBlockedName={onToggleBlockedName}
contacts={contacts}
onBulkDeleteContacts={onBulkDeleteContacts}
trackedTelemetryRepeaters={trackedTelemetryRepeaters}
onToggleTrackedTelemetry={onToggleTrackedTelemetry}
className={sectionContentClass}
/>
) : (
+23 -69
View File
@@ -19,7 +19,6 @@ import {
type Contact,
type Channel,
type Conversation,
type Favorite,
} from '../types';
import {
buildSidebarSectionSortOrders,
@@ -36,7 +35,6 @@ import { isPublicChannelKey } from '../utils/publicChannel';
import { getContactDisplayName } from '../utils/pubkey';
import { handleKeyboardActivate } from '../utils/a11y';
import { ContactAvatar } from './ContactAvatar';
import { isFavorite } from '../utils/favorites';
import { Input } from './ui/input';
import { Button } from './ui/button';
import { cn } from '@/lib/utils';
@@ -106,37 +104,19 @@ interface SidebarProps {
crackerRunning: boolean;
onToggleCracker: () => void;
onMarkAllRead: () => void;
favorites: Favorite[];
/** Legacy global sort order, used only to seed per-section local preferences. */
legacySortOrder?: SortOrder;
isConversationNotificationsEnabled?: (type: 'channel' | 'contact', id: string) => boolean;
blockedKeys?: string[];
blockedNames?: string[];
}
type InitialSectionSortState = {
orders: SidebarSectionSortOrders;
source: 'section' | 'legacy' | 'none';
};
function loadInitialSectionSortOrders(): InitialSectionSortState {
function loadInitialSectionSortOrders(): SidebarSectionSortOrders {
const storedOrders = loadLocalStorageSidebarSectionSortOrders();
if (storedOrders) {
return { orders: storedOrders, source: 'section' };
}
if (storedOrders) return storedOrders;
const legacyOrder = loadLegacyLocalStorageSortOrder();
if (legacyOrder) {
return {
orders: buildSidebarSectionSortOrders(legacyOrder),
source: 'legacy',
};
}
return {
orders: buildSidebarSectionSortOrders(),
source: 'none',
};
const orders = buildSidebarSectionSortOrders(legacyOrder ?? undefined);
saveLocalStorageSidebarSectionSortOrders(orders);
return orders;
}
export function Sidebar({
@@ -152,8 +132,6 @@ export function Sidebar({
crackerRunning,
onToggleCracker,
onMarkAllRead,
favorites,
legacySortOrder,
isConversationNotificationsEnabled,
blockedKeys = [],
blockedNames = [],
@@ -166,8 +144,8 @@ export function Sidebar({
);
const [searchQuery, setSearchQuery] = useState('');
const initialSectionSortState = useMemo(loadInitialSectionSortOrders, []);
const [sectionSortOrders, setSectionSortOrders] = useState(initialSectionSortState.orders);
const initialSectionSortOrders = useMemo(loadInitialSectionSortOrders, []);
const [sectionSortOrders, setSectionSortOrders] = useState(initialSectionSortOrders);
const initialCollapsedState = useMemo(loadCollapsedState, []);
const [toolsCollapsed, setToolsCollapsed] = useState(initialCollapsedState.tools);
const [favoritesCollapsed, setFavoritesCollapsed] = useState(initialCollapsedState.favorites);
@@ -176,29 +154,12 @@ export function Sidebar({
const [roomsCollapsed, setRoomsCollapsed] = useState(initialCollapsedState.rooms);
const [repeatersCollapsed, setRepeatersCollapsed] = useState(initialCollapsedState.repeaters);
const collapseSnapshotRef = useRef<CollapseState | null>(null);
const sectionSortSourceRef = useRef(initialSectionSortState.source);
useEffect(() => {
if (sectionSortSourceRef.current === 'legacy') {
saveLocalStorageSidebarSectionSortOrders(sectionSortOrders);
sectionSortSourceRef.current = 'section';
return;
}
if (sectionSortSourceRef.current !== 'none' || legacySortOrder === undefined) return;
const seededOrders = buildSidebarSectionSortOrders(legacySortOrder);
setSectionSortOrders(seededOrders);
saveLocalStorageSidebarSectionSortOrders(seededOrders);
sectionSortSourceRef.current = 'section';
}, [legacySortOrder, sectionSortOrders]);
const handleSortToggle = (section: SidebarSortableSection) => {
setSectionSortOrders((prev) => {
const nextOrder = prev[section] === 'alpha' ? 'recent' : 'alpha';
const updated = { ...prev, [section]: nextOrder };
saveLocalStorageSidebarSectionSortOrders(updated);
sectionSortSourceRef.current = 'section';
return updated;
});
};
@@ -523,22 +484,16 @@ export function Sidebar({
nonFavoriteRooms,
nonFavoriteRepeaters,
} = useMemo(() => {
const favChannels = filteredChannels.filter((c) => isFavorite(favorites, 'channel', c.key));
const favChannels = filteredChannels.filter((c) => c.favorite);
const favContacts = [
...filteredNonRepeaterContacts,
...filteredRooms,
...filteredRepeaters,
].filter((c) => isFavorite(favorites, 'contact', c.public_key));
const nonFavChannels = filteredChannels.filter((c) => !isFavorite(favorites, 'channel', c.key));
const nonFavContacts = filteredNonRepeaterContacts.filter(
(c) => !isFavorite(favorites, 'contact', c.public_key)
);
const nonFavRooms = filteredRooms.filter(
(c) => !isFavorite(favorites, 'contact', c.public_key)
);
const nonFavRepeaters = filteredRepeaters.filter(
(c) => !isFavorite(favorites, 'contact', c.public_key)
);
].filter((c) => c.favorite);
const nonFavChannels = filteredChannels.filter((c) => !c.favorite);
const nonFavContacts = filteredNonRepeaterContacts.filter((c) => !c.favorite);
const nonFavRooms = filteredRooms.filter((c) => !c.favorite);
const nonFavRepeaters = filteredRepeaters.filter((c) => !c.favorite);
const items: FavoriteItem[] = [
...favChannels.map((channel) => ({ type: 'channel' as const, channel })),
@@ -557,7 +512,6 @@ export function Sidebar({
filteredNonRepeaterContacts,
filteredRooms,
filteredRepeaters,
favorites,
sectionSortOrders.favorites,
sortFavoriteItemsByOrder,
]);
@@ -619,7 +573,7 @@ export function Sidebar({
contactType={row.contact.type}
/>
)}
<span className="name flex-1 truncate text-[13px]">{row.name}</span>
<span className="name flex-1 truncate text-[0.8125rem]">{row.name}</span>
<span className="ml-auto flex items-center gap-1">
{row.notificationsEnabled && (
<span aria-label="Notifications enabled" title="Notifications enabled">
@@ -629,7 +583,7 @@ export function Sidebar({
{row.unreadCount > 0 && (
<span
className={cn(
'text-[10px] font-semibold px-1.5 py-0.5 rounded-full min-w-[18px] text-center',
'text-[0.625rem] font-semibold px-1.5 py-0.5 rounded-full min-w-[18px] text-center',
highlightUnread
? 'bg-badge-mention text-badge-mention-foreground'
: 'bg-badge-unread/90 text-badge-unread-foreground'
@@ -661,7 +615,7 @@ export function Sidebar({
key={key}
data-active={active ? 'true' : undefined}
className={cn(
'sidebar-action-row px-3 py-2 cursor-pointer flex items-center gap-2 border-l-2 border-transparent hover:bg-accent transition-colors text-[13px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
'sidebar-action-row px-3 py-2 cursor-pointer flex items-center gap-2 border-l-2 border-transparent hover:bg-accent transition-colors text-[0.8125rem] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
active && 'bg-accent border-l-primary'
)}
role="button"
@@ -770,7 +724,7 @@ export function Sidebar({
{showCracker ? 'Hide' : 'Show'} Channel Finder
<span
className={cn(
'ml-1 text-[11px]',
'ml-1 text-[0.6875rem]',
crackerRunning ? 'text-primary' : 'text-muted-foreground'
)}
>
@@ -798,7 +752,7 @@ export function Sidebar({
<div className="flex justify-between items-center px-3 py-2 pt-3.5">
<button
className={cn(
'flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded',
'flex items-center gap-1.5 text-[0.625rem] uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded',
isSearching && 'cursor-default'
)}
aria-expanded={!effectiveCollapsed}
@@ -818,7 +772,7 @@ export function Sidebar({
<div className="ml-auto flex items-center gap-1.5">
{sortSection && sectionSortOrder && (
<button
className="bg-transparent text-muted-foreground/60 px-1 py-0.5 text-[10px] rounded hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
className="bg-transparent text-muted-foreground/60 px-1 py-0.5 text-[0.625rem] rounded hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
onClick={() => handleSortToggle(sortSection)}
aria-label={
sectionSortOrder === 'alpha'
@@ -837,7 +791,7 @@ export function Sidebar({
{unreadCount > 0 && (
<span
className={cn(
'text-[10px] font-medium px-1.5 py-0.5 rounded-full',
'text-[0.625rem] font-medium px-1.5 py-0.5 rounded-full',
highlightUnread
? 'bg-badge-mention text-badge-mention-foreground'
: 'bg-secondary text-muted-foreground'
@@ -866,7 +820,7 @@ export function Sidebar({
onClick={onNewMessage}
title="Add channel or contact"
aria-label="Add channel or contact"
className="h-8 w-full justify-start gap-2 border-primary/20 bg-primary/5 px-3 text-[13px] text-primary hover:bg-primary/10 hover:text-primary"
className="h-8 w-full justify-start gap-2 border-primary/20 bg-primary/5 px-3 text-[0.8125rem] text-primary hover:bg-primary/10 hover:text-primary"
>
<SquarePen className="h-4 w-4" />
<span>Add Channel/Contact</span>
@@ -883,7 +837,7 @@ export function Sidebar({
aria-label="Search conversations"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className={cn('h-7 text-[13px] bg-background/50', searchQuery ? 'pr-8' : 'pr-3')}
className={cn('h-7 text-[0.8125rem] bg-background/50', searchQuery ? 'pr-8' : 'pr-3')}
/>
{searchQuery && (
<button
@@ -909,7 +863,7 @@ export function Sidebar({
{/* Mark All Read */}
{!query && Object.values(unreadCounts).some((c) => c > 0) && (
<div
className="px-3 py-2 cursor-pointer flex items-center gap-2 border-l-2 border-transparent hover:bg-accent transition-colors text-[13px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
className="px-3 py-2 cursor-pointer flex items-center gap-2 border-l-2 border-transparent hover:bg-accent transition-colors text-[0.8125rem] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
role="button"
tabIndex={0}
onKeyDown={handleKeyboardActivate}
+1 -1
View File
@@ -123,7 +123,7 @@ export function StatusBar({
<div className="hidden lg:flex items-center gap-2 text-muted-foreground">
<span className="text-foreground font-medium">{config.name || 'Unnamed'}</span>
<span
className="font-mono text-[11px] text-muted-foreground cursor-pointer hover:text-primary transition-colors"
className="font-mono text-[0.6875rem] text-muted-foreground cursor-pointer hover:text-primary transition-colors"
role="button"
tabIndex={0}
onKeyDown={handleKeyboardActivate}
+154 -7
View File
@@ -28,6 +28,48 @@ import { cn } from '@/lib/utils';
type TraceSortMode = 'alpha' | 'recent' | 'distance';
type CustomHopBytes = 1 | 2 | 4;
const RECENT_TRACES_KEY = 'remoteterm-recent-traces';
const MAX_RECENT_TRACES = 5;
interface SavedTraceHop {
kind: 'repeater' | 'custom';
publicKey?: string;
hopHex?: string;
hopBytes?: CustomHopBytes;
displayName: string;
}
interface SavedTrace {
hops: SavedTraceHop[];
ranAt: number;
}
function loadRecentTraces(): SavedTrace[] {
try {
const raw = localStorage.getItem(RECENT_TRACES_KEY);
if (!raw) return [];
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed.slice(0, MAX_RECENT_TRACES) : [];
} catch {
return [];
}
}
function saveRecentTrace(trace: SavedTrace): void {
try {
const existing = loadRecentTraces();
// Dedupe by hop signature
const sig = trace.hops.map((h) => h.publicKey ?? h.hopHex ?? '').join(',');
const deduped = existing.filter(
(t) => t.hops.map((h) => h.publicKey ?? h.hopHex ?? '').join(',') !== sig
);
const updated = [trace, ...deduped].slice(0, MAX_RECENT_TRACES);
localStorage.setItem(RECENT_TRACES_KEY, JSON.stringify(updated));
} catch {
// localStorage may be disabled
}
}
type TraceDraftHop =
| { id: string; kind: 'repeater'; publicKey: string }
| { id: string; kind: 'custom'; hopHex: string; hopBytes: CustomHopBytes };
@@ -118,7 +160,7 @@ function TraceNodeRow({
>
<div
className={cn(
'flex h-9 w-9 items-center justify-center rounded-full border text-[11px] font-semibold uppercase tracking-wide',
'flex h-9 w-9 items-center justify-center rounded-full border text-[0.6875rem] font-semibold uppercase tracking-wide',
fixed
? 'border-primary/30 bg-primary/10 text-primary'
: 'border-border bg-muted text-muted-foreground'
@@ -129,12 +171,12 @@ function TraceNodeRow({
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-medium">{title}</div>
<div className="truncate text-xs text-muted-foreground">{subtitle}</div>
{meta ? <div className="mt-1 text-[11px] text-muted-foreground">{meta}</div> : null}
{note ? <div className="mt-1 text-[11px] text-muted-foreground">{note}</div> : null}
{meta ? <div className="mt-1 text-[0.6875rem] text-muted-foreground">{meta}</div> : null}
{note ? <div className="mt-1 text-[0.6875rem] text-muted-foreground">{note}</div> : null}
</div>
{snr ? (
<div className="shrink-0 text-right">
<div className="text-[11px] text-muted-foreground">SNR</div>
<div className="text-[0.6875rem] text-muted-foreground">SNR</div>
<div className="font-mono text-sm">{snr}</div>
</div>
) : null}
@@ -154,6 +196,7 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
const [customHopBytesDraft, setCustomHopBytesDraft] = useState<CustomHopBytes>(1);
const [customHopHexDraft, setCustomHopHexDraft] = useState('');
const [customHopError, setCustomHopError] = useState<string | null>(null);
const [recentTraces, setRecentTraces] = useState<SavedTrace[]>(loadRecentTraces);
const activeRunTokenRef = useRef(0);
const repeaters = useMemo(() => {
@@ -272,6 +315,56 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
clearPendingResult();
};
const handleLoadRecentTrace = async (trace: SavedTrace) => {
const hops: TraceDraftHop[] = trace.hops.map((h, i) => {
if (h.kind === 'repeater' && h.publicKey) {
return {
id: nextDraftHopId('repeater', i),
kind: 'repeater' as const,
publicKey: h.publicKey,
};
}
return {
id: nextDraftHopId('custom', i),
kind: 'custom' as const,
hopHex: h.hopHex ?? '',
hopBytes: h.hopBytes ?? (1 as CustomHopBytes),
};
});
setDraftHops(hops);
// Determine hop hash bytes from the loaded hops
const customHop = hops.find((h) => h.kind === 'custom');
const hopHashBytes: CustomHopBytes = customHop?.hopBytes ?? 4;
// Run the trace immediately
const runToken = activeRunTokenRef.current + 1;
activeRunTokenRef.current = runToken;
setLoading(true);
setError(null);
setResult(null);
try {
const traceResult = await onRunTracePath(
hopHashBytes,
hops.map((hop) =>
hop.kind === 'repeater' ? { public_key: hop.publicKey } : { hop_hex: hop.hopHex }
)
);
if (activeRunTokenRef.current !== runToken) return;
setResult(traceResult);
// Re-save to bump this trace to the top of recents
const savedTrace: SavedTrace = { hops: trace.hops, ranAt: Date.now() };
saveRecentTrace(savedTrace);
setRecentTraces(loadRecentTraces());
} catch (err) {
if (activeRunTokenRef.current !== runToken) return;
setError(err instanceof Error ? err.message : 'Unknown error');
} finally {
if (activeRunTokenRef.current === runToken) setLoading(false);
}
};
const handleRunTrace = async () => {
if (draftHops.length === 0) {
return;
@@ -292,6 +385,27 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
return;
}
setResult(traceResult);
// Persist to recent traces
const savedHops: SavedTraceHop[] = draftHops.map((hop) => {
if (hop.kind === 'repeater') {
const c = repeatersByKey.get(hop.publicKey);
return {
kind: 'repeater',
publicKey: hop.publicKey,
displayName: getContactDisplayName(c?.name, hop.publicKey, c?.last_advert ?? null),
};
}
return {
kind: 'custom',
hopHex: hop.hopHex,
hopBytes: hop.hopBytes,
displayName: `${hop.hopHex.toUpperCase()} (${hop.hopBytes}B)`,
};
});
const trace: SavedTrace = { hops: savedHops, ranAt: Date.now() };
saveRecentTrace(trace);
setRecentTraces(loadRecentTraces());
} catch (err) {
if (activeRunTokenRef.current !== runToken) {
return;
@@ -370,7 +484,7 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
))}
</div>
{sortMode === 'distance' && !canSortByDistance ? (
<p className="mt-2 text-[11px] text-muted-foreground">
<p className="mt-2 text-[0.6875rem] text-muted-foreground">
Distance sorting is using known repeater coordinates, but the local radio does not
currently have a valid location.
</p>
@@ -421,12 +535,12 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
{getShortKey(contact.public_key)}
</div>
{sortMode === 'distance' && distanceKm !== null ? (
<div className="mt-1 text-[11px] text-muted-foreground">
<div className="mt-1 text-[0.6875rem] text-muted-foreground">
{distanceKm.toFixed(1)} km away
</div>
) : null}
{selectedCount > 0 ? (
<div className="mt-1 text-[11px] text-muted-foreground">
<div className="mt-1 text-[0.6875rem] text-muted-foreground">
Added {selectedCount} time{selectedCount === 1 ? '' : 's'}
</div>
) : null}
@@ -453,6 +567,39 @@ export function TracePane({ contacts, config, onRunTracePath }: TracePaneProps)
<p className="mt-1 text-xs text-muted-foreground">
The first node is display-only. The terminal node is the local radio.
</p>
{recentTraces.length > 0 && (
<div className="mt-2">
<div className="text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium mb-1">
Rerun a recent trace:
</div>
<div className="flex flex-wrap gap-1.5">
{recentTraces.map((trace, i) => {
const label = trace.hops
.map((h) => {
if (h.kind === 'repeater' && h.publicKey) {
const shortKey = h.publicKey.slice(0, 12);
return h.displayName !== shortKey
? `${h.displayName} (${shortKey})`
: shortKey;
}
return h.displayName;
})
.join(' → ');
return (
<button
key={i}
type="button"
className="rounded-md border border-border px-2.5 py-1.5 text-xs hover:bg-accent transition-colors truncate max-w-full disabled:opacity-50 disabled:cursor-not-allowed"
disabled={loading}
onClick={() => handleLoadRecentTrace(trace)}
>
{label}
</button>
);
})}
</div>
</div>
)}
</div>
{draftHops.length > 0 ? (
<Button
@@ -13,6 +13,8 @@ export function ConsolePane({
}) {
const [input, setInput] = useState('');
const outputRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const prevLoadingRef = useRef(loading);
// Auto-scroll to bottom on new entries
useEffect(() => {
@@ -21,6 +23,14 @@ export function ConsolePane({
}
}, [history]);
// Refocus input after command completes
useEffect(() => {
if (prevLoadingRef.current && !loading) {
inputRef.current?.focus();
}
prevLoadingRef.current = loading;
}, [loading]);
const handleSubmit = useCallback(
async (e: FormEvent) => {
e.preventDefault();
@@ -59,6 +69,7 @@ export function ConsolePane({
</div>
<form onSubmit={handleSubmit} className="flex gap-2 p-2 border-t border-border">
<Input
ref={inputRef}
type="text"
autoComplete="off"
name="console-input"
@@ -9,7 +9,11 @@ import {
ResponsiveContainer,
} from 'recharts';
import { cn } from '@/lib/utils';
import type { TelemetryHistoryEntry } from '../../types';
import { Button } from '../ui/button';
import { Separator } from '../ui/separator';
import type { TelemetryHistoryEntry, Contact } from '../../types';
const MAX_TRACKED = 8;
type Metric = 'battery_volts' | 'noise_floor_dbm' | 'packets' | 'uptime_seconds';
@@ -47,8 +51,26 @@ function formatUptime(seconds: number): string {
return `${(seconds / 86400).toFixed(1)}d`;
}
export function TelemetryHistoryPane({ entries }: { entries: TelemetryHistoryEntry[] }) {
interface TelemetryHistoryPaneProps {
entries: TelemetryHistoryEntry[];
publicKey: string;
contacts: Contact[];
trackedTelemetryRepeaters: string[];
onToggleTrackedTelemetry: (publicKey: string) => Promise<void>;
}
export function TelemetryHistoryPane({
entries,
publicKey,
contacts,
trackedTelemetryRepeaters,
onToggleTrackedTelemetry,
}: TelemetryHistoryPaneProps) {
const [metric, setMetric] = useState<Metric>('battery_volts');
const [toggling, setToggling] = useState(false);
const isTracked = trackedTelemetryRepeaters.includes(publicKey);
const slotsFull = trackedTelemetryRepeaters.length >= MAX_TRACKED && !isTracked;
const config = METRIC_CONFIG[metric];
@@ -68,13 +90,96 @@ export function TelemetryHistoryPane({ entries }: { entries: TelemetryHistoryEnt
const dataKeys = metric === 'packets' ? ['packets_received', 'packets_sent'] : [metric];
const yDomain = useMemo<[number, number] | undefined>(() => {
if (metric !== 'battery_volts' || chartData.length === 0) return undefined;
const values = chartData.map((d) => d.battery_volts).filter((v) => v != null) as number[];
if (values.length === 0) return [3, 5];
const lo = Math.min(...values);
const hi = Math.max(...values);
return [Math.min(3, Math.floor(lo) - 1), Math.max(5, Math.ceil(hi) + 1)];
}, [metric, chartData]);
const handleToggle = async () => {
setToggling(true);
try {
await onToggleTrackedTelemetry(publicKey);
} finally {
setToggling(false);
}
};
const trackedNames = useMemo(() => {
if (!slotsFull) return [];
return trackedTelemetryRepeaters.map((key) => {
const contact = contacts.find((c) => c.public_key === key);
return { key, name: contact?.name ?? key.slice(0, 12) };
});
}, [slotsFull, trackedTelemetryRepeaters, contacts]);
return (
<div className="border border-border rounded-lg overflow-hidden">
<div className="flex items-center justify-between px-3 py-2 bg-muted/50 border-b border-border">
<h3 className="text-sm font-medium">Telemetry History</h3>
<span className="text-[10px] text-muted-foreground">{entries.length} samples</span>
<div className="flex items-center gap-2">
<h3 className="text-sm font-medium">Telemetry History</h3>
{entries.length > 0 && (
<span className="text-[0.625rem] text-muted-foreground">{entries.length} samples</span>
)}
</div>
</div>
<div className="p-3">
{/* Explanation + tracking toggle */}
<div className="mb-3 space-y-3">
<p className="text-xs text-muted-foreground leading-relaxed">
Any time repeater telemetry is fetched, the metrics are stored for 30 days (or 1,000
samples, whichever comes first). This telemetry is stored on normal interactive fetches
via the repeater pane, API calls to the endpoint (
<code className="text-[0.6875rem]">POST /api/contacts/&lt;key&gt;/repeater/status</code>
), or when the repeater is opted into interval telemetry polling, in which case the
repeater will be polled for metrics every 8 hours. You can see which repeaters are opted
into this flow in the{' '}
<a
href="#settings/database"
className="underline text-primary hover:text-primary/80 transition-colors"
>
Database &amp; Messaging
</a>{' '}
settings pane. A maximum of {MAX_TRACKED} repeaters may be opted into this for the sake
of keeping mesh congestion reasonable.
</p>
{isTracked ? (
<Button
variant="outline"
onClick={handleToggle}
disabled={toggling}
className="border-destructive/50 text-destructive hover:bg-destructive/10"
>
{toggling ? 'Updating...' : 'Remove Repeater from Interval Metrics Tracking'}
</Button>
) : slotsFull ? (
<div className="space-y-2">
<Button variant="outline" disabled>
Tracking Full ({trackedTelemetryRepeaters.length}/{MAX_TRACKED} slots used)
</Button>
<p className="text-xs text-muted-foreground">
Disable tracking on another repeater to free a slot:{' '}
{trackedNames.map((t) => t.name).join(', ')}
</p>
</div>
) : (
<Button
variant="outline"
onClick={handleToggle}
disabled={toggling}
className="border-green-600/50 text-green-600 hover:bg-green-600/10"
>
{toggling ? 'Updating...' : 'Opt Repeater into 8hr Interval Metrics Tracking'}
</Button>
)}
</div>
<Separator className="mb-3" />
{/* Metric selector */}
<div className="flex gap-1 mb-2">
{(Object.keys(METRIC_CONFIG) as Metric[]).map((m) => (
@@ -83,7 +188,7 @@ export function TelemetryHistoryPane({ entries }: { entries: TelemetryHistoryEnt
type="button"
onClick={() => setMetric(m)}
className={cn(
'text-[11px] px-2 py-0.5 rounded transition-colors',
'text-[0.6875rem] px-2 py-0.5 rounded transition-colors',
metric === m
? 'bg-primary text-primary-foreground'
: 'text-muted-foreground hover:text-foreground hover:bg-accent'
@@ -112,6 +217,7 @@ export function TelemetryHistoryPane({ entries }: { entries: TelemetryHistoryEnt
tickFormatter={formatTime}
/>
<YAxis
domain={yDomain}
tick={{ fontSize: 10, fill: 'hsl(var(--muted-foreground))' }}
tickLine={false}
axisLine={false}
@@ -149,10 +255,15 @@ export function TelemetryHistoryPane({ entries }: { entries: TelemetryHistoryEnt
fill={metric === 'packets' ? (i === 0 ? '#0ea5e9' : '#f43f5e') : config.color}
fillOpacity={0.15}
strokeWidth={1.5}
dot={false}
activeDot={{
dot={{
r: 4,
fill: metric === 'packets' ? (i === 0 ? '#0ea5e9' : '#f43f5e') : config.color,
strokeWidth: 1.5,
stroke: 'hsl(var(--popover))',
}}
activeDot={{
r: 6,
fill: metric === 'packets' ? (i === 0 ? '#0ea5e9' : '#f43f5e') : config.color,
strokeWidth: 2,
stroke: 'hsl(var(--popover))',
}}
@@ -141,10 +141,10 @@ export function RepeaterPane({
<div className="flex items-center justify-between px-3 py-2 bg-muted/50 border-b border-border">
<div className="min-w-0">
<h3 className="text-sm font-medium">{title}</h3>
{headerNote && <p className="text-[11px] text-muted-foreground">{headerNote}</p>}
{headerNote && <p className="text-[0.6875rem] text-muted-foreground">{headerNote}</p>}
{fetchedAt && (
<p
className="text-[11px] text-muted-foreground"
className="text-[0.6875rem] text-muted-foreground"
title={new Date(fetchedAt).toLocaleString()}
>
Fetched {formatFetchedTime(fetchedAt)} ({formatFetchedRelative(fetchedAt)})
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useRef } from 'react';
import { Input } from '../ui/input';
import { Label } from '../ui/label';
import { Button } from '../ui/button';
@@ -7,7 +7,13 @@ import { toast } from '../ui/sonner';
import { api } from '../../api';
import { formatTime } from '../../utils/messageParser';
import { BulkDeleteContactsModal } from './BulkDeleteContactsModal';
import type { AppSettings, AppSettingsUpdate, Contact, HealthStatus } from '../../types';
import type {
AppSettings,
AppSettingsUpdate,
Contact,
HealthStatus,
TelemetryHistoryEntry,
} from '../../types';
export function SettingsDatabaseSection({
appSettings,
@@ -20,6 +26,8 @@ export function SettingsDatabaseSection({
onToggleBlockedName,
contacts = [],
onBulkDeleteContacts,
trackedTelemetryRepeaters = [],
onToggleTrackedTelemetry,
className,
}: {
appSettings: AppSettings;
@@ -32,6 +40,8 @@ export function SettingsDatabaseSection({
onToggleBlockedName?: (name: string) => void;
contacts?: Contact[];
onBulkDeleteContacts?: (deletedKeys: string[]) => void;
trackedTelemetryRepeaters?: string[];
onToggleTrackedTelemetry?: (publicKey: string) => Promise<void>;
className?: string;
}) {
const [retentionDays, setRetentionDays] = useState('14');
@@ -44,11 +54,35 @@ export function SettingsDatabaseSection({
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [latestTelemetry, setLatestTelemetry] = useState<
Record<string, TelemetryHistoryEntry | null>
>({});
const telemetryFetchedRef = useRef(false);
useEffect(() => {
setAutoDecryptOnAdvert(appSettings.auto_decrypt_dm_on_advert);
setDiscoveryBlockedTypes(appSettings.discovery_blocked_types ?? []);
}, [appSettings]);
useEffect(() => {
if (trackedTelemetryRepeaters.length === 0 || telemetryFetchedRef.current) return;
telemetryFetchedRef.current = true;
let cancelled = false;
const fetches = trackedTelemetryRepeaters.map((key) =>
api.repeaterTelemetryHistory(key).then(
(history) => [key, history.length > 0 ? history[history.length - 1] : null] as const,
() => [key, null] as const
)
);
Promise.all(fetches).then((entries) => {
if (cancelled) return;
setLatestTelemetry(Object.fromEntries(entries));
});
return () => {
cancelled = true;
};
}, [trackedTelemetryRepeaters]);
const handleCleanup = async () => {
const days = parseInt(retentionDays, 10);
if (isNaN(days) || days < 1) {
@@ -223,6 +257,71 @@ export function SettingsDatabaseSection({
</p>
</div>
<Separator />
{/* ── Tracked Repeater Telemetry ── */}
<div className="space-y-3">
<Label className="text-base">Tracked Repeater Telemetry</Label>
<p className="text-xs text-muted-foreground">
Repeaters opted into automatic telemetry collection are polled every 8 hours. Up to 8
repeaters may be tracked at a time ({trackedTelemetryRepeaters.length} / 8 slots used).
</p>
{trackedTelemetryRepeaters.length === 0 ? (
<p className="text-sm text-muted-foreground italic">
No repeaters are being tracked. Enable tracking from a repeater's dashboard.
</p>
) : (
<div className="space-y-2">
{trackedTelemetryRepeaters.map((key) => {
const contact = contacts.find((c) => c.public_key === key);
const displayName = contact?.name ?? key.slice(0, 12);
const snap = latestTelemetry[key];
const d = snap?.data;
return (
<div key={key} className="rounded-md border border-border px-3 py-2">
<div className="flex items-center justify-between gap-2">
<div className="flex-1 min-w-0">
<span className="text-sm truncate block">{displayName}</span>
<span className="text-[0.625rem] text-muted-foreground font-mono">
{key.slice(0, 12)}
</span>
</div>
{onToggleTrackedTelemetry && (
<Button
variant="ghost"
size="sm"
onClick={() => onToggleTrackedTelemetry(key)}
className="h-7 text-xs flex-shrink-0 text-destructive hover:text-destructive"
>
Remove
</Button>
)}
</div>
{d ? (
<div className="mt-1.5 flex flex-wrap gap-x-3 gap-y-0.5 text-[0.625rem] text-muted-foreground">
<span>{d.battery_volts?.toFixed(2)}V</span>
<span>noise {d.noise_floor_dbm} dBm</span>
<span>
rx {d.packets_received != null ? d.packets_received.toLocaleString() : '?'}
</span>
<span>
tx {d.packets_sent != null ? d.packets_sent.toLocaleString() : '?'}
</span>
<span className="ml-auto">checked {formatTime(snap.timestamp)}</span>
</div>
) : snap === null ? (
<div className="mt-1 text-[0.625rem] text-muted-foreground italic">
No telemetry recorded yet
</div>
) : null}
</div>
);
})}
</div>
)}
</div>
{error && (
<div className="text-sm text-destructive" role="alert">
{error}
@@ -537,7 +537,7 @@ function CreateIntegrationDialog({
<div className="space-y-4">
{sectionedOptions.map((group) => (
<div key={group.section} className="space-y-1.5">
<div className="px-2 text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground">
<div className="px-2 text-[0.6875rem] font-semibold uppercase tracking-wider text-muted-foreground">
{group.section}
</div>
{group.options.map((option) => {
@@ -577,7 +577,7 @@ function CreateIntegrationDialog({
{selectedOption ? (
<>
<div className="space-y-1.5">
<div className="text-xs font-semibold uppercase tracking-[0.12em] text-muted-foreground">
<div className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
{selectedOption.section}
</div>
<h3 className="text-lg font-semibold">{selectedOption.label}</h3>
@@ -1,8 +1,10 @@
import { useState } from 'react';
import { Logs, MessageSquare } from 'lucide-react';
import { ChevronRight, Logs, MessageSquare, Send, Settings } from 'lucide-react';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Label } from '../ui/label';
import { Separator } from '../ui/separator';
import { cn } from '../../lib/utils';
import { ContactAvatar } from '../ContactAvatar';
import {
captureLastViewedConversationFromHash,
@@ -37,6 +39,13 @@ export function SettingsLocalSection({
const [reopenLastConversation, setReopenLastConversation] = useState(
getReopenLastConversationEnabled
);
const [darkMap, setDarkMap] = useState(() => {
try {
return localStorage.getItem('remoteterm-dark-map') === 'true';
} catch {
return false;
}
});
const [localLabelText, setLocalLabelText] = useState(() => getLocalLabel().text);
const [localLabelColor, setLocalLabelColor] = useState(() => getLocalLabel().color);
const [fontScale, setFontScale] = useState(getSavedFontScale);
@@ -233,11 +242,31 @@ export function SettingsLocalSection({
/>
<span className="text-sm">Reopen to last viewed channel/conversation</span>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={darkMap}
onChange={(e) => {
const v = e.target.checked;
setDarkMap(v);
try {
localStorage.setItem('remoteterm-dark-map', String(v));
} catch {
// localStorage may be disabled
}
}}
className="w-4 h-4 rounded border-input accent-primary"
/>
<span className="text-sm">Dark mode map tiles</span>
</label>
</div>
);
}
function ThemePreview({ className }: { className?: string }) {
const [showStyleRef, setShowStyleRef] = useState(false);
return (
<div className={`rounded-lg border border-border bg-card p-3 ${className ?? ''}`}>
<p className="text-xs text-muted-foreground mb-3">
@@ -271,7 +300,7 @@ function ThemePreview({ className }: { className?: string }) {
</div>
<div className="mt-4 rounded-md border border-border bg-background p-2">
<p className="mb-2 text-[11px] font-medium text-muted-foreground">Sidebar preview</p>
<p className="mb-2 text-[0.6875rem] font-medium text-muted-foreground">Sidebar preview</p>
<div className="space-y-1">
<PreviewSidebarRow
active
@@ -289,7 +318,7 @@ function ThemePreview({ className }: { className?: string }) {
leading={<ContactAvatar name="Alice" publicKey={'ab'.repeat(32)} size={24} />}
label="Alice"
badge={
<span className="rounded-full bg-badge-unread/90 px-1.5 py-0.5 text-[10px] font-semibold text-badge-unread-foreground">
<span className="rounded-full bg-badge-unread/90 px-1.5 py-0.5 text-[0.625rem] font-semibold text-badge-unread-foreground">
3
</span>
}
@@ -298,13 +327,267 @@ function ThemePreview({ className }: { className?: string }) {
leading={<ContactAvatar name="Mesh Ops" publicKey={'cd'.repeat(32)} size={24} />}
label="Mesh Ops"
badge={
<span className="rounded-full bg-badge-mention px-1.5 py-0.5 text-[10px] font-semibold text-badge-mention-foreground">
<span className="rounded-full bg-badge-mention px-1.5 py-0.5 text-[0.625rem] font-semibold text-badge-mention-foreground">
@2
</span>
}
/>
</div>
</div>
{/* ── Style Reference (collapsible) ── */}
<button
type="button"
onClick={() => setShowStyleRef((v) => !v)}
className="mt-4 flex w-full items-center gap-1.5 text-[0.6875rem] font-medium text-muted-foreground hover:text-foreground transition-colors"
>
<ChevronRight
className={cn('h-3.5 w-3.5 transition-transform', showStyleRef && 'rotate-90')}
/>
Canonical style reference
</button>
{showStyleRef && (
<>
{/* ── Text Hierarchy ── */}
<PreviewSection title="Text hierarchy">
<div className="space-y-2">
<PreviewTextRow
classes="text-xl font-semibold"
label="text-xl font-semibold"
desc="Hero / large data"
/>
<PreviewTextRow
classes="text-lg font-semibold"
label="text-lg font-semibold"
desc="Sheet / dialog title"
/>
<PreviewTextRow
classes="text-base font-semibold"
label="text-base font-semibold"
desc="Section title"
/>
<PreviewTextRow classes="text-sm" label="text-sm" desc="Body text, form labels" />
<PreviewTextRow
classes="text-xs text-muted-foreground"
label="text-xs text-muted-foreground"
desc="Helper text"
/>
<PreviewTextRow
classes="text-[0.6875rem] text-muted-foreground"
label="text-[0.6875rem] text-muted-foreground"
desc="Metadata, timestamps"
/>
<div>
<p className="text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium">
Section Label
</p>
<p className="text-[0.625rem] text-muted-foreground/60 mt-0.5">
text-[0.625rem] uppercase tracking-wider text-muted-foreground font-medium
</p>
</div>
</div>
</PreviewSection>
{/* ── Mono Text ── */}
<PreviewSection title="Mono text">
<div className="space-y-1.5">
<div>
<p className="text-xs font-mono text-muted-foreground">
a1b2c3d4e5f6...7890abcdef01
</p>
<p className="text-[0.625rem] text-muted-foreground/60">
text-xs font-mono keys, identifiers
</p>
</div>
<div>
<p className="text-[0.6875rem] font-mono">1h 23m 45s uptime</p>
<p className="text-[0.625rem] text-muted-foreground/60">
text-[0.6875rem] font-mono metadata mono
</p>
</div>
<div>
<p className="text-sm font-mono">$ req_status_sync 0xA1B2...</p>
<p className="text-[0.625rem] text-muted-foreground/60">
text-sm font-mono console / code
</p>
</div>
</div>
</PreviewSection>
{/* ── Badges ── */}
<PreviewSection title="Badges and tags">
<div className="flex flex-wrap items-center gap-2">
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
Hashtag
</span>
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium">
Repeater
</span>
<span className="text-[0.625rem] uppercase tracking-wider px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium">
On Radio
</span>
<span className="rounded-full bg-badge-unread/90 px-1.5 py-0.5 text-[0.625rem] font-semibold text-badge-unread-foreground">
3
</span>
<span className="rounded-full bg-badge-mention px-1.5 py-0.5 text-[0.625rem] font-semibold text-badge-mention-foreground">
@2
</span>
</div>
<p className="text-[0.625rem] text-muted-foreground/60 mt-1.5">
Muted: bg-muted &middot; Primary: bg-primary/10 &middot; Unread/Mention: bg-badge-*
</p>
</PreviewSection>
{/* ── Buttons ── */}
<PreviewSection title="Buttons">
<div className="space-y-3">
<div>
<p className="text-[0.625rem] text-muted-foreground/60 mb-1.5">
Standard variants (size sm)
</p>
<div className="flex flex-wrap gap-1.5">
<Button size="sm">Default</Button>
<Button size="sm" variant="outline">
Outline
</Button>
<Button size="sm" variant="secondary">
Secondary
</Button>
<Button size="sm" variant="destructive">
Destructive
</Button>
<Button size="sm" variant="ghost">
Ghost
</Button>
<Button size="icon" variant="outline">
<Settings className="h-4 w-4" />
</Button>
<Button size="icon" variant="outline">
<Send className="h-4 w-4" />
</Button>
</div>
</div>
<div>
<p className="text-[0.625rem] text-muted-foreground/60 mb-1.5">
Semantic outline variants
</p>
<div className="flex flex-wrap gap-1.5">
<Button
size="sm"
variant="outline"
className="border-destructive/50 text-destructive hover:bg-destructive/10"
>
Danger
</Button>
<Button
size="sm"
variant="outline"
className="border-warning/50 text-warning hover:bg-warning/10"
>
Warning
</Button>
<Button
size="sm"
variant="outline"
className="border-green-600/50 text-green-600 hover:bg-green-600/10"
>
Success
</Button>
</div>
</div>
<div>
<p className="text-[0.625rem] text-muted-foreground/60 mb-1.5">
Metric selector pills
</p>
<div className="flex gap-1">
{['Voltage', 'Noise Floor', 'Packets'].map((label, i) => (
<button
key={label}
type="button"
className={cn(
'text-[0.6875rem] px-2 py-0.5 rounded transition-colors',
i === 0
? 'bg-primary text-primary-foreground'
: 'text-muted-foreground hover:text-foreground hover:bg-accent'
)}
>
{label}
</button>
))}
</div>
</div>
</div>
</PreviewSection>
{/* ── Clickable Text ── */}
<PreviewSection title="Clickable text">
<div className="space-y-1.5">
<span
role="button"
tabIndex={0}
className="text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary transition-colors block"
>
a1b2c3d4e5f6 (click to copy)
</span>
<span
role="button"
tabIndex={0}
className="text-sm cursor-pointer underline underline-offset-2 decoration-muted-foreground/50 hover:text-primary transition-colors"
>
Underlined navigational link
</span>
</div>
<p className="text-[0.625rem] text-muted-foreground/60 mt-1.5">
cursor-pointer hover:text-primary transition-colors use role=&quot;button&quot; +
tabIndex
</p>
</PreviewSection>
{/* ── Inline Alerts ── */}
<PreviewSection title="Inline alerts">
<div className="space-y-1.5">
<div className="rounded-md border border-info/30 bg-info/10 px-3 py-2 text-xs text-info">
Info: channel slot cache refreshed from radio.
</div>
<div className="rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning">
Warning: radio clock skew detected.
</div>
<div className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
Error: post-connect setup timed out. Reboot the radio and restart.
</div>
</div>
</PreviewSection>
</>
)}
</div>
);
}
function PreviewSection({ title, children }: { title: string; children: React.ReactNode }) {
return (
<div className="mt-4 rounded-md border border-border bg-background p-2">
<p className="mb-2 text-[0.6875rem] font-medium text-muted-foreground">{title}</p>
{children}
</div>
);
}
function PreviewTextRow({
classes,
label,
desc,
}: {
classes: string;
label: string;
desc: string;
}) {
return (
<div>
<p className={classes}>Sample text at this size</p>
<p className="text-[0.625rem] text-muted-foreground/60">
{label} {desc}
</p>
</div>
);
}
@@ -327,7 +610,7 @@ function PreviewMessage({
return (
<div className={`flex ${alignRight ? 'justify-end' : 'justify-start'}`}>
<div className={`max-w-[85%] ${alignRight ? 'items-end' : 'items-start'} flex flex-col`}>
<span className="mb-1 text-[11px] text-muted-foreground">{sender}</span>
<span className="mb-1 text-[0.6875rem] text-muted-foreground">{sender}</span>
<div className={`rounded-2xl px-3 py-2 text-sm break-words ${bubbleClassName}`}>{text}</div>
</div>
</div>
@@ -348,7 +631,7 @@ function PreviewSidebarRow({
return (
<div
data-active={active ? 'true' : undefined}
className={`sidebar-action-row flex items-center gap-2 rounded-md border-l-2 px-3 py-2 text-[13px] ${
className={`sidebar-action-row flex items-center gap-2 rounded-md border-l-2 px-3 py-2 text-[0.8125rem] ${
active ? 'border-l-primary bg-accent text-foreground' : 'border-l-transparent'
}`}
>
@@ -570,9 +570,9 @@ export function SettingsRadioSection({
onChange={(e) => setPathHashMode(e.target.value)}
className="w-full h-10 px-3 rounded-md border border-input bg-background text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
>
<option value="0">1 byte (default)</option>
<option value="1">2 bytes</option>
<option value="2">3 bytes</option>
<option value="0">1 byte up to 63 hops (default)</option>
<option value="1">2 bytes up to 32 hops</option>
<option value="2">3 bytes up to 21 hops</option>
</select>
<div className="rounded-md border border-warning/50 bg-warning/10 p-3 text-xs text-warning">
<p className="font-semibold mb-1">Compatibility Warning</p>
@@ -702,6 +702,26 @@ export function SettingsRadioSection({
</p>
</div>
</div>
<div className="flex items-start gap-3 rounded-md border border-border/60 p-3">
<Checkbox
id="auto-resend-channel"
checked={appSettings.auto_resend_channel}
onCheckedChange={(checked) =>
onSaveAppSettings({ auto_resend_channel: checked === true })
}
className="mt-0.5"
/>
<div className="space-y-1">
<Label htmlFor="auto-resend-channel">Auto-Resend Unheard Channel Messages</Label>
<p className="text-xs text-muted-foreground">
When enabled, outgoing channel messages that receive no echo within 2 seconds are
automatically resent once (byte-perfect, within the 30-second dedup window). Repeaters
that already heard the original will ignore the duplicate. This functionality will NOT
create double-sent/duplicate messages.
</p>
</div>
</div>
</div>
<div className="space-y-2">
+1
View File
@@ -19,6 +19,7 @@ const Toaster = ({ ...props }: ToasterProps) => {
'group-[.toaster]:bg-toast-error group-[.toaster]:text-toast-error-foreground group-[.toaster]:border-toast-error-border [&_[data-description]]:text-toast-error-foreground',
},
}}
closeButton
{...props}
/>
);
@@ -95,7 +95,7 @@ export function VisualizerControls({
{PACKET_LEGEND_ITEMS.map((item) => (
<div key={item.label} className="flex items-center gap-2">
<div
className="w-5 h-5 rounded-full flex items-center justify-center text-[8px] font-bold text-white"
className="w-5 h-5 rounded-full flex items-center justify-center text-[0.5rem] font-bold text-white"
style={{ backgroundColor: item.color }}
>
{item.label}
+44 -73
View File
@@ -2,26 +2,12 @@ import { useState, useCallback, useEffect, useRef } from 'react';
import { api } from '../api';
import { takePrefetchOrFetch } from '../prefetch';
import { toast } from '../components/ui/sonner';
import {
initLastMessageTimes,
loadLocalStorageLastMessageTimes,
loadLocalStorageSortOrder,
clearLocalStorageConversationState,
} from '../utils/conversationState';
import {
isFavorite,
loadLocalStorageFavorites,
clearLocalStorageFavorites,
} from '../utils/favorites';
import type { AppSettings, AppSettingsUpdate, Favorite } from '../types';
import { initLastMessageTimes } from '../utils/conversationState';
import type { AppSettings, AppSettingsUpdate } from '../types';
export function useAppSettings() {
const [appSettings, setAppSettings] = useState<AppSettings | null>(null);
// Stable empty array prevents a new reference every render when there are none.
const emptyFavorites = useRef<Favorite[]>([]).current;
const favorites: Favorite[] = appSettings?.favorites ?? emptyFavorites;
// One-time migration guard
const hasMigratedRef = useRef(false);
@@ -94,93 +80,78 @@ export function useAppSettings() {
}
}, []);
const handleToggleFavorite = useCallback(async (type: 'channel' | 'contact', id: string) => {
const handleToggleTrackedTelemetry = useCallback(async (publicKey: string) => {
const key = publicKey.toLowerCase();
setAppSettings((prev) => {
if (!prev) return prev;
const currentFavorites = prev.favorites ?? [];
const wasFavorited = isFavorite(currentFavorites, type, id);
const optimisticFavorites = wasFavorited
? currentFavorites.filter((f) => !(f.type === type && f.id === id))
: [...currentFavorites, { type, id }];
return { ...prev, favorites: optimisticFavorites };
const current = prev.tracked_telemetry_repeaters ?? [];
const wasTracked = current.includes(key);
const optimistic = wasTracked ? current.filter((k) => k !== key) : [...current, key];
return { ...prev, tracked_telemetry_repeaters: optimistic };
});
try {
const updatedSettings = await api.toggleFavorite(type, id);
setAppSettings(updatedSettings);
const result = await api.toggleTrackedTelemetry(publicKey);
setAppSettings((prev) =>
prev ? { ...prev, tracked_telemetry_repeaters: result.tracked_telemetry_repeaters } : prev
);
} catch (err) {
console.error('Failed to toggle favorite:', err);
console.error('Failed to toggle tracked telemetry:', err);
try {
const settings = await api.getSettings();
setAppSettings(settings);
} catch {
// If refetch also fails, leave optimistic state
}
toast.error('Failed to update favorite');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const detail = (err as any)?.body?.detail;
if (typeof detail === 'object' && detail?.message) {
toast.error(detail.message);
} else {
toast.error('Failed to update tracked telemetry');
}
}
}, []);
// One-time migration of localStorage preferences to server
// Legacy favorites migration: if pre-server-side favorites exist in
// localStorage, toggle each one via the existing API and clear the key.
useEffect(() => {
if (!appSettings || hasMigratedRef.current) return;
if (appSettings.preferences_migrated) {
clearLocalStorageFavorites();
clearLocalStorageConversationState();
hasMigratedRef.current = true;
return;
}
const localFavorites = loadLocalStorageFavorites();
const localSortOrder = loadLocalStorageSortOrder();
const localLastMessageTimes = loadLocalStorageLastMessageTimes();
const hasLocalData =
localFavorites.length > 0 ||
localSortOrder !== 'recent' ||
Object.keys(localLastMessageTimes).length > 0;
if (!hasLocalData) {
hasMigratedRef.current = true;
return;
}
hasMigratedRef.current = true;
const migratePreferences = async () => {
try {
const result = await api.migratePreferences({
favorites: localFavorites,
sort_order: localSortOrder,
last_message_times: localLastMessageTimes,
});
const FAVORITES_KEY = 'remoteterm-favorites';
let localFavorites: Array<{ type: 'channel' | 'contact'; id: string }> = [];
try {
const stored = localStorage.getItem(FAVORITES_KEY);
if (stored) localFavorites = JSON.parse(stored);
} catch {
// corrupt or unavailable
}
if (localFavorites.length === 0) return;
if (result.migrated) {
toast.success('Preferences migrated', {
description: `Migrated ${localFavorites.length} favorites to server`,
});
const migrate = async () => {
let migrated = 0;
for (const f of localFavorites) {
try {
await api.toggleFavorite(f.type, f.id);
migrated++;
} catch {
// Entity may have been deleted; skip and continue
}
setAppSettings(result.settings);
initLastMessageTimes(result.settings.last_message_times ?? {});
clearLocalStorageFavorites();
clearLocalStorageConversationState();
} catch (err) {
console.error('Failed to migrate preferences:', err);
}
localStorage.removeItem(FAVORITES_KEY);
// Reload so contacts/channels pick up the new favorite flags
if (migrated > 0) window.location.reload();
};
migratePreferences();
migrate();
}, [appSettings]);
return {
appSettings,
favorites,
fetchAppSettings,
handleSaveAppSettings,
handleToggleFavorite,
handleToggleBlockedKey,
handleToggleBlockedName,
handleToggleTrackedTelemetry,
};
}
@@ -21,6 +21,10 @@ interface UseConversationActionsResult {
channelKey: string,
floodScopeOverride: string
) => Promise<void>;
handleSetChannelPathHashModeOverride: (
channelKey: string,
pathHashModeOverride: number | null
) => Promise<void>;
handleSenderClick: (sender: string) => void;
handleTrace: () => Promise<void>;
handlePathDiscovery: (publicKey: string) => Promise<PathDiscoveryResponse>;
@@ -106,6 +110,25 @@ export function useConversationActions({
[mergeChannelIntoList]
);
const handleSetChannelPathHashModeOverride = useCallback(
async (channelKey: string, pathHashModeOverride: number | null) => {
try {
const updated = await api.setChannelPathHashModeOverride(channelKey, pathHashModeOverride);
mergeChannelIntoList(updated);
toast.success(
updated.path_hash_mode_override != null
? 'Path hop width override saved'
: 'Path hop width override cleared'
);
} catch (err) {
toast.error('Failed to update path hop width override', {
description: err instanceof Error ? err.message : 'Unknown error',
});
}
},
[mergeChannelIntoList]
);
const handleSenderClick = useCallback(
(sender: string) => {
messageInputRef.current?.appendText(`@[${sender}] `);
@@ -143,6 +166,7 @@ export function useConversationActions({
handleSendMessage,
handleResendChannelMessage,
handleSetChannelFloodScopeOverride,
handleSetChannelPathHashModeOverride,
handleSenderClick,
handleTrace,
handlePathDiscovery,
+36 -20
View File
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef } from 'react';
import type { Favorite } from '../types';
import type { Channel, Contact } from '../types';
import { getStateKey } from '../utils/conversationState';
const APP_TITLE = 'RemoteTerm for MeshCore';
@@ -25,12 +25,11 @@ function getUnreadDirectMessageCount(unreadCounts: Record<string, number>): numb
function getUnreadFavoriteChannelCount(
unreadCounts: Record<string, number>,
favorites: Favorite[]
channels: Channel[]
): number {
return favorites.reduce(
(sum, favorite) =>
sum +
(favorite.type === 'channel' ? unreadCounts[getStateKey('channel', favorite.id)] || 0 : 0),
return channels.reduce(
(sum, channel) =>
sum + (channel.favorite ? unreadCounts[getStateKey('channel', channel.key)] || 0 : 0),
0
);
}
@@ -41,19 +40,29 @@ export function getTotalUnreadCount(unreadCounts: Record<string, number>): numbe
export function getFavoriteUnreadCount(
unreadCounts: Record<string, number>,
favorites: Favorite[]
contacts: Contact[],
channels: Channel[]
): number {
return favorites.reduce((sum, favorite) => {
const stateKey = getStateKey(favorite.type, favorite.id);
return sum + (unreadCounts[stateKey] || 0);
}, 0);
let sum = 0;
for (const contact of contacts) {
if (contact.favorite) {
sum += unreadCounts[getStateKey('contact', contact.public_key)] || 0;
}
}
for (const channel of channels) {
if (channel.favorite) {
sum += unreadCounts[getStateKey('channel', channel.key)] || 0;
}
}
return sum;
}
export function getUnreadTitle(
unreadCounts: Record<string, number>,
favorites: Favorite[]
contacts: Contact[],
channels: Channel[]
): string {
const unreadCount = getFavoriteUnreadCount(unreadCounts, favorites);
const unreadCount = getFavoriteUnreadCount(unreadCounts, contacts, channels);
if (unreadCount <= 0) {
return APP_TITLE;
}
@@ -65,13 +74,13 @@ export function getUnreadTitle(
export function deriveFaviconBadgeState(
unreadCounts: Record<string, number>,
mentions: Record<string, boolean>,
favorites: Favorite[]
channels: Channel[]
): FaviconBadgeState {
if (Object.values(mentions).some(Boolean) || getUnreadDirectMessageCount(unreadCounts) > 0) {
return 'red';
}
if (getUnreadFavoriteChannelCount(unreadCounts, favorites) > 0) {
if (getUnreadFavoriteChannelCount(unreadCounts, channels) > 0) {
return 'green';
}
@@ -128,8 +137,15 @@ function applyFaviconHref(href: string): void {
upsertFaviconLinks('shortcut icon', href);
}
export function useUnreadTitle(unreadCounts: Record<string, number>, favorites: Favorite[]): void {
const title = useMemo(() => getUnreadTitle(unreadCounts, favorites), [favorites, unreadCounts]);
export function useUnreadTitle(
unreadCounts: Record<string, number>,
contacts: Contact[],
channels: Channel[]
): void {
const title = useMemo(
() => getUnreadTitle(unreadCounts, contacts, channels),
[contacts, channels, unreadCounts]
);
useEffect(() => {
document.title = title;
@@ -143,12 +159,12 @@ export function useUnreadTitle(unreadCounts: Record<string, number>, favorites:
export function useFaviconBadge(
unreadCounts: Record<string, number>,
mentions: Record<string, boolean>,
favorites: Favorite[]
channels: Channel[]
): void {
const objectUrlRef = useRef<string | null>(null);
const badgeState = useMemo(
() => deriveFaviconBadgeState(unreadCounts, mentions, favorites),
[favorites, mentions, unreadCounts]
() => deriveFaviconBadgeState(unreadCounts, mentions, channels),
[channels, mentions, unreadCounts]
);
useEffect(() => {
+6 -14
View File
@@ -24,7 +24,6 @@ const mocks = vi.hoisted(() => ({
requestTrace: vi.fn(),
updateRadioConfig: vi.fn(),
setPrivateKey: vi.fn(),
migratePreferences: vi.fn(),
},
toast: {
success: vi.fn(),
@@ -188,11 +187,9 @@ const baseConfig = {
const baseSettings = {
max_radio_contacts: 200,
favorites: [] as Array<{ type: 'channel' | 'contact'; id: string }>,
auto_decrypt_dm_on_advert: false,
sidebar_sort_order: 'recent' as const,
last_message_times: {},
preferences_migrated: false,
advert_interval: 0,
last_advert_time: 0,
flood_scope: '',
@@ -206,6 +203,7 @@ const publicChannel = {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
describe('App favorite toggle flow', () => {
@@ -218,8 +216,9 @@ describe('App favorite toggle flow', () => {
mocks.api.getChannels.mockResolvedValue([publicChannel]);
mocks.api.getContacts.mockResolvedValue([]);
mocks.api.toggleFavorite.mockResolvedValue({
...baseSettings,
favorites: [{ type: 'channel', id: publicChannel.key }],
type: 'channel',
id: publicChannel.key,
favorite: true,
});
});
@@ -241,11 +240,8 @@ describe('App favorite toggle flow', () => {
});
});
it('rolls back favorite state by refetching settings on toggle failure', async () => {
it('rolls back favorite state on toggle failure', async () => {
mocks.api.toggleFavorite.mockRejectedValue(new Error('toggle failed'));
mocks.api.getSettings
.mockResolvedValueOnce({ ...baseSettings }) // initial load
.mockResolvedValueOnce({ ...baseSettings }); // rollback refetch
render(<App />);
@@ -259,10 +255,6 @@ describe('App favorite toggle flow', () => {
expect(mocks.api.toggleFavorite).toHaveBeenCalledWith('channel', publicChannel.key);
});
await waitFor(() => {
expect(mocks.api.getSettings).toHaveBeenCalledTimes(2);
});
await waitFor(() => {
expect(mocks.toast.error).toHaveBeenCalledWith('Failed to update favorite');
});
+2 -4
View File
@@ -11,7 +11,6 @@ const mocks = vi.hoisted(() => ({
getUndecryptedPacketCount: vi.fn(),
getChannels: vi.fn(),
getContacts: vi.fn(),
migratePreferences: vi.fn(),
},
useConversationMessagesCalls: vi.fn(),
}));
@@ -216,11 +215,9 @@ describe('App search jump target handling', () => {
});
mocks.api.getSettings.mockResolvedValue({
max_radio_contacts: 200,
favorites: [],
auto_decrypt_dm_on_advert: false,
sidebar_sort_order: 'recent',
last_message_times: {},
preferences_migrated: true,
advert_interval: 0,
last_advert_time: 0,
});
@@ -232,6 +229,7 @@ describe('App search jump target handling', () => {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
},
]);
mocks.api.getContacts.mockResolvedValue([]);
+6 -4
View File
@@ -9,7 +9,6 @@ const mocks = vi.hoisted(() => ({
getUndecryptedPacketCount: vi.fn(),
getChannels: vi.fn(),
getContacts: vi.fn(),
migratePreferences: vi.fn(),
},
}));
@@ -146,6 +145,7 @@ const publicChannel = {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
describe('App startup hash resolution', () => {
@@ -167,11 +167,9 @@ describe('App startup hash resolution', () => {
});
mocks.api.getSettings.mockResolvedValue({
max_radio_contacts: 200,
favorites: [],
auto_decrypt_dm_on_advert: false,
sidebar_sort_order: 'recent',
last_message_times: {},
preferences_migrated: true,
advert_interval: 0,
last_advert_time: 0,
});
@@ -249,6 +247,7 @@ describe('App startup hash resolution', () => {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
window.location.hash = '';
@@ -280,6 +279,7 @@ describe('App startup hash resolution', () => {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
window.location.hash = '';
@@ -310,6 +310,7 @@ describe('App startup hash resolution', () => {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
window.location.hash = '';
@@ -347,6 +348,7 @@ describe('App startup hash resolution', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -17,6 +17,7 @@ describe('BulkAddChannelResultModal', () => {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
},
{
key: 'BB'.repeat(16),
@@ -24,6 +25,7 @@ describe('BulkAddChannelResultModal', () => {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
},
],
existing_count: 3,
@@ -2,7 +2,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { ChannelInfoPane } from '../components/ChannelInfoPane';
import type { Channel, ChannelDetail, Favorite } from '../types';
import type { Channel, ChannelDetail } from '../types';
// Mock the api module
vi.mock('../api', () => ({
@@ -15,7 +15,7 @@ import { api } from '../api';
const mockGetChannelDetail = vi.mocked(api.getChannelDetail);
function makeChannel(key: string, name: string, isHashtag: boolean): Channel {
return { key, name, is_hashtag: isHashtag, on_radio: false, last_read_at: null };
return { key, name, is_hashtag: isHashtag, on_radio: false, last_read_at: null, favorite: false };
}
function makeDetail(channel: Channel): ChannelDetail {
@@ -25,6 +25,15 @@ function makeDetail(channel: Channel): ChannelDetail {
first_message_at: null,
unique_sender_count: 0,
top_senders_24h: [],
path_hash_width_24h: {
total_packets: 0,
single_byte: 0,
double_byte: 0,
triple_byte: 0,
single_byte_pct: 0,
double_byte_pct: 0,
triple_byte_pct: 0,
},
};
}
@@ -32,7 +41,6 @@ const noop = () => {};
const baseProps = {
onClose: noop,
favorites: [] as Favorite[],
onToggleFavorite: noop,
};
@@ -2,12 +2,12 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/rea
import { describe, expect, it, vi } from 'vitest';
import { ChatHeader } from '../components/ChatHeader';
import type { Channel, Contact, Conversation, Favorite, PathDiscoveryResponse } from '../types';
import type { Channel, Contact, Conversation, PathDiscoveryResponse } from '../types';
import { CONTACT_TYPE_ROOM } from '../types';
import { PUBLIC_CHANNEL_KEY } from '../utils/publicChannel';
function makeChannel(key: string, name: string, isHashtag: boolean): Channel {
return { key, name, is_hashtag: isHashtag, on_radio: false, last_read_at: null };
return { key, name, is_hashtag: isHashtag, on_radio: false, last_read_at: null, favorite: false };
}
const noop = () => {};
@@ -15,7 +15,6 @@ const noop = () => {};
const baseProps = {
contacts: [],
config: null,
favorites: [] as Favorite[],
notificationsSupported: true,
notificationsEnabled: false,
notificationsPermission: 'granted' as const,
@@ -186,6 +185,7 @@ describe('ChatHeader key visibility', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -237,6 +237,7 @@ describe('ChatHeader key visibility', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -286,6 +287,7 @@ describe('ChatHeader key visibility', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+1 -1
View File
@@ -47,6 +47,7 @@ function createContact(overrides: Partial<Contact> = {}): Contact {
lon: null,
last_seen: 1700000000,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: 1699990000,
@@ -90,7 +91,6 @@ const baseProps = {
onClose: () => {},
contacts: [] as Contact[],
config: null,
favorites: [],
onToggleFavorite: () => {},
onSearchMessagesByKey: vi.fn(),
onSearchMessagesByName: vi.fn(),
+8 -10
View File
@@ -3,15 +3,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ConversationPane } from '../components/ConversationPane';
import type {
Channel,
Contact,
Conversation,
Favorite,
HealthStatus,
Message,
RadioConfig,
} from '../types';
import type { Channel, Contact, Conversation, HealthStatus, Message, RadioConfig } from '../types';
import type { RawPacketStatsSessionState } from '../utils/rawPacketStats';
const mocks = vi.hoisted(() => ({
@@ -97,6 +89,7 @@ const channel: Channel = {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
const message: Message = {
@@ -134,7 +127,6 @@ function createProps(overrides: Partial<React.ComponentProps<typeof Conversation
notificationsSupported: true,
notificationsEnabled: false,
notificationsPermission: 'granted' as const,
favorites: [] as Favorite[],
messages: [message],
messagesLoading: false,
loadingOlder: false,
@@ -164,6 +156,8 @@ function createProps(overrides: Partial<React.ComponentProps<typeof Conversation
onDismissUnreadMarker: vi.fn(),
onSendMessage: vi.fn(async () => {}),
onToggleNotifications: vi.fn(),
trackedTelemetryRepeaters: [],
onToggleTrackedTelemetry: vi.fn(async () => {}),
...overrides,
};
}
@@ -203,6 +197,7 @@ describe('ConversationPane', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -276,6 +271,7 @@ describe('ConversationPane', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -370,6 +366,7 @@ describe('ConversationPane', () => {
lon: null,
last_seen: 1700000000,
on_radio: false,
favorite: false,
last_contacted: 1700000000,
last_read_at: null,
first_seen: 1700000000,
@@ -406,6 +403,7 @@ describe('ConversationPane', () => {
lon: null,
last_seen: 1700000000,
on_radio: false,
favorite: false,
last_contacted: 1700000000,
last_read_at: null,
first_seen: 1700000000,
+1 -1
View File
@@ -1227,7 +1227,7 @@ describe('SettingsFanoutSection', () => {
const group = await screen.findByRole('group', { name: 'Integration Apprise Feed' });
expect(
within(group).getByText(/discord:\/\/abc, mailto:\/\/one@example.com/)
within(group).getByText(/discord:\/\/\*{8}, mailto:\/\/\*{8}, mailto:\/\/\*{8}/)
).toBeInTheDocument();
});
+1
View File
@@ -278,6 +278,7 @@ function makeContact(overrides: Partial<Contact> = {}): Contact {
lon: null,
last_seen: null,
on_radio: true,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+2
View File
@@ -40,6 +40,7 @@ describe('MapView', () => {
lon: -74,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -74,6 +75,7 @@ describe('MapView', () => {
lon: -73,
last_seen: Math.floor(Date.now() / 1000) - 7 * 24 * 60 * 60 + 60,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+1
View File
@@ -95,6 +95,7 @@ describe('MessageList channel sender rendering', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+8 -8
View File
@@ -9,7 +9,7 @@ import { describe, it, expect } from 'vitest';
import {
findLinkedChannelReferences,
formatTime,
isValidLinkedChannelName,
HASHTAG_CHANNEL_NAME_PATTERN,
parseSenderFromText,
} from '../utils/messageParser';
@@ -103,16 +103,16 @@ describe('formatTime', () => {
describe('linked channel references', () => {
it('accepts lowercase alphanumeric names with single dashes', () => {
expect(isValidLinkedChannelName('ops')).toBe(true);
expect(isValidLinkedChannelName('ops-1')).toBe(true);
expect(isValidLinkedChannelName('1-2-3')).toBe(true);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops')).toBe(true);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops-1')).toBe(true);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('1-2-3')).toBe(true);
});
it('rejects uppercase, leading or trailing dashes, and repeated dashes', () => {
expect(isValidLinkedChannelName('Ops')).toBe(false);
expect(isValidLinkedChannelName('-ops')).toBe(false);
expect(isValidLinkedChannelName('ops-')).toBe(false);
expect(isValidLinkedChannelName('ops--room')).toBe(false);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('Ops')).toBe(false);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('-ops')).toBe(false);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops-')).toBe(false);
expect(HASHTAG_CHANNEL_NAME_PATTERN.test('ops--room')).toBe(false);
});
it('finds standalone linked channel references in message text', () => {
@@ -62,6 +62,7 @@ function createContact(publicKey: string, name: string, type = 1): Contact {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+1
View File
@@ -30,6 +30,7 @@ function createContact(overrides: Partial<Contact> = {}): Contact {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
-37
View File
@@ -1,37 +0,0 @@
import { describe, it, expect } from 'vitest';
import { RADIO_PRESETS } from '../utils/radioPresets';
describe('Radio Presets', () => {
describe('preset values are valid LoRa parameters', () => {
it('all frequencies are in valid ISM bands', () => {
for (const preset of RADIO_PRESETS) {
// 433 MHz: 433.05-434.79, EU 868: 863-870, US/AU/NZ/VN 900: 902-928
const valid433 = preset.freq >= 433 && preset.freq <= 435;
const validEU = preset.freq >= 863 && preset.freq <= 870;
const valid900 = preset.freq >= 902 && preset.freq <= 928;
expect(valid433 || validEU || valid900).toBe(true);
}
});
it('all spreading factors are valid (7-12)', () => {
for (const preset of RADIO_PRESETS) {
expect(preset.sf).toBeGreaterThanOrEqual(7);
expect(preset.sf).toBeLessThanOrEqual(12);
}
});
it('all coding rates are valid (5-8 for 4/5 to 4/8)', () => {
for (const preset of RADIO_PRESETS) {
expect(preset.cr).toBeGreaterThanOrEqual(5);
expect(preset.cr).toBeLessThanOrEqual(8);
}
});
it('all bandwidths are standard LoRa values', () => {
const validBandwidths = [7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250, 500];
for (const preset of RADIO_PRESETS) {
expect(validBandwidths).toContain(preset.bw);
}
});
});
});
@@ -23,6 +23,7 @@ const BOT_CHANNEL: Channel = {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
};
const BOT_PACKET: RawPacket = {
@@ -14,6 +14,7 @@ const TEST_CHANNEL: Channel = {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
};
const COLLIDING_TEST_CHANNEL: Channel = {
@@ -87,6 +88,7 @@ function createContact(overrides: Partial<Contact> = {}): Contact {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+7 -5
View File
@@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { RepeaterDashboard } from '../components/RepeaterDashboard';
import type { UseRepeaterDashboardResult } from '../hooks/useRepeaterDashboard';
import type { Contact, Conversation, Favorite } from '../types';
import type { Contact, Conversation } from '../types';
// Mock the hook — typed as mutable version of the return type
const mockHook: {
@@ -99,18 +99,16 @@ const contacts: Contact[] = [
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
},
];
const favorites: Favorite[] = [];
const defaultProps = {
conversation,
contacts,
favorites,
notificationsSupported: true,
notificationsEnabled: false,
notificationsPermission: 'granted' as const,
@@ -124,6 +122,8 @@ const defaultProps = {
onToggleNotifications: vi.fn(),
onToggleFavorite: vi.fn(),
onDeleteContact: vi.fn(),
trackedTelemetryRepeaters: [] as string[],
onToggleTrackedTelemetry: vi.fn(async () => {}),
};
function createDeferred<T>() {
@@ -335,6 +335,7 @@ describe('RepeaterDashboard', () => {
lon: 115.87,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -395,6 +396,7 @@ describe('RepeaterDashboard', () => {
lon: 115.87,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -677,7 +679,7 @@ describe('RepeaterDashboard', () => {
render(<RepeaterDashboard {...defaultProps} />);
expect(screen.getByText('Telemetry History')).toBeInTheDocument();
expect(screen.getByText('0 samples')).toBeInTheDocument();
expect(screen.getByText(/No history yet/)).toBeInTheDocument();
});
it('updates history from live status fetch', async () => {
@@ -40,6 +40,7 @@ const roomContact: Contact = {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+9 -1
View File
@@ -35,7 +35,14 @@ function createSearchResult(overrides: Partial<Message> = {}): Message {
const defaultProps = {
contacts: [],
channels: [
{ key: 'ABC123', name: 'Public', is_hashtag: true, on_radio: false, last_read_at: null },
{
key: 'ABC123',
name: 'Public',
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
},
],
onNavigateToMessage: vi.fn(),
};
@@ -239,6 +246,7 @@ describe('SearchView', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
first_seen: null,
last_read_at: null,
+3 -3
View File
@@ -59,17 +59,17 @@ const baseHealth: HealthStatus = {
const baseSettings: AppSettings = {
max_radio_contacts: 200,
favorites: [],
auto_decrypt_dm_on_advert: false,
sidebar_sort_order: 'recent',
last_message_times: {},
preferences_migrated: false,
advert_interval: 0,
last_advert_time: 0,
flood_scope: '',
blocked_keys: [],
blocked_names: [],
discovery_blocked_types: [],
tracked_telemetry_repeaters: [],
auto_resend_channel: false,
};
function renderModal(overrides?: {
+27 -43
View File
@@ -2,13 +2,7 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/rea
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { Sidebar } from '../components/Sidebar';
import {
CONTACT_TYPE_REPEATER,
CONTACT_TYPE_ROOM,
type Channel,
type Contact,
type Favorite,
} from '../types';
import { CONTACT_TYPE_REPEATER, CONTACT_TYPE_ROOM, type Channel, type Contact } from '../types';
import { getStateKey, type ConversationTimes } from '../utils/conversationState';
import { PUBLIC_CHANNEL_KEY } from '../utils/publicChannel';
@@ -19,6 +13,7 @@ function makeChannel(key: string, name: string): Channel {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
}
@@ -41,6 +36,7 @@ function makeContact(
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -51,7 +47,6 @@ function makeContact(
function renderSidebar(overrides?: {
unreadCounts?: Record<string, number>;
mentions?: Record<string, boolean>;
favorites?: Favorite[];
lastMessageTimes?: ConversationTimes;
channels?: Channel[];
isConversationNotificationsEnabled?: (type: 'channel' | 'contact', id: string) => boolean;
@@ -59,7 +54,7 @@ function renderSidebar(overrides?: {
const aliceName = 'Alice';
const roomName = 'Ops Board';
const publicChannel = makeChannel('AA'.repeat(16), 'Public');
const flightChannel = makeChannel('BB'.repeat(16), '#flight');
const flightChannel = { ...makeChannel('BB'.repeat(16), '#flight'), favorite: true };
const opsChannel = makeChannel('CC'.repeat(16), '#ops');
const alice = makeContact('11'.repeat(32), aliceName);
const board = makeContact('33'.repeat(32), roomName, CONTACT_TYPE_ROOM);
@@ -73,7 +68,6 @@ function renderSidebar(overrides?: {
[getStateKey('contact', relay.public_key)]: 4,
};
const favorites = overrides?.favorites ?? [{ type: 'channel', id: flightChannel.key }];
const channels = overrides?.channels ?? [publicChannel, flightChannel, opsChannel];
const onSelectConversation = vi.fn();
@@ -91,8 +85,6 @@ function renderSidebar(overrides?: {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={favorites}
legacySortOrder="recent"
isConversationNotificationsEnabled={overrides?.isConversationNotificationsEnabled}
/>
);
@@ -139,8 +131,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="recent"
/>
);
@@ -197,11 +187,26 @@ describe('Sidebar section summaries', () => {
});
it('turns favorite contact row badges red', () => {
const { aliceName } = renderSidebar({
favorites: [{ type: 'contact', id: '11'.repeat(32) }],
});
const alice = makeContact('11'.repeat(32), 'Alice', 1, { favorite: true });
const aliceRow = screen.getByText(aliceName).closest('div');
render(
<Sidebar
contacts={[alice]}
channels={[makeChannel(PUBLIC_CHANNEL_KEY, 'Public')]}
activeConversation={null}
onSelectConversation={vi.fn()}
onNewMessage={vi.fn()}
lastMessageTimes={{}}
unreadCounts={{ [getStateKey('contact', alice.public_key)]: 3 }}
mentions={{}}
showCracker={false}
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
/>
);
const aliceRow = screen.getByText('Alice').closest('div');
if (!aliceRow) throw new Error('Missing Alice row');
expect(within(aliceRow).getByText('3')).toHaveClass(
'bg-badge-mention',
@@ -299,8 +304,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="recent"
/>
);
@@ -396,8 +399,6 @@ describe('Sidebar section summaries', () => {
crackerRunning: false,
onToggleCracker: vi.fn(),
onMarkAllRead: vi.fn(),
favorites: [],
legacySortOrder: 'recent' as const,
};
const getChannelsOrder = () => screen.getAllByText(/^#/).map((node) => node.textContent);
@@ -468,8 +469,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="recent"
/>
);
@@ -503,8 +502,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="recent"
/>
);
@@ -552,8 +549,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="recent"
/>
);
@@ -585,8 +580,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[]}
legacySortOrder="alpha"
/>
);
@@ -601,8 +594,8 @@ describe('Sidebar section summaries', () => {
it('sorts favorites independently and persists the favorites sort preference', () => {
const publicChannel = makeChannel(PUBLIC_CHANNEL_KEY, 'Public');
const zed = makeContact('11'.repeat(32), 'Zed', 1, { last_advert: 150 });
const amy = makeContact('22'.repeat(32), 'Amy');
const zed = makeContact('11'.repeat(32), 'Zed', 1, { last_advert: 150, favorite: true });
const amy = makeContact('22'.repeat(32), 'Amy', 1, { favorite: true });
const props = {
contacts: [zed, amy],
@@ -619,11 +612,6 @@ describe('Sidebar section summaries', () => {
crackerRunning: false,
onToggleCracker: vi.fn(),
onMarkAllRead: vi.fn(),
favorites: [
{ type: 'contact', id: zed.public_key },
{ type: 'contact', id: amy.public_key },
] satisfies Favorite[],
legacySortOrder: 'recent' as const,
};
const getFavoritesOrder = () =>
@@ -650,8 +638,8 @@ describe('Sidebar section summaries', () => {
localStorage.setItem('remoteterm-sortOrder', 'alpha');
const publicChannel = makeChannel(PUBLIC_CHANNEL_KEY, 'Public');
const zed = makeContact('11'.repeat(32), 'Zed', 1, { last_advert: 150 });
const amy = makeContact('22'.repeat(32), 'Amy');
const zed = makeContact('11'.repeat(32), 'Zed', 1, { last_advert: 150, favorite: true });
const amy = makeContact('22'.repeat(32), 'Amy', 1, { favorite: true });
render(
<Sidebar
@@ -669,10 +657,6 @@ describe('Sidebar section summaries', () => {
crackerRunning={false}
onToggleCracker={vi.fn()}
onMarkAllRead={vi.fn()}
favorites={[
{ type: 'contact', id: zed.public_key },
{ type: 'contact', id: amy.public_key },
]}
/>
);
+1
View File
@@ -24,6 +24,7 @@ function makeContact(
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
+6
View File
@@ -193,6 +193,7 @@ describe('resolveChannelFromHashToken', () => {
is_hashtag: false,
on_radio: true,
last_read_at: null,
favorite: false,
},
{
key: '11111111111111111111111111111111',
@@ -200,6 +201,7 @@ describe('resolveChannelFromHashToken', () => {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
},
{
key: '22222222222222222222222222222222',
@@ -207,6 +209,7 @@ describe('resolveChannelFromHashToken', () => {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
},
];
@@ -241,6 +244,7 @@ describe('resolveContactFromHashToken', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -258,6 +262,7 @@ describe('resolveContactFromHashToken', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -275,6 +280,7 @@ describe('resolveContactFromHashToken', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -51,6 +51,7 @@ function makeContact(suffix: string): Contact {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -184,6 +185,7 @@ describe('useContactsAndChannels', () => {
is_hashtag: true,
on_radio: false,
last_read_at: null,
favorite: false,
},
],
existing_count: 1,
@@ -33,6 +33,7 @@ const publicChannel: Channel = {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
const sentMessage: Message = {
@@ -208,6 +209,7 @@ describe('useConversationActions', () => {
lon: null,
last_seen: null,
on_radio: false,
favorite: false,
last_contacted: null,
last_read_at: null,
first_seen: null,
@@ -10,6 +10,7 @@ const publicChannel: Channel = {
is_hashtag: false,
on_radio: false,
last_read_at: null,
favorite: false,
};
function createArgs(overrides: Partial<Parameters<typeof useConversationNavigation>[0]> = {}) {

Some files were not shown because too many files have changed in this diff Show More