[PR #1930] [MERGED] feat: format user mentions with display names in email notifications #7919

Closed
opened 2026-04-20 17:56:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/1930
Author: @kolaente
Created: 12/4/2025
Status: Merged
Merged: 12/10/2025
Merged by: @kolaente

Base: mainHead: mention-email-formatting


📝 Commits (10+)

  • ce4079d feat: format user mentions with display names in email notifications
  • ea4f859 feat(avatar): add method to export avatar as base64 inline
  • 4a82676 fix: inline avatar
  • 614f151 fix: style
  • f610bf0 refactor: streamline avatar data uri generation
  • 4706e81 chore: cleanup
  • 6c9e360 fix: fetch upfront
  • 0c973b8 fix: lint
  • 9b0460f chore: refactor
  • 167f5c3 fix: name

📊 Changes

14 files changed (+610 additions, -25 deletions)

View changed files

📝 pkg/models/mentions.go (+189 -0)
📝 pkg/models/mentions_test.go (+213 -0)
📝 pkg/models/notifications.go (+10 -2)
📝 pkg/modules/avatar/avatar.go (+27 -0)
📝 pkg/modules/avatar/empty/empty.go (+15 -1)
📝 pkg/modules/avatar/gravatar/gravatar.go (+16 -0)
📝 pkg/modules/avatar/initials/initials.go (+15 -0)
pkg/modules/avatar/inline_profile_picture_test.go (+77 -0)
📝 pkg/modules/avatar/ldap/ldap.go (+5 -0)
📝 pkg/modules/avatar/marble/marble.go (+16 -0)
📝 pkg/modules/avatar/openid/openid.go (+5 -0)
📝 pkg/modules/avatar/upload/upload.go (+15 -0)
📝 pkg/notifications/mail_render.go (+6 -0)
📝 pkg/routes/api/v1/avatar.go (+1 -22)

📄 Description

Summary

Fixes the issue where user mentions in email notifications show invisible HTML tags or just usernames instead of human-readable display names.

Changes

  • New function: formatMentionsForEmail() in pkg/models/mentions.go

    • Parses HTML to find <mention-user> tags
    • Extracts data-label attribute (display name) or falls back to data-id (username)
    • Replaces mention tags with <strong>@DisplayName</strong> for email rendering
  • Updated notifications:

    • TaskCommentNotification.ToMail() - formats mentions in comments
    • UserMentionedInTaskNotification.ToMail() - formats mentions in task descriptions
  • Comprehensive test coverage: 30+ test cases covering:

    • New format with data-label, old format with text nodes
    • Fallback chain: data-label → data-id → text content
    • HTML preservation (links, paragraphs, bold, italic, lists)
    • Special characters (quotes, ampersands, apostrophes)
    • Unicode characters and emoji
    • Mixed formats, nested structures, malformed HTML

Before / After

Before:

<mention-user data-id="konrad" data-label="Konrad"></mention-user>
→ (stripped by sanitizer, invisible in email)

After:

<mention-user data-id="konrad" data-label="Konrad"></mention-user><strong>@Konrad</strong> (visible as bold "@Konrad" in email)

Technical Details

  • No database lookups needed: Uses existing data-label attribute from mention tags
  • Backward compatible: Handles old mention format with text nodes
  • Safe error handling: Returns original HTML unchanged on parsing errors
  • Linter clean: 0 issues

Test Results

All new tests pass (30/30)
All existing mention tests pass
Linter passes with 0 issues
No breaking changes

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Email notifications now display user mentions with inline avatar images for improved visual recognition and easier identification. Mentions gracefully fall back to display names if avatars are unavailable.
  • Chores

    • Refactored avatar provider architecture for improved code maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/1930 **Author:** [@kolaente](https://github.com/kolaente) **Created:** 12/4/2025 **Status:** ✅ Merged **Merged:** 12/10/2025 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `mention-email-formatting` --- ### 📝 Commits (10+) - [`ce4079d`](https://github.com/go-vikunja/vikunja/commit/ce4079dd9b36a84256fe5acc8fe97a9eb70211ac) feat: format user mentions with display names in email notifications - [`ea4f859`](https://github.com/go-vikunja/vikunja/commit/ea4f859fbb99e982c5fd9454294664b7088e0cdf) feat(avatar): add method to export avatar as base64 inline - [`4a82676`](https://github.com/go-vikunja/vikunja/commit/4a82676f8c94042c19eb4c4a16de6a7a8460c556) fix: inline avatar - [`614f151`](https://github.com/go-vikunja/vikunja/commit/614f151513018a9282f8b012edc766c47aaf4108) fix: style - [`f610bf0`](https://github.com/go-vikunja/vikunja/commit/f610bf0bfe79ec4be479271d4a01d7f9ae1c1390) refactor: streamline avatar data uri generation - [`4706e81`](https://github.com/go-vikunja/vikunja/commit/4706e812bd2a86335d07adb2721f2eae5840c330) chore: cleanup - [`6c9e360`](https://github.com/go-vikunja/vikunja/commit/6c9e360d3eaef10c4d9cb502b7c5941e8cf3c01c) fix: fetch upfront - [`0c973b8`](https://github.com/go-vikunja/vikunja/commit/0c973b82e1d7feaf974feb136576fb8f9dd4676b) fix: lint - [`9b0460f`](https://github.com/go-vikunja/vikunja/commit/9b0460fa67fa67c39724ac5a52cf84d075566a1a) chore: refactor - [`167f5c3`](https://github.com/go-vikunja/vikunja/commit/167f5c32b203424c49d2379f4116a830f3c28f00) fix: name ### 📊 Changes **14 files changed** (+610 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `pkg/models/mentions.go` (+189 -0) 📝 `pkg/models/mentions_test.go` (+213 -0) 📝 `pkg/models/notifications.go` (+10 -2) 📝 `pkg/modules/avatar/avatar.go` (+27 -0) 📝 `pkg/modules/avatar/empty/empty.go` (+15 -1) 📝 `pkg/modules/avatar/gravatar/gravatar.go` (+16 -0) 📝 `pkg/modules/avatar/initials/initials.go` (+15 -0) ➕ `pkg/modules/avatar/inline_profile_picture_test.go` (+77 -0) 📝 `pkg/modules/avatar/ldap/ldap.go` (+5 -0) 📝 `pkg/modules/avatar/marble/marble.go` (+16 -0) 📝 `pkg/modules/avatar/openid/openid.go` (+5 -0) 📝 `pkg/modules/avatar/upload/upload.go` (+15 -0) 📝 `pkg/notifications/mail_render.go` (+6 -0) 📝 `pkg/routes/api/v1/avatar.go` (+1 -22) </details> ### 📄 Description ## Summary Fixes the issue where user mentions in email notifications show invisible HTML tags or just usernames instead of human-readable display names. ### Changes - **New function**: `formatMentionsForEmail()` in `pkg/models/mentions.go` - Parses HTML to find `<mention-user>` tags - Extracts `data-label` attribute (display name) or falls back to `data-id` (username) - Replaces mention tags with `<strong>@DisplayName</strong>` for email rendering - **Updated notifications**: - `TaskCommentNotification.ToMail()` - formats mentions in comments - `UserMentionedInTaskNotification.ToMail()` - formats mentions in task descriptions - **Comprehensive test coverage**: 30+ test cases covering: - New format with data-label, old format with text nodes - Fallback chain: data-label → data-id → text content - HTML preservation (links, paragraphs, bold, italic, lists) - Special characters (quotes, ampersands, apostrophes) - Unicode characters and emoji - Mixed formats, nested structures, malformed HTML ### Before / After **Before**: ```html <mention-user data-id="konrad" data-label="Konrad"></mention-user> → (stripped by sanitizer, invisible in email) ``` **After**: ```html <mention-user data-id="konrad" data-label="Konrad"></mention-user> → <strong>@Konrad</strong> (visible as bold "@Konrad" in email) ``` ### Technical Details - **No database lookups needed**: Uses existing `data-label` attribute from mention tags - **Backward compatible**: Handles old mention format with text nodes - **Safe error handling**: Returns original HTML unchanged on parsing errors - **Linter clean**: 0 issues ### Test Results ✅ All new tests pass (30/30) ✅ All existing mention tests pass ✅ Linter passes with 0 issues ✅ No breaking changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Email notifications now display user mentions with inline avatar images for improved visual recognition and easier identification. Mentions gracefully fall back to display names if avatars are unavailable. * **Chores** * Refactored avatar provider architecture for improved code maintainability. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 17:56:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#7919