Auto-favorite nodes on direct message, except CLIENT_BASE role

Open
#1,240 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #1491 by @FawwazLawal — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript
Domain
api

Research direction

Start in packages/sdk/src/features/chat/ChatClient.ts, in the onMessagePacket subscriber where direct messages are classified, and read how NodesClient.favorite() in packages/sdk/src/features/nodes/NodesClient.ts is used. The local role comes from client.config.radio.value.device?.role via ConfigClient. Done means a direct-message peer is favorited on send and receive unless the local role is CLIENT_BASE, with no duplicate admin message, and the three cases are covered by tests modeled on ChatClient.send.test.ts. The design question in meshtastic/design#39 should be confirmed first.

Written by the indexing model from the issue text.

Description

help wanted parity
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 — sends setFavoriteNode / removeFavoriteNode admin messages via AdminMessageSender.
    • packages/sdk/src/features/nodes/domain/Node.ts — Node.isFavorite: boolean.
  • There is no reference to CLIENT_BASE anywhere in the TypeScript source (only in the generated proto definition, packages/protobufs/meshtastic/config.proto, where CLIENT_BASE = 12 is a Config.DeviceConfig.Role enum 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 the client.events.onMessagePacket.subscribe(...) handler. It already computes whether a packet is a direct message and derives the peer node number:
    const 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 };
    
    This looks like the natural hook point for triggering auto-favorite logic on both inbound and outbound (echoed) direct messages, for the derived peer node 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 the device variant of the Config.Config protobuf oneof (Config_DeviceConfig.role, generated from packages/protobufs/meshtastic/config.proto).
  • NodesClient already exposes favorite(nodeNum) and each node's current isFavorite state, so the missing piece is purely the "when" — wiring a call to client.nodes.favorite(peer) from the direct-message handler, guarded by the CLIENT_BASE role check.
Suggested implementation approach
  1. In ChatClient.ts's onMessagePacket subscriber (or a small use case it delegates to), when conv.kind === "direct":
    • Look up the peer node via client.nodes and skip if it's already isFavorite.
    • Read the local device role via client.config.radio.value.device?.role.
    • If the role is not Protobuf.Config.Config_DeviceConfig_Role.CLIENT_BASE, call client.nodes.favorite(peer).
    • Skip entirely if the role is CLIENT_BASE.
  2. This should fire for both inbound direct messages and locally-sent outbound direct messages (matching the "receives/sends a direct message" wording in meshtastic/design#39, and mirroring the Android use case which triggers on send).
  3. 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_BASE role never triggers auto-favorite.
References
  • Alignment issue: meshtastic/design#39
  • Prior report (auto-closed by stale bot, not fixed): #932
Dominant language
TypeScript
Stars
861
Forks
316
Avg merge
2d 10h
Merged PRs (30d)
18

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from meshtastic/web

All issues in meshtastic/web

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.