Channels have no sound row; a muted channel is silent; mentions always play

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-21 01:06:32 -05:00
1 parent 037585dd15
commit da2e5d3044
8 files changed
+144 -78

No files matched your search

+4 -3
View File
@@ -23,9 +23,10 @@ can change how things behave. It does not only add new things.
- **MeshTerm plays sounds for the messages that you want to know about.** A DM, a mention
of your node, a channel message, a room post, and a low battery each have their own
sound, from Android's set (the Android Open Source Project, under the same licence as
MeshTerm). Each channel, DM, and room has a *Sound* row: never, mentions only, every message,
or the default for its kind (every message for a DM, mentions only for a channel or a
room).
MeshTerm). Channels follow one preference, *Channel sound* (mentions only by default), and
a muted channel is silent. Each DM and room has a *Sound* row: never, mentions only, every
message, or the default for its kind (every message for a DM, mentions only for a room).
*Mentions always* (on by default) plays each mention of your node, also on a muted channel.
Ctrl+S mutes or unmutes the sounds from any screen, and the header shows 🔊 or 🔇. The
new *Sound* group of preferences has the theme (Android, terminal bell, or no sound), a
volume slider of ten steps that plays each step, a short tick for each packet heard (off
+12 -7
View File
@@ -85,19 +85,24 @@ MeshTerm plays a sound when something arrives that you want to know about now:
| --- | --- |
| Direct message | A DM arrives |
| Mention | A message in any conversation mentions your node (`@[Your name]`) |
| Channel message | A message arrives on a channel whose sound is **every message** |
| Channel message | A message arrives on a channel that is not muted, when **Channel sound** is **every message** |
| Room post | A post arrives in a room whose sound is **every message** |
| Battery low | The battery goes below 25% (the **Battery low** preference). It plays one time, and again only after the battery is 5 points higher or charges |
| Packet tick | A very short tick for each packet heard that plays no other sound. It is off until you turn on **Packet tick**, and it plays at most four times each second |
The conversation that is open on the screen makes no sound, because you already see it.
Each channel, DM, and room has a **Sound** row: on the channel page, on the node page of
the contact, and on the room page. Select **never**, **mentions only**, **every message**, or
**Default**. Default follows the preference for that kind of conversation: every message
for a DM, and mentions only for a channel or a room. The mute of a channel (🔕) is a different
setting. It removes the channel from the unread count, but a mention in it still plays a
sound.
All channels follow one preference, **Channel sound**: **never**, **mentions only** (the
default), or **every message**. A channel that you muted (🔕) is silent, because the mute
turns off all of its notifications.
Each DM and room has a **Sound** row: on the node page of the contact, and on the room page.
Select **never**, **mentions only**, **every message**, or **Default**. Default follows the
preference for that kind of conversation: every message for a DM, and mentions only for a
room.
**Mentions always** (on by default) plays the mention sound for each mention of your node,
also on a muted channel and in a DM or a room set to **never**.
**Ctrl+S** mutes or unmutes the sounds from any screen. The header shows 🔊 while the
sounds play and 🔇 while they are muted. The **Sound** row above Quit in the main menu
+17 -2
View File
@@ -575,8 +575,8 @@ PREFERENCES: tuple[PrefSpec, ...] = (
PrefSpec(
key="channel_sound",
label="Channel sound",
help="Unless set per channel",
question="When a channel plays a sound, unless the channel has its own setting",
help="For channels not muted",
question="When a channel plays a sound. A muted channel plays none",
group="Sound",
value_type="enum",
# Mentions: a public channel can carry many messages each hour.
@@ -584,6 +584,21 @@ PREFERENCES: tuple[PrefSpec, ...] = (
choices=SOUND_WHEN_CHOICES,
platforms=_SOUND_PLATFORMS,
),
PrefSpec(
key="mention_sound_always",
label="Mentions always",
help="Even if muted or never",
question=(
"Play the mention sound for each mention of your node, also on a muted channel"
" and in a conversation set to never"
),
group="Sound",
value_type="bool",
# On: a mention is the message that the user most wants to hear (JP, 2026-11-21:
# "a global always play sound for mentions"). The ^S mute still silences it.
default=True,
platforms=_SOUND_PLATFORMS,
),
PrefSpec(
key="room_sound",
label="Room sound",
+35 -23
View File
@@ -382,10 +382,10 @@ class ChatService:
await self.channel_id_for(message.channel) if message.is_channel else None
)
listed = await self._is_listed(message, channel_id)
notify = listed and not self._is_muted(message, channel_id)
chat = self._store_inbound(run_id, message, channel_id, notify=notify)
muted = self._is_muted(message, channel_id)
chat = self._store_inbound(run_id, message, channel_id, notify=listed and not muted)
if listed:
await self._play_sound(message, chat.key)
await self._play_sound(message, chat.key, muted=muted)
except Exception as exc: # noqa: BLE001 - one bad message must not stop the worker
self._ctx.log.debug("chat: failed to record message: %s", exc)
finally:
@@ -481,21 +481,25 @@ class ChatService:
return await self._is_listed_channel(channel_id)
return await self._is_listed_contact(message.sender, post=message.is_post)
async def _play_sound(self, message: Message, key: str) -> None:
async def _play_sound(self, message: Message, key: str, *, muted: bool = False) -> None:
"""Play the sound of a received message, if its conversation wants one.
The rule (JP, 2026-11-20):
The rule (JP, 2026-11-21):
* The open conversation makes no sound, the same as its unread count: the user
already sees the message.
* Each conversation has a sound setting (refer to
:class:`~meshterm.core.sound_store.SoundStore`), or follows the default of its
kind (the ``channel_sound``, ``dm_sound``, and ``room_sound`` preferences).
* ``off`` plays nothing. Otherwise a mention of our node plays the mention sound.
``all`` plays the sound of the kind for each other message, and ``mentions``
plays nothing for it.
* With ``mention_sound_always`` on (the default), a mention of our node always plays
the mention sound, also on a muted channel and in a conversation set to ``off``.
* A muted channel (``muted``, refer to MuteStore) plays nothing else. A mute turns
off the notifications of the channel, and a sound is one.
* A channel follows the ``channel_sound`` preference. Channels have no setting of
their own. A DM and a room have their own setting (refer to
:class:`~meshterm.core.sound_store.SoundStore`), or follow ``dm_sound`` and
``room_sound``.
* ``off`` plays nothing. Otherwise a mention plays the mention sound. ``all`` plays
the sound of the kind for each other message, and ``mentions`` plays nothing for
it.
The channel mute is not part of this rule. It stops the unread count, not the sound.
A failure here must never stop the recording of messages, so it only goes to the log.
"""
if key == self._active:
@@ -504,27 +508,35 @@ class ChatService:
if sound is None:
return
try:
event = await self._sound_event(message, key)
event = await self._sound_event(message, key, muted=muted)
if event is not None:
sound.notify(event)
except Exception as exc: # noqa: BLE001 - a sound must never stop the recorder
self._ctx.log.debug("chat: sound failed: %s", exc)
async def _sound_event(self, message: Message, key: str) -> SoundEvent | None:
async def _sound_event(
self, message: Message, key: str, *, muted: bool = False
) -> SoundEvent | None:
"""The sound event of a received message, or ``None`` for no sound."""
prefs = self._ctx.preferences
mention = await self._mentions_us(message.text)
if mention and prefs.mention_sound_always:
return SoundEvent.MENTION
if message.is_channel:
kind, event = "channel_sound", SoundEvent.CHANNEL_MESSAGE
elif message.is_post:
kind, event = "room_sound", SoundEvent.ROOM_POST
if muted:
return None
when, event = prefs.channel_sound, SoundEvent.CHANNEL_MESSAGE
else:
kind, event = "dm_sound", SoundEvent.DIRECT_MESSAGE
store = getattr(self._ctx, "sound_store", None)
when = (store.get(key) if store is not None else None) or getattr(
self._ctx.preferences, kind
)
kind, event = (
("room_sound", SoundEvent.ROOM_POST)
if message.is_post
else ("dm_sound", SoundEvent.DIRECT_MESSAGE)
)
store = getattr(self._ctx, "sound_store", None)
when = (store.get(key) if store is not None else None) or getattr(prefs, kind)
if when == "off":
return None
if await self._mentions_us(message.text):
if mention:
return SoundEvent.MENTION
return event if when == "all" else None
+1 -11
View File
@@ -90,9 +90,7 @@ from ..core.regions import RegionNameError
from ..core.regions import validate as validate_region
from ..persistence.repository import ACTIVITY_DRAWN_BUCKETS
from ..platforms import get_platform
from . import conversation_sound
from .braillechart import activity_peak, activity_sparkline
from .conversation_sound import SOUND_ICON, SOUND_ROW, sound_row
from .menus import (
Lane,
column_header,
@@ -903,7 +901,7 @@ def _detail_items(ctx: AppContext, slot: ChannelSlot) -> list:
# ✎ and 🗑 are one cell, and 📱 🔑 💬 🔔 🔕 are two cells. Thus the code measures the
# column one time and pads each mark to it. If not, the edit row and the clear row start
# their labels one column to the left of the rows above them.
lane = icon_lane(("📱", "🔑", "💬", "🔔", "🔕", SOUND_ICON, "🔖", "✎", "🗑"))
lane = icon_lane(("📱", "🔑", "💬", "🔔", "🔕", "🔖", "✎", "🗑"))
chat_label = marked_label("💬", "Open in chat", "", lane=lane)
if unread:
chat_label.append(" ●", style="err")
@@ -934,11 +932,6 @@ def _detail_items(ctx: AppContext, slot: ChannelSlot) -> list:
),
(chat_label, "Read and send messages on this channel", _CHAT),
mute_row,
*(
[sound_row(ctx, slot.conversation.key, "channel", lane)]
if conversation_sound.offered(ctx)
else []
),
_scope_row(ctx, slot, lane),
(
marked_label("✎", "Rename / change key…", "", lane=lane),
@@ -1010,9 +1003,6 @@ async def _channel_detail(
# place and go back to the detail screen (its rows render again to the new
# state). Do not count it as a channel change.
_toggle_mute(ctx, slot)
elif choice == SOUND_ROW:
# MeshTerm keeps it, as it keeps the mute. It is not a channel change.
await conversation_sound.pick_sound(ctx, slot.conversation.key, "channel", slot.name)
elif choice == _SCOPE:
# MeshTerm keeps it, as it keeps the mute. Nothing is written to the radio until
# a message is sent, so it is not a channel change either.
+11 -8
View File
@@ -1,11 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
"""The *Sound…* row of a conversation, and the picker that it opens.
A channel, a DM, and a room each have a sound setting (refer to
A DM and a room each have a sound setting (refer to
:class:`~meshterm.core.sound_store.SoundStore`): ``off``, ``mentions``, ``all``, or the
default of its kind (a preference). Three pages show the row: the channel detail page,
the node page of a contact, and the page of a room. They all build it here, so that the
words and the picker are the same on each page.
default of its kind (a preference). Two pages show the row: the node page of a contact,
and the page of a room. They both build it here, so that the words and the picker are the
same on each page.
A channel has no sound setting of its own (JP, 2026-11-21). All channels follow the
``channel_sound`` preference, and the mute of a channel makes it silent.
The row is only on a platform that can play a sound. The PicoCalc has no sound, so a
setting there would change nothing that the user can hear.
@@ -35,7 +38,7 @@ SOUND_ROW = "sound"
_DEFAULT = "default"
#: The preference that holds the default of each kind of conversation.
KIND_PREFERENCE = {"channel": "channel_sound", "dm": "dm_sound", "room": "room_sound"}
KIND_PREFERENCE = {"dm": "dm_sound", "room": "room_sound"}
def offered(ctx: AppContext) -> bool:
@@ -55,7 +58,7 @@ def describe(ctx: AppContext, key: str, kind: str) -> str:
Args:
ctx: The shared application context.
key: The key of the conversation (``chan:…`` or ``dm:…``).
kind: ``channel``, ``dm``, or ``room``.
kind: ``dm`` or ``room``.
Returns:
A short sentence, for example ``Default: mentions only``.
@@ -81,7 +84,7 @@ async def pick_sound(ctx: AppContext, key: str, kind: str, subject: str) -> bool
Args:
ctx: The shared application context.
key: The key of the conversation.
kind: ``channel``, ``dm``, or ``room``.
kind: ``dm`` or ``room``.
subject: The name of the conversation, for the title.
Returns:
@@ -98,7 +101,7 @@ async def pick_sound(ctx: AppContext, key: str, kind: str, subject: str) -> bool
choice = await ctx.ui.select(
f"Sound — {subject}",
items,
prompt=f"When this {'conversation' if kind == 'dm' else kind} plays a sound:",
prompt=f"When this {'conversation' if kind == 'dm' else 'room'} plays a sound:",
default=current,
)
if choice is None or choice == current:
+56 -16
View File
@@ -2841,19 +2841,27 @@ async def test_sound_a_channel_plays_only_for_a_mention_by_default(
await device.disconnect()
async def test_sound_the_setting_of_a_conversation_wins(tmp_path: Path, repo: Repository) -> None:
"""The setting of one channel replaces the default of its kind: ``all``, then ``off``."""
from meshterm.services.sound import SoundEvent
async def test_sound_the_setting_of_a_dm_wins(tmp_path: Path, repo: Repository) -> None:
"""The setting of one DM replaces the default of its kind: ``off`` silences it."""
device, ctx, chat, events = await _sound_chat(repo, tmp_path)
try:
ctx.sound_store.set(_public_key(), "all")
ctx.sound_store.set("dm:d4e5f6a7", "off")
await _record(chat, ctx, Message(text="hello", sender="d4e5f6a7"))
assert events == []
finally:
await chat.stop()
await device.disconnect()
async def test_sound_a_channel_has_no_setting_of_its_own(tmp_path: Path, repo: Repository) -> None:
"""A channel follows ``channel_sound`` only. A record in the store changes nothing."""
from meshterm.services.sound import SoundEvent
device, ctx, chat, events = await _sound_chat(repo, tmp_path, channel_sound="all")
try:
ctx.sound_store.set(_public_key(), "off") # an old record: ignored
await _record(chat, ctx, Message(text="Ann: hey", channel=0, is_channel=True))
assert events == [SoundEvent.CHANNEL_MESSAGE]
ctx.sound_store.set(_public_key(), "off")
text = "Ann: @[MockCompanion] hi"
await _record(chat, ctx, Message(text=text, channel=0, is_channel=True))
assert events == [SoundEvent.CHANNEL_MESSAGE] # off: not even a mention
finally:
await chat.stop()
await device.disconnect()
@@ -2884,22 +2892,54 @@ async def test_sound_the_open_conversation_is_silent(tmp_path: Path, repo: Repos
await device.disconnect()
async def test_sound_a_muted_channel_still_plays_a_mention(
tmp_path: Path, repo: Repository
) -> None:
"""The mute stops the unread count, not the sound (JP, 2026-11-20)."""
async def _muted_public(ctx, tmp_path: Path) -> None:
from meshterm.core.channels import channel_identity
from meshterm.core.mute_store import MuteStore
ctx.mute_store = MuteStore(tmp_path / "mutes.json")
ctx.mute_store.set_muted(channel_identity("Public", DEFAULT_PUBLIC_SECRET), True)
async def test_sound_a_muted_channel_is_silent(tmp_path: Path, repo: Repository) -> None:
"""A mute turns off the notifications of a channel, and a sound is one (JP, 2026-11-21)."""
device, ctx, chat, events = await _sound_chat(repo, tmp_path, channel_sound="all")
try:
await _muted_public(ctx, tmp_path)
await _record(chat, ctx, Message(text="Ann: hey", channel=0, is_channel=True))
assert events == []
finally:
await chat.stop()
await device.disconnect()
async def test_sound_a_mention_always_plays_by_default(tmp_path: Path, repo: Repository) -> None:
"""``mention_sound_always`` (on) plays a mention on a muted channel and in an ``off`` DM."""
from meshterm.services.sound import SoundEvent
device, ctx, chat, events = await _sound_chat(repo, tmp_path)
try:
ctx.mute_store = MuteStore(tmp_path / "mutes.json")
ctx.mute_store.set_muted(channel_identity("Public", DEFAULT_PUBLIC_SECRET), True)
await _muted_public(ctx, tmp_path)
text = "Ann: @[MockCompanion] look"
await _record(chat, ctx, Message(text=text, channel=0, is_channel=True))
assert chat.unread(_public_key()) == 0
assert events == [SoundEvent.MENTION]
ctx.sound_store.set("dm:d4e5f6a7", "off")
await _record(chat, ctx, Message(text="@[MockCompanion] hi", sender="d4e5f6a7"))
assert events == [SoundEvent.MENTION, SoundEvent.MENTION]
finally:
await chat.stop()
await device.disconnect()
async def test_sound_without_the_override_a_muted_mention_is_silent(
tmp_path: Path, repo: Repository
) -> None:
"""With ``mention_sound_always`` off, a mention on a muted channel plays nothing."""
device, ctx, chat, events = await _sound_chat(repo, tmp_path, mention_sound_always=False)
try:
await _muted_public(ctx, tmp_path)
text = "Ann: @[MockCompanion] look"
await _record(chat, ctx, Message(text=text, channel=0, is_channel=True))
assert events == []
finally:
await chat.stop()
await device.disconnect()
+8 -8
View File
@@ -39,24 +39,24 @@ def _ctx(tmp_path: Path, answer: object = None, **prefs: object) -> SimpleNamesp
def test_the_description_names_the_default_or_the_own_setting(tmp_path: Path) -> None:
"""With no setting, the row names the default of the kind. With one, it names it."""
ctx = _ctx(tmp_path)
assert conversation_sound.describe(ctx, "chan:a", "channel") == "Default: mentions only"
assert conversation_sound.describe(ctx, "dm:a", "room") == "Default: mentions only"
assert conversation_sound.describe(ctx, "dm:b", "dm") == "Default: every message"
ctx.sound_store.set("chan:a", "off")
assert conversation_sound.describe(ctx, "chan:a", "channel") == "No sound"
ctx.sound_store.set("dm:a", "off")
assert conversation_sound.describe(ctx, "dm:a", "room") == "No sound"
def test_the_picker_stores_a_setting_and_default_removes_it(tmp_path: Path) -> None:
"""A pick stores the setting. ``Default`` removes it again."""
ctx = _ctx(tmp_path, answer="all")
assert asyncio.run(conversation_sound.pick_sound(ctx, "chan:a", "channel", "Public"))
assert ctx.sound_store.get("chan:a") == "all"
assert asyncio.run(conversation_sound.pick_sound(ctx, "dm:a", "room", "Board"))
assert ctx.sound_store.get("dm:a") == "all"
title, items, default = ctx.ui.asked[0]
assert title == "Sound — Public"
assert title == "Sound — Board"
assert default == "default"
assert [i.value for i in items] == ["default", "off", "mentions", "all"]
ctx.ui.answer = "default"
assert asyncio.run(conversation_sound.pick_sound(ctx, "chan:a", "channel", "Public"))
assert ctx.sound_store.get("chan:a") is None
assert asyncio.run(conversation_sound.pick_sound(ctx, "dm:a", "room", "Board"))
assert ctx.sound_store.get("dm:a") is None
def test_esc_or_the_same_value_changes_nothing(tmp_path: Path) -> None: