Repository navigation
Description
Summary
Per cross-platform alignment issue meshtastic/design#39, all Meshtastic clients should automatically mark a node as a "favorite" when a direct message is sent or received with that node — except when the local device's own role is CLIENT_BASE, in which case auto-favoriting must be skipped to avoid creating unintended routing/relay behavior.
This is already implemented on iOS and Android. Based on a code search of this repo (meshtastic/web, main branch), the web client does not implement this yet: it has a favorite/unfavorite concept, but it is purely user-triggered from the UI, with no automatic trigger tied to direct-message send/receive, and there is no CLIENT_BASE role check anywhere in the codebase.
Related prior report: #932 (same behavior gap, auto-closed by the stale bot without a fix landing — re-filing with full implementation context since an agent/contributor needs a concrete starting point).
Reference implementations (other platforms)
iOS — meshtastic/Meshtastic-Apple, Meshtastic/Accessory/Accessory Manager/AccessoryManager+ToRadio.swift (around line 339):
user.userNode?.favorite = user.userNode?.deviceConfig?.role ?? 0 != DeviceRoles.clientBase.rawValue
// Do not auto-favorite when using CLIENT_BASE role to avoid creating routing issues.Android — meshtastic/Meshtastic-Android, core/repository/src/commonMain/kotlin/org/meshtastic/core/repository/usecase/SendMessageUseCase.kt (around lines 89-143):
val isClientBase = ourNode?.user?.role == Config.DeviceConfig.Role.CLIENT_BASE
...
if (!destNode.isFavorite && !isClientBase) {
// ...setFavorite(node.num, favorite = true)...
}Both platforms: on send/receive of a direct message, if the peer node is not already a favorite AND the local device's own configured role is not CLIENT_BASE, mark the peer as a favorite.
Current state in this repo
- Favoriting exists but is entirely manual, driven from the UI:
apps/web/src/core/hooks/useFavoriteNode.ts— toggle callback used by node detail/table UI.packages/sdk-react/src/hooks/useFavoriteNode.ts— thin SDK-react wrapper.packages/sdk/src/features/nodes/NodesClient.ts(favorite()/unfavorite()methods, ~lines 176-186) — sends the admin message and patches local node state (isFavorite).packages/sdk/src/features/nodes/application/FavoriteNodeUseCase.ts— sendssetFavoriteNode/removeFavoriteNodeadmin messages viaAdminMessageSender.packages/sdk/src/features/nodes/domain/Node.ts—Node.isFavorite: boolean.
- There is no reference to
CLIENT_BASEanywhere in the TypeScript source (only in the generated proto definition,packages/protobufs/meshtastic/config.proto, whereCLIENT_BASE = 12is aConfig.DeviceConfig.Roleenum value — the concept exists in the protocol but is unused by any app logic). - Direct-message detection already happens in
packages/sdk/src/features/chat/ChatClient.ts(~lines 108-131), in theclient.events.onMessagePacket.subscribe(...)handler. It already computes whether a packet is a direct message and derives the peer node number:This looks like the natural hook point for triggering auto-favorite logic on both inbound and outbound (echoed) direct messages, for the derivedconst conv: ConversationKey = packet.type === "direct" && packet.to !== Constants.broadcastNum ? { kind: "direct", peer: packet.from === client.myNodeNum ? packet.to : packet.from } : { kind: "channel", channel: packet.channel };
peernode number. - The local device's configured role is available via
ConfigClient—client.config.radio.value.device?.role(packages/sdk/src/features/config/ConfigClient.ts,packages/sdk/src/features/config/domain/RadioConfig.ts), which maps to thedevicevariant of theConfig.Configprotobuf oneof (Config_DeviceConfig.role, generated frompackages/protobufs/meshtastic/config.proto). NodesClientalready exposesfavorite(nodeNum)and each node's currentisFavoritestate, so the missing piece is purely the "when" — wiring a call toclient.nodes.favorite(peer)from the direct-message handler, guarded by the CLIENT_BASE role check.
Suggested implementation approach
- In
ChatClient.ts'sonMessagePacketsubscriber (or a small use case it delegates to), whenconv.kind === "direct":- Look up the peer node via
client.nodesand skip if it's alreadyisFavorite. - Read the local device role via
client.config.radio.value.device?.role. - If the role is not
Protobuf.Config.Config_DeviceConfig_Role.CLIENT_BASE, callclient.nodes.favorite(peer). - Skip entirely if the role is
CLIENT_BASE.
- Look up the peer node via
- This should fire for both inbound direct messages and locally-sent outbound direct messages (matching the "receives/sends a direct message" wording in [ALIGNMENT]: Clients should auto-favorite nodes on direct message except for CLIENT_BASE design#39, and mirroring the Android use case which triggers on send).
- Add unit test coverage similar to
packages/sdk/src/features/nodes/NodesClient.test.ts/ChatClient.send.test.ts, covering: (a) normal role auto-favorites an un-favorited DM peer, (b) already-favorited peer is left alone / no duplicate admin message sent, (c)CLIENT_BASErole never triggers auto-favorite.
References
- Alignment issue: [ALIGNMENT]: Clients should auto-favorite nodes on direct message except for CLIENT_BASE design#39
- Prior report (auto-closed by stale bot, not fixed): [Bug]: Clients / apps should auto-favorite nodes upon direct-message except for CLIENT_BASE nodes #932
Update (in progress: #1554)
This now follows Android's SendMessageUseCase and meshtastic/design#39 instead of always favouriting:
- Firmware 2.7.12 and later: before each direct message (and retry), the web client sends the peer to the local radio as a
SharedContact(add_contact). It skips this when it has no public key for the peer, so the radio's stored key is never cleared. - Older firmware: it favourites the peer of a legacy (non-PKI) DM, except when the local role is
CLIENT_BASEor the peer is already a favourite.
Both are best-effort, so the message is sent either way. Like Android, nothing happens when a DM is received.
Activity