commit bfb484b4b897fb265477b9ebd1f5bbd382ce2867
parent 5393bbf6c7275c7210bd12eb23c96b2df72419d7
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 29 Dec 2023 02:07:36 -0500
cleanup
Diffstat:
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/pkg/web/handlers/api/v1/chat.go b/pkg/web/handlers/api/v1/chat.go
@@ -84,6 +84,25 @@ func applyUserFilters(db *database.DkfDB, authUser *database.User, msg *database
return true
}
+func soundNotifications(msg *database.ChatMessage, authUser *database.User, renderedMsg *string) (out string) {
+ var newMessageSound, taggedSound, pmSound bool
+ if msg.User.ID != authUser.ID && !msg.SkipNotify {
+ newMessageSound = true
+ if strings.Contains(*renderedMsg, authUser.Username.AtStr()) {
+ taggedSound = true
+ }
+ if msg.IsPmRecipient(*authUser) {
+ pmSound = true
+ }
+ }
+ if (authUser.NotifyTagged && taggedSound) || (authUser.NotifyPmmed && pmSound) {
+ out = `<audio src="/public/mp3/sound5.mp3" autoplay></audio>`
+ } else if authUser.NotifyNewMessage && newMessageSound {
+ out = `<audio src="/public/mp3/sound6.mp3" autoplay></audio>`
+ }
+ return
+}
+
type Alternator struct {
state bool
fmt, animation string
@@ -382,21 +401,7 @@ Loop:
showReadMarker()
// Sound notifications
- var newMessageSound, taggedSound, pmSound bool
- if msg.User.ID != authUser.ID && !msg.SkipNotify {
- newMessageSound = true
- if strings.Contains(renderedMsg, authUser.Username.AtStr()) {
- taggedSound = true
- }
- if msg.IsPmRecipient(*authUser) {
- pmSound = true
- }
- }
- if (authUser.NotifyTagged && taggedSound) || (authUser.NotifyPmmed && pmSound) {
- send(`<audio src="/public/mp3/sound5.mp3" autoplay></audio>`)
- } else if authUser.NotifyNewMessage && newMessageSound {
- send(`<audio src="/public/mp3/sound6.mp3" autoplay></audio>`)
- }
+ send(soundNotifications(msg, authUser, &renderedMsg))
c.Response().Flush()
} // end of infinite loop (LOOP)