Skip to content

Apply channel_name_template to 1-to-1 DM rooms; track displayname template hash to force re-sync on change#74

Open
BierDav wants to merge 5 commits intomautrix:mainfrom
BierDav:copilot/update-slack-displayname-template
Open

Apply channel_name_template to 1-to-1 DM rooms; track displayname template hash to force re-sync on change#74
BierDav wants to merge 5 commits intomautrix:mainfrom
BierDav:copilot/update-slack-displayname-template

Conversation

@BierDav
Copy link

@BierDav BierDav commented Mar 8, 2026

Disclaimer: This code was fully AI generated, but reviewed by me if makes sense. I'm not an expert in go nor very familiar with the codebase. I've tested these changes in my environment using the follwing configuration:

 mautrix-slack:
    build:
      context: "https://github.com/BierDav/slack.git#copilot/update-slack-displayname-template"
      dockerfile: Dockerfile
    restart: unless-stopped

Two independent bugs prevented templates from being applied as configured:

  1. DM rooms bypassed channel_name_template — room name was left nil, so the Matrix bridge used the ghost display name directly. Users had no way to add a suffix (e.g. (SL)) to DM rooms independently of puppet names.

  2. Changing displayname_template didn't re-format existing puppets — the bridge uses Slack's incremental cache API (GetUsersCacheContext with per-user timestamps). If a user's Slack profile hadn't changed, Slack returned nothing, wrapUserInfo was never called, and the new template was never applied.

Changes

DM room names now go through channel_name_template

  • Removed the roomType != database.RoomTypeDM guard in wrapChatInfo; formatChannelName is now called unconditionally for all channel types.
  • For 1-to-1 DMs, info.Name is already set to the other user's ghost display name, so the default template is fully backward-compatible.
  • Updated example-config.yaml to document that .Name for DM channels is the other user's display name.
# Add (SL) only to DM rooms:
channel_name_template: '{{if and .IsChannel (not .IsPrivate)}}#{{end}}{{.Name}}{{if .IsNoteToSelf}} (you){{end}}{{if .IsIM}} (SL){{end}}'

Template-change detection forces puppet re-sync

  • Added NameTemplateHash (string, omitempty) to GhostMetadata — persisted in the DB, records which template version last formatted each ghost.
  • Config computes a 16-hex-char SHA-256 hash of DisplaynameTemplate at load time; exposed via GetDisplaynameTemplateHash().
  • wrapUserInfo ExtraUpdates writes the current hash into ghost metadata after formatting.
  • syncManyUsers passes lastUpdated = 0 for any ghost whose stored hash diverges from the current one, forcing Slack to return full user data even for otherwise-unchanged profiles.
  • GetUserInfo bypasses the 4-hour MinGhostSyncInterval gate when the template hash has changed.

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 5 commits March 8, 2026 17:48
…e changes

Co-authored-by: BierDav <46626041+BierDav@users.noreply.github.com>
Co-authored-by: BierDav <46626041+BierDav@users.noreply.github.com>
…ame_template

Co-authored-by: BierDav <46626041+BierDav@users.noreply.github.com>
…tals

Co-authored-by: BierDav <46626041+BierDav@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants