A locked author's sender chip carries the padlock, as ours carries the star

In a channel, a DM, or a room, the chip of a sender that is a locked
contact reads 🔒 Name (⚿ on the PicoCalc), in the place of the ★ on our
own chip. The transcript cache now compares the locks, so a ^K or a lock
from the node page redraws the chips on the next paint.

The padlock is one constant, marks.LOCK_ICON, shared with the Contacts list.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Haiku 5.5 committed 2026-10-19 23:40:32 -04:00
1 parent 793bc26436
commit 59273a6b29
8 files changed
+110 -20

No files matched your search

+3 -1
View File
@@ -511,7 +511,9 @@ as a grouped list does. Filling a page in is editing its `.md`; no Python follow
2026-10-14, after a turned-over light chip read wrong). The PicoCalc draws the same
pair, white on the hue's dim twin. Our **sender** chip is `★ Name`
(`widgets.self_chip`), the star in the white label; the star on the page right of the
chip was tried and put back (JP, 2026-10-13). A **mention** of us is the same chip
chip was tried and put back (JP, 2026-10-13). A **locked** sender's chip carries the
padlock in the same place, `🔒 Name` (`author_chip(locked=…)`, `marks.LOCK_ICON`, `⚿` on
the PicoCalc; JP, 2026-10-19). A **mention** of us is the same chip
with no star (`mention_chip(you=True)`); the message carrying it gets **our white
`★`** left of its time instead (`widgets.mention_mark`, the same on every platform and
in arrow mode). The map's yellow star, the chip's notch-and-point pair, its point alone
+19 -2
View File
@@ -630,6 +630,10 @@ class ChatScreen(Screen):
* its identity or ``acked`` is different from the cache (it was appended, it was
replaced in place when a pending bubble resolved, or it was removed).
A change of the locks draws all of the transcript again, because the sender chip of
a locked contact has a padlock (refer to :meth:`_group_header`). The locks change
rarely: ^K here, or the lock row of the node page of an author.
Most importantly, this works for each message. It is not a cached prefix that
stops at the first such row. Thus a message stays cheap to draw again, however far
back it is in a long transcript. With a prefix that stops, a page up through the
@@ -641,7 +645,13 @@ class ChatScreen(Screen):
total = len(messages)
cache = self._render_cache
spacing = self.section_spacing()
if cache is not None and cache["width"] == width and cache["spacing"] == spacing:
locks = self._pages.locked_keys() if self._pages is not None else frozenset()
if (
cache is not None
and cache["width"] == width
and cache["spacing"] == spacing
and cache["locks"] == locks
):
cached_ids = cache["ids"]
cached_acked = cache["acked"]
cached_selected = cache["selected"]
@@ -736,6 +746,7 @@ class ChatScreen(Screen):
self._render_cache = {
"width": width,
"spacing": spacing,
"locks": locks,
"ids": ids,
"acked": ackeds,
"selected": selecteds,
@@ -776,12 +787,18 @@ class ChatScreen(Screen):
The sender is the origin of the route of each message under it. Thus the chip
closes on the point, the mark of a route that goes on. An ``@mention`` in a body is
the other end, and it opens on the notch (refer to :meth:`_render_mentions`).
A sender that is a locked contact has the padlock before its name, in the place of
the ``★`` of our chip (JP, 2026-10-19). Thus the chip shows the state that ^K
toggles.
"""
if message.outbound:
return self_chip(self._self_name, self._self_key, role=ORIGIN)
# ``·`` is a channel line that arrived with no sender prefix: there is no key to use.
key = None if sender == "·" else self._header_key(sender, message)
return author_chip(sender, key)
pages = self._pages
locked = key is not None and pages is not None and pages.lock_state(pages.find(key)) is True
return author_chip(sender, key, locked=locked)
def _header_key(self, sender: str, message: ChatMessage) -> str | None:
"""The key that gives the colour of the sender chip of a group: the key of the name.
+3 -11
View File
@@ -38,7 +38,7 @@ from typing import Any
from rich.cells import cell_len
from rich.text import Text
from .marks import SELF_MARK
from .marks import LOCK_ICON, SELF_MARK
from .menus import fit_cells
from .theme import glyph, name_style
from .tui.select import Choice, SelectScreen, Separator
@@ -134,14 +134,6 @@ TRACE_LANES: tuple[ContactLane, ...] = (TRACED_LANE, HEARD_LANE, PKTS_LANE)
#: what the contact still transmits. It is about when the contact left.
ARCHIVED_LANES: tuple[ContactLane, ...] = (ARCHIVED_LANE,)
#: The padlock at the start of the row of a locked contact (refer to
#: :attr:`ContactRow.locked`). It is the private-channel ``🔒`` of the icon lexicon, because
#: it means the same thing (this item is closed to something). On the PicoCalc,
#: :func:`~meshterm.ui.theme.glyph` gives the hand-drawn padlock ``⚿`` of the font. An
#: unlocked contact draws nothing. The mark is an exception that the user must notice, and a
#: lane of open padlocks makes the few closed padlocks hard to see.
_LOCK_ICON = "🔒"
def _lock_lane_width(rows: list[ContactRow]) -> int:
"""The width of the lock column in cells: the platform padlock and its gap, or ``0``.
@@ -152,7 +144,7 @@ def _lock_lane_width(rows: list[ContactRow]) -> int:
"""
if not any(row.locked for row in rows):
return 0
return cell_len(glyph(_LOCK_ICON)) + 1
return cell_len(glyph(LOCK_ICON)) + 1
def _lock_cell(row: ContactRow, lock_w: int) -> str:
@@ -161,7 +153,7 @@ def _lock_cell(row: ContactRow, lock_w: int) -> str:
return ""
if not row.locked:
return " " * lock_w
mark = glyph(_LOCK_ICON)
mark = glyph(LOCK_ICON)
return mark + " " * (lock_w - cell_len(mark))
+9
View File
@@ -52,6 +52,15 @@ UNKNOWN_MARK = ("○", "node.unknown")
#: purpose. Those marks have a meaning, and this one means "not shown".
MASK_MARK = "•"
#: The padlock of a locked contact: at the start of its row in the Contacts list, and before
#: its name on its sender chip in a chat. It is the private-channel ``🔒`` of the icon
#: lexicon, because it means the same thing (this item is closed to something). It goes
#: through :func:`~meshterm.ui.theme.glyph`, which gives the hand-drawn padlock ``⚿`` of the
#: font on the PicoCalc. An unlocked contact draws nothing. The mark is an exception that
#: the user must notice, and a lane of open padlocks makes the few closed padlocks hard to
#: see.
LOCK_ICON = "🔒"
#: Sentinels that name the endpoints of a path on the route graph. ``\x00`` never occurs
#: in a node hash, so the sentinels can share the namespace of node ids and not collide
#: with an id.
+10
View File
@@ -1323,6 +1323,16 @@ class ContactPages:
return None
return self._ctx.contact_store.is_locked(self._dev_pub, key)
def locked_keys(self) -> frozenset[str]:
"""The full keys of the contacts locked on this device, or none where no lock is stored.
A conversation compares it at each paint, to draw again the sender chips that gained
or lost their padlock (refer to :class:`~meshterm.ui.chat.ChatScreen`).
"""
if not self.can_lock:
return frozenset()
return self._ctx.contact_store.locked_keys(self._dev_pub)
def set_locked(self, contact: Contact, locked: bool) -> None:
"""Lock or unlock ``contact``. The caller asked :meth:`lock_state` first."""
if self.can_lock:
+10 -2
View File
@@ -46,6 +46,7 @@ from ..core.models import (
from ..platforms import Platform, on_platform
from .marks import (
DST_NODE,
LOCK_ICON,
NODE_MARK,
REPEATER_MARK,
RGB,
@@ -683,7 +684,7 @@ def name_chip(
return hop_chip(hop, role=role)
def author_chip(name: str, key: str | None) -> Text:
def author_chip(name: str, key: str | None, *, locked: bool = False) -> Text:
"""The author of a message in a chat: the chip of the node, which closes on the point.
It is :func:`name_chip` with the role of an origin, and one difference: a node that no
@@ -691,14 +692,21 @@ def author_chip(name: str, key: str | None) -> Text:
(refer to :attr:`~meshterm.ui.pathline.PathHop.quiet`). The transcript and the
Messages list draw each sender through this function.
A locked contact has the padlock before its name, in the chip: ``🔒 Name`` (JP,
2026-10-19). It is the same place as the ``★`` of our own chip (refer to
:func:`self_chip`), and the same padlock as the row of the contact in the Contacts list
(:data:`~meshterm.ui.marks.LOCK_ICON`, ``⚿`` on the PicoCalc).
Args:
name: The name as it must read.
key: Any known prefix of the key of the node, or ``None``.
locked: Whether the author is a contact that is locked against the archive sweep.
Returns:
The chip as a one-line :class:`Text`.
"""
return hop_chip(PathHop(name, key=key or None, quiet=True), role=ORIGIN)
label = f"{glyph(LOCK_ICON)} {name}" if locked else name
return hop_chip(PathHop(label, key=key or None, quiet=True), role=ORIGIN)
def self_chip(name: str | None, key: str | None, *, role: str | None = None) -> Text:
+44
View File
@@ -3210,6 +3210,50 @@ def test_k_locks_and_unlocks_the_author_of_the_selected_message(tmp_path: Path)
assert "^K lock" in screen.footer_hint
@pytest.mark.parametrize("chips", [True, False])
def test_a_locked_author_has_the_padlock_on_its_sender_chip(
tmp_path: Path,
powerline, # noqa: ANN001
chips: bool,
) -> None:
"""A locked contact reads ``🔒 Name`` on its sender chip, as our chip reads ``★ Name``.
JP, 2026-10-19. The padlock is in the label, so arrow mode has it too. The transcript
keeps the lines of each message in a cache, but a change of the locks draws the chips
again: here the lock goes away as the node page would remove it, with no key press in
the chat.
"""
from meshterm.core.contact_store import ContactStore
from tests.conftest import recording_pages
powerline(chips)
store = ContactStore(tmp_path / "contacts.json")
dev = "cc" * 32
alice = Contact(name="Alice", public_key="a1" * 32, key_prefix="a1" * 6)
store.set_locked(dev, alice, True)
pages = recording_pages([alice], store=store, self_key=dev)
keys = {"alice": "a1" * 32, "bob": "b2" * 32}
screen = ChatScreen(
Conversation(label="#public", is_channel=True, channel_idx=0),
[
ChatMessage(text="Alice: hi", is_channel=True, channel_idx=0),
ChatMessage(text="Bob: yo", is_channel=True, channel_idx=0),
],
send=None,
names={},
session=_StubSession(),
key_of=lambda name: keys.get(name.casefold()),
pages=pages, # type: ignore[arg-type]
)
shown = _strip_ansi(screen.render_body(60))
assert "\U0001f512 Alice" in shown
assert "\U0001f512 Bob" not in shown # Bob is not a contact, so he has no lock
pages.set_locked(alice, False) # type: ignore[attr-defined]
shown = _strip_ansi(screen.render_body(60))
assert "\U0001f512" not in shown and "Alice" in shown
def test_the_lock_atom_never_pushes_another_key_out_of_the_hint(tmp_path: Path) -> None:
"""With a link and a location, the hint has no room for ^K, so the atom stays out.
+12 -4
View File
@@ -534,10 +534,17 @@ def _region_editor(cols: int, rows: int) -> Screen:
def _chat(cols: int, rows: int) -> Screen:
conv = Conversation(
label="Alice",
is_channel=False,
contact=Contact(name="Alice", public_key="d4" + "0" * 62, key_prefix="d4e5f6a7"),
"""A direct chat with a locked peer, so that its sender chip has the padlock of the font."""
from types import SimpleNamespace
from tests.conftest import recording_pages
alice = Contact(name="Alice", public_key="d4" + "0" * 62, key_prefix="d4e5f6a7")
conv = Conversation(label="Alice", is_channel=False, contact=alice)
store = SimpleNamespace(
is_locked=lambda dev, key: True,
locked_keys=lambda dev: frozenset({alice.public_key}),
archived=lambda dev: [],
)
messages = [
ChatMessage(text="on my way, should be there soon", outbound=False, peer="d4e5f6a7"),
@@ -551,6 +558,7 @@ def _chat(cols: int, rows: int) -> Screen:
send=None,
names={"d4e5f6a7": "Alice"},
session=_GallerySession(cols, rows),
pages=recording_pages([alice], store=store, self_key="cc" * 32), # type: ignore[arg-type]
)