Add default flag emoji display names

This commit is contained in:
sepia 2025-07-23 19:31:41 -05:00
parent bc45f3a604
commit 734b01ea5d
1 changed files with 28 additions and 0 deletions

View File

@ -81,3 +81,31 @@ document.addEventListener('htmx:wsConfigSend', function (e) {
};
}
});
// Set the user's name to their flag by default
document.body.addEventListener('htmx:wsOpen', function (evt) {
const locale = navigator.language || navigator.userLanguage;
const countryCode = locale.split('-')[1] || locale.split('_')[1] || locale;
const countryCodeToFlagEmoji = (code) => {
if (code.length === 2) {
return code
.toUpperCase()
.split('')
.map((char) => String.fromCodePoint(127397 + char.charCodeAt(0)))
.join('');
}
return null;
};
const flagEmoji = countryCodeToFlagEmoji(countryCode);
if (flagEmoji) {
const message = {
type: 'update_display_name',
displayName: flagEmoji,
};
evt.detail.socketWrapper.send(JSON.stringify(message));
const displayNameSpan = document.getElementById('display-name');
displayNameSpan.textContent = flagEmoji;
}
});