Added sound.

This commit is contained in:
retoor 2025-02-21 00:24:14 +01:00
parent a7e0e5a3f8
commit 54920e1545
3 changed files with 13 additions and 5 deletions

View File

@ -263,7 +263,10 @@ class NotificationAudio {
this.schedule = new Schedule(timeout); this.schedule = new Schedule(timeout);
} }
sounds = ["/audio/soundfx.d_beep3.mp3"]; sounds = [
"/audio/soundfx.d_beep3.mp3",
"/audio/mention1.wav"
];
play(soundIndex = 0) { play(soundIndex = 0) {
this.schedule.delay(() => { this.schedule.delay(() => {

Binary file not shown.

View File

@ -116,11 +116,20 @@
setInterval(updateTimes, 1000); setInterval(updateTimes, 1000);
function isMention(message){
const mentionText = '@{{ user.username.value }}';
return message.toLowerCase().includes(mentionText);
}
app.addEventListener("channel-message", (data) => { app.addEventListener("channel-message", (data) => {
if (data.channel_uid !== channelUid) return; if (data.channel_uid !== channelUid) return;
if (data.username !== "{{ user.username.value }}") { if (data.username !== "{{ user.username.value }}") {
if(isMention(data.message)){
app.playSound(1);
}else{
app.playSound(0); app.playSound(0);
}
} }
const messagesContainer = document.querySelector(".chat-messages"); const messagesContainer = document.querySelector(".chat-messages");
@ -128,10 +137,6 @@
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage); const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
const message = document.createElement("div"); const message = document.createElement("div");
message.dataset.color = data.color;
message.dataset.created_at = data.created_at;
message.dataset.user_nick = data.user_nick;
message.dataset.uid = data.uid;
message.innerHTML = data.html; message.innerHTML = data.html;
document.querySelector(".chat-messages").appendChild(message.firstChild); document.querySelector(".chat-messages").appendChild(message.firstChild);
updateLayout(doScrollDownBecauseLastMessageIsVisible); updateLayout(doScrollDownBecauseLastMessageIsVisible);