Added notifcation when you're name is mentioned

This commit is contained in:
skattkookie 2026-02-28 12:48:19 +00:00
parent 8f6d502b3e
commit b727227162
1 changed files with 25 additions and 0 deletions

View File

@ -110,6 +110,31 @@ export function injectSounds(webContents: Electron.WebContents) {
playUserLeaveSound();
}
if (data.type === "Message" && data.mentions?.includes(currentUserId) && data.author !== currentUserId) {
playMentionSound();
const cachedName = userNameCache[data.author];
if (cachedName) {
const myName = userNameCache[currentUserId] || 'you';
const content = data.content?.replace(/<@[^>]+>/g, '@' + myName).trim() || "New message";
__showMentionToast(cachedName, 'mention', content);
} else {
// fetch user from API if not cached
fetch('https://api.revolt.chat/users/' + data.author)
.then(r => r.json())
.then(user => {
const name = user.username || data.author;
userNameCache[data.author] = name;
const myName = userNameCache[currentUserId] || 'you';
const content = data.content?.replace(/<@[^>]+>/g, '@' + myName).trim() || "New message";
__showMentionToast(name, 'mention', content);
})
.catch(() => {
const content = data.content?.replace(/<@[^>]+>/g, '').trim() || "New message";
__showMentionToast(data.author, 'mention', content);
});
}
}
if (data.type === "Message" && data.role_mentions?.length > 0 && data.member?.roles?.length > 0) {
const matchedRoleId = data.role_mentions.find(roleId => data.member.roles.includes(roleId));
if (matchedRoleId) {