Apply channel_name_template to 1-to-1 DM rooms; track displayname template hash to force re-sync on change
**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.
```yaml
# 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.
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 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.](https://gh.io/cca-advanced-security)
合并状态:未合并 2 条评论