Mentions are how users talk directly to each other inside an app - tagging teammates, calling attention, or continuing a thread. But mentions can break easily when stored as plain text.
Say your app saves:
Hey @john, can you check this?
Now John changes their username to @johndoe. Every old message still says @john, which is now outdated.
Don't Store Text - Store Identity
Instead of saving the visible username, store a stable reference (like the user’s ID). For example:
@4313
Then, at render time, look up the user’s current profile info by ID and display the latest username.
So internally, your message data could look like this:
{
"content": "Hello <@4313>, please check </12> <#44> <:tada:>",
"mentions": [
{ "id": 4313, "username": "johndoe" }
],
"group_mentions": [
{ "id": 12, "slug": "frontend", "name": "Frontend Team" }
],
"hashtags": [
{ "id": 55, "tag": "release" }
],
"emojis": [
{ "id": "tada", "unicode": "🎉" }
]
}
When rendered, the output becomes:
Hello @johndoe, please check /frontend #release 🎉
This ensures mentions, group mentions, hashtags, and emojis always stay accurate even if usernames or group names change later.
Why This Works
- Future-proof: Mentions update automatically with name changes.
- Structured: Messages become searchable and analyzable.
- Extensible: Supports hashtags
(#), group mentions(/), emojis(:)and more. - Data integrity: Keeps messages semantically consistent over time.