Skip to content

Link Matrix users to system contacts - #137

Merged
viktorstrate merged 1 commit into
viktorstrate:mainfrom
ttimpe:contacts-linking
Nov 18, 2026
Merged

viktorstrate merged 1 commit into
viktorstrate:mainfrom
ttimpe:contacts-linking

Conversation

@ttimpe

@ttimpe ttimpe commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Lets you link a Matrix user to an existing macOS contact. Once linked, Mactrix shows the contact's name (or nickname) and photo instead of the user's chosen Matrix display name and avatar.

How it works

  • Linking: the user profile inspector has a new Contact section. "Link to Contact…" opens a searchable contact picker. Linked users also get "Change Linked Contact…", "Open in Contacts" and "Unlink Contact".
  • Storage: the link is saved on the contact as a social profile with the service Matrix, the Matrix ID as username and a matrix.to URL. It shows in Contacts.app, syncs with the contact, and can also be added there by hand. A Matrix ID is linked to at most one contact.
  • Settings: a new Contacts tab with a master switch (off by default; turning it on requests Contacts access), plus toggles for contact names, preferring nicknames and contact photos.
  • Where it applies: timeline senders, reply previews, read receipts, the typing indicator, state events, mention pills and mention autocomplete, direct chat titles (sidebar, window title, composer placeholder), the room inspector, and notification titles.
  • Original name stays visible: the Matrix display name remains available as a tooltip and in the profile inspector.

Privacy: contact names are display-only. Mentions inserted by the composer and drag payloads keep the Matrix display name, so contact names are never sent to other users.

Implementation notes

  • New ContactLinking target with a @MainActor @Observable ContactDirectory. It loads contacts off the main actor in two passes: social profiles first, then names and photos for linked contacts only. It reloads on CNContactStoreDidChange.
  • Avatars pick up contact photos centrally in AvatarView. The timeline redraws visible rows when the directory changes.
  • RoomInfo gains directUserId (the single hero of a direct room) to resolve DM titles and avatars.
  • The app target gets the Contacts entitlement and NSContactsUsageDescription.

Testing

  • swift test passes, including a new ContactLinkingTests target: social profile parsing, name fallback order, settings gating. The test target is added to Mactrix.xctestplan.
  • The Mactrix scheme builds; the built app has the address-book entitlement and the usage description.

Matrix users can be linked to a contact from their profile in the
inspector. The link is stored on the contact as a "Matrix" social
profile, so it syncs with the contact and shows up in Contacts.app.

When enabled in the new Contacts settings tab, the linked contact's
name (or nickname) and photo replace the Matrix display name and avatar
throughout the app: timeline, replies, read receipts, typing indicator,
state events, mention pills and autocomplete, DM room titles and
notifications. Contact names are display-only; mentions sent to the
server keep the Matrix display name.
@viktorstrate

Copy link
Copy Markdown
Owner

Awesome great work. I've reviewed the code and it looks very readable and maintainable. When testing the application the integration works really well. I were not able to produce any stale synchronization between Apple Contacts and Mactrix. Although, I couldn't figure out how to add a matrix url to a contact manually (I don't know how to add a custom attribute called matrix without linking from Mactrix).

I only found one small bug that happens when I click "Cancel" to dismiss the link contact popup sheet. Instead of closing the popup cleanly, it plays the close animation twice. I also managed to have the close animation replay several times when relinking. This is probably a simple fix.

Otherwise great work!

@viktorstrate viktorstrate linked an issue Nov 18, 2026 that may be closed by this pull request
@viktorstrate

Copy link
Copy Markdown
Owner

As the earlier mentioned issues are very minor and I want to merge this before another PR (to simplify merge conflicts), I'm merging this one now. Let's address the animation glitch in a separate PR instead.

Thank you very much for implementing this!

@viktorstrate
viktorstrate merged commit d4a5c1f into viktorstrate:main Nov 18, 2026
3 checks passed
viktorstrate added a commit that referenced this pull request Nov 18, 2026
* Implement QuickNavigationSession

* Implement navigation window

* First draft of presenting navigation window

* Make quick navigation view based rather than window based.

* Update quick navigation view to use glass effect

* Hook up navigation popup with matrix rooms

* Polish quick navigation view

* Implement custom scroll animation

* Integrate quick navigation with linked contacts (#137)
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.

Add macOS contacts connections and custom nicknames

2 participants