Skip to content

feat(messages): share the peer's contact before a direct message - #1554

Open
danditomaso wants to merge 2 commits into
meshtastic:mainfrom
danditomaso:feat/dm-shared-contact
Open

danditomaso wants to merge 2 commits into
meshtastic:mainfrom
danditomaso:feat/dm-shared-contact

Conversation

@danditomaso

@danditomaso danditomaso commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Before each direct message (and retry), the client now sends the peer to the local radio as a SharedContact on firmware 2.7.12+, so its NodeDB keeps the peer and key. It's skipped when we have no public key, so the radio's stored key is never cleared. On older firmware it favourites the peer of a legacy DM instead, except on CLIENT_BASE. This matches Android (meshtastic/design#39), and the JS facade now routes add_contact.

Refs #1240

Summary by CodeRabbit

  • New Features
    • Direct messages can share contact information with eligible peers on supported firmware. On older firmware, eligible peers may be added to favorites instead.
    • Channel messages do not trigger direct-message contact actions.
  • Reliability
    • Direct messages wait briefly for contact actions to complete before sending. If an action fails or takes too long, the message still sends.

Before each DM (and retry), firmware 2.7.12+ gets the peer as a
SharedContact (add_contact), skipped without a public key so the radio's
stored key is never cleared. Older firmware favorites the peer of a
legacy DM unless the local role is CLIENT_BASE. Matches Android's
SendMessageUseCase (meshtastic/design#39). The JS facade now routes
add_contact to AdminApi.addContact.
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@danditomaso is attempting to deploy a commit to the Meshtastic Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Direct-message sends now invoke a callback that selects a contact action based on firmware and node data. MeshSession shares contact details or favorites the peer when the selected action requires it. Channel sends do not invoke the callback.

Changes: Direct-message contact handling

Layer / File(s) Summary
Contact action policy
apps/web/src/core/messaging/directContact.ts, apps/web/src/core/messaging/directContact.test.ts
directContactAction selects shareContact, favorite, or none based on firmware version, peer data, and node role. Tests cover these conditions.
ChatClient send hook
apps/web/src/core/kmp/chat.ts, apps/web/src/core/kmp/chat.test.ts
ChatClientOptions adds onDirectSend(peer). ChatClient invokes it before direct sends and resends, waits for it to settle or time out, and ignores rejection. Channel sends bypass the callback.
Session and Admin integration
apps/web/src/core/kmp/session.ts, apps/web/src/core/kmp/session.test.ts, packages/sdk-kmp/src/jsMain/kotlin/org/meshtastic/sdk/js/Admin.kt
MeshSession handles the selected action by sending an Admin addContact message, favoriting the peer, or taking no action. The Admin dispatcher routes add_contact messages to addContact. Tests verify contact sharing and local-node behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ChatClient
  participant MeshSession
  participant directContactAction
  participant AdminApi
  participant nodes
  ChatClient->>MeshSession: onDirectSend(peer)
  MeshSession->>directContactAction: select action using peer, local node, and firmware
  directContactAction-->>MeshSession: shareContact, favorite, or none
  alt shareContact
    MeshSession->>AdminApi: send addContact with peer contact
  else favorite
    MeshSession->>nodes: favorite(peer)
  end
Loading

Possibly related issues

  • meshtastic/web#1240: The issue requests auto-favoriting direct-message peers, and its update describes contact sharing on firmware 2.7.12+ with favoriting on older firmware.
  • meshtastic/web#932: The issue requests auto-favoriting direct-message peers, with a CLIENT_BASE exception. This change applies that behavior on older firmware.

Possibly related PRs

  • meshtastic/web#1491: This PR also auto-favorites a direct-message peer, which overlaps with this change’s legacy-firmware path.
Merge Risk: Minimal · up to a5580

Direct messages now share or favorite the peer with the radio before sending, so the radio can use the peer's key for encrypted delivery. A failed or slow share does not block the message, and no remaining merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: before a direct message, the client shares the peer's contact with the local radio. It follows the conventional type(scope) prefix and is a single, specific sentence u…
Description check Passed The description leads with why (direct messages should share the peer so the radio keeps its key), states the firmware-based behavior, the CLIENT_BASE exception, the key-clearing safeguard, and the An…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: before a direct message, the client shares the peer's contact with the local radio. It follows the conventional type(scope) prefix and is a single, specific sentence under 72 characters. The changeset adds the directContactAction logic, the onDirectSend hook in chat and session, the add_contact routing in the JS facade, and tests, all of which fit the title.

Full details: Description check

Explanation

The description leads with why (direct messages should share the peer so the radio keeps its key), states the firmware-based behavior, the CLIENT_BASE exception, the key-clearing safeguard, and the Android parity reference. It also links the related issue (Refs #1240). It does not fill the template's Changes Made section with grouped bullets, and its Testing Done, Screenshots, and Checklist sections are absent. Those gaps are non-critical for a Medium-effort, non-UI change, so the description is mostly complete.

Finishing Touches

Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit taps a message through the night
A peer’s contact joins when firmware is right
On older paths, a favorite may appear
The channel sends move on without the hook near
The hook may wait, reject, or time out
Yet messages still find their route about

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c77ac5bf-c4f4-434c-9a5d-8f76ab6ea067
Commits

Reviewing files that changed from the base of the PR and between 98016f5 and a558052.

Files selected for processing: 4

  • apps/web/src/core/kmp/chat.test.ts
  • apps/web/src/core/kmp/chat.ts
  • apps/web/src/core/kmp/session.test.ts
  • apps/web/src/core/kmp/session.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

As on Android, a direct message now waits (up to 3 s) for the contact
share or favorite, so the radio has the peer's key before the text and
can PKI-encrypt it. A failed or stuck share still sends the message. DMs
to our own node no longer share or favorite it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant