commit e0a298dfeeed2cbfed84941394deb9f1b0038211
parent ea775f6936b6676d9f603cb2e3eb806ff5666c4c
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 23 May 2023 16:39:17 -0700
Add sound notifications for stream chat
Diffstat:
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4973,14 +4973,35 @@ Loop:
continue
}
}
+
baseTopBarURL := "/api/v1/chat/top-bar/" + room.Name
readMarkerRendered := true
isFirstMsg := false
- s := v1.RenderMessage(1, *msg, authUser, data, baseTopBarURL, &readMarkerRendered, &isFirstMsg, csrf, config.NullUsername)
- _, _ = c.Response().Write([]byte(fmt.Sprintf(`%s`, s)))
+ renderedMsg := v1.RenderMessage(1, *msg, authUser, data, baseTopBarURL, &readMarkerRendered, &isFirstMsg, csrf, config.NullUsername)
+
+ _, _ = c.Response().Write([]byte(renderedMsg))
+
+ // When editing a message, hide previous revision of the message
if msgTyp.Typ == database.EditMsg {
_, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>.msgidc-%s-%d{display:none;}</style>`, msg.UUID, msg.Rev-1)))
}
+
+ // Sound notifications
+ var taggedSound, pmSound bool
+ if msg.User.ID != authUser.ID {
+ if strings.Contains(renderedMsg, "@"+authUser.Username) {
+ taggedSound = true
+ }
+ if msg.ToUserID != nil && msg.ToUser.ID == authUser.ID {
+ pmSound = true
+ }
+ }
+ if (authUser.NotifyTagged && taggedSound) || (authUser.NotifyPmmed && pmSound) {
+ _, _ = c.Response().Write([]byte(`<audio src="/public/mp3/sound5.mp3" autoplay></audio>`))
+ } else if authUser.NotifyNewMessage {
+ _, _ = c.Response().Write([]byte(`<audio src="/public/mp3/sound6.mp3" autoplay></audio>`))
+ }
+
c.Response().Flush()
// Refresh the page to prevent having it growing infinitely bigger