A channel sender or a mention can have a name of 32 characters
A MeshCore node keeps its name in a 32-byte field, but the sender and mention patterns stopped at 20 characters. A sender with the name YUL-H7H-SiO-C-Heltec1 (21 characters) showed with no name and no key. The patterns of the channel sender, the mention, and the compose chip now use one limit, MAX_SENDER_NAME. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4356bc9012
commit
42a9083c91
3 files changed
+23
-7
No files matched your search
@@ -34,18 +34,24 @@ from urllib.parse import parse_qs, quote, urlsplit
|
||||
# module from the sys.modules dict. Both functions bind the names one time for each call,
|
||||
# not one time for each candidate channel. Thus the reception path pays almost nothing.
|
||||
|
||||
#: The longest node name that a sender or a mention can carry, in characters. A MeshCore node
|
||||
#: keeps its name in a 32-byte field, and a name such as ``YUL-H7H-SiO-C-Heltec1`` has 21
|
||||
#: characters. A limit of 20 left that sender with no name and no key.
|
||||
MAX_SENDER_NAME = 32
|
||||
|
||||
#: Matches the ``Name: message`` convention that channel senders use to identify themselves
|
||||
#: (the protocol has no sender field). The name is 1–20 characters that are not colons, and
|
||||
#: ``": "`` must follow it. This rule is strict enough that it does not match ``http://…``
|
||||
#: or ``note:x``.
|
||||
SENDER_PREFIX = re.compile(r"^([^\s:][^:]{0,19}):[ \t]+(.*)$", re.DOTALL)
|
||||
#: (the protocol has no sender field). The name is 1 to :data:`MAX_SENDER_NAME` characters
|
||||
#: that are not colons, and ``": "`` must follow it. This rule is strict enough that it
|
||||
#: does not match ``http://…`` or ``note:x``.
|
||||
SENDER_PREFIX = re.compile(rf"^([^\s:][^:]{{0,{MAX_SENDER_NAME - 1}}}):[ \t]+(.*)$", re.DOTALL)
|
||||
|
||||
#: Matches an ``@[Name]`` mention token, which the reply flow puts into the compose line in
|
||||
#: advance. A transcript renders each token as a bare ``@Name`` in the hue of that sender,
|
||||
#: and does not show the brackets. The history face of the CLI also takes out the same
|
||||
#: names. Thus the token is defined here, with the remainder of the message-body parsing, and
|
||||
#: not in one of the two renderers. The name is 1–20 characters that are not ``]``.
|
||||
MENTION = re.compile(r"@\[([^\]]{1,20})\]")
|
||||
#: not in one of the two renderers. The name is 1 to :data:`MAX_SENDER_NAME` characters that
|
||||
#: are not ``]``.
|
||||
MENTION = re.compile(rf"@\[([^\]]{{1,{MAX_SENDER_NAME}}})\]")
|
||||
|
||||
|
||||
def split_channel_sender(text: str) -> tuple[str | None, str]:
|
||||
|
||||
@@ -18,6 +18,7 @@ from dataclasses import replace
|
||||
|
||||
from rich.text import Text
|
||||
|
||||
from ..core.channels import MAX_SENDER_NAME
|
||||
from .pathline import PathHop
|
||||
from .tui.prompt import LineEditor
|
||||
from .widgets import DESTINATION, hop_chip
|
||||
@@ -25,7 +26,7 @@ from .widgets import DESTINATION, hop_chip
|
||||
#: A complete mention in the compose line. It is :data:`~meshterm.core.channels.MENTION`
|
||||
#: with one more rule: the name has no ``[``. Thus an ``@[`` that the user types in front
|
||||
#: of a chip does not join the chip into one long token, and the chip stays as it is.
|
||||
ATOM = re.compile(r"@\[([^\[\]]{1,20})\]")
|
||||
ATOM = re.compile(rf"@\[([^\[\]]{{1,{MAX_SENDER_NAME}}})\]")
|
||||
|
||||
#: The actions that move the cursor to the left. A cursor that one of them puts inside a
|
||||
#: chip goes to the start of the chip. Each other action puts it at the end.
|
||||
|
||||
@@ -1187,6 +1187,15 @@ def test_split_channel_sender_extracts_name_prefix() -> None:
|
||||
assert split_channel_sender("14:30 standup") == (None, "14:30 standup")
|
||||
|
||||
|
||||
def test_split_channel_sender_accepts_a_long_node_name() -> None:
|
||||
"""A 21-character name (YUL-H7H-SiO-C-Heltec1) once fell outside the 20-character limit."""
|
||||
from meshterm.core.channels import MENTION, split_channel_sender
|
||||
|
||||
name = "YUL-H7H-SiO-C-Heltec1"
|
||||
assert split_channel_sender(f"{name}: Salut all!") == (name, "Salut all!")
|
||||
assert MENTION.search(f"@[{name}] bon matin!").group(1) == name
|
||||
|
||||
|
||||
def test_channel_transcript_groups_by_sender() -> None:
|
||||
"""Channel messages in a row from the same sender share one header. The body has no prefix."""
|
||||
from datetime import datetime, timezone
|
||||
|
||||
Reference in new issue
Block a user