add: chat notifications
use sql_chanes/notifications_tag.sql; ignore first statement if you never used a preview commit
This commit is contained in:
parent
a009ef9e34
commit
59cfec4819
22 changed files with 267 additions and 136 deletions
|
@ -109,7 +109,7 @@ hide_user_menu=true) }}
|
|||
<div class="w-full flex flex-col gap-2" id="stream" style="padding: 1rem">
|
||||
<turbo-frame
|
||||
id="stream_body_frame"
|
||||
src="/chats/{{ selected_community }}/{{ selected_channel }}/_stream?page={{ page }}"
|
||||
src="/chats/{{ selected_community }}/{{ selected_channel }}/_stream?page={{ page }}&message={{ message }}"
|
||||
></turbo-frame>
|
||||
|
||||
<form
|
||||
|
@ -336,6 +336,7 @@ hide_user_menu=true) }}
|
|||
|
||||
<script>
|
||||
window.CURRENT_PAGE = Number.parseInt("{{ page }}");
|
||||
window.VIEWING_SINGLE = "{{ message }}".length > 0;
|
||||
window.CHAT_PROPS = {
|
||||
selected_community: "{{ selected_community }}",
|
||||
selected_channel: "{{ selected_channel }}",
|
||||
|
@ -457,6 +458,26 @@ hide_user_menu=true) }}
|
|||
window.socket_id = window.CHAT_PROPS.selected_channel;
|
||||
}
|
||||
|
||||
if (window.CHANNEL_NOTIFS_INTERVAL) {
|
||||
window.clearInterval(window.CHANNEL_NOTIFS_INTERVAL);
|
||||
}
|
||||
|
||||
window.CHANNEL_NOTIFS_INTERVAL = setInterval(() => {
|
||||
if (!window.CHAT_PROPS.selected_channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window.location.href.includes("{{ selected_channel }}")) {
|
||||
window.clearInterval(window.CHANNEL_NOTIFS_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(
|
||||
`/api/v1/notifications/tag/chats/${window.CHAT_PROPS.selected_channel}`,
|
||||
{ method: "DELETE" },
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
window.socket.addEventListener("open", () => {
|
||||
// auth
|
||||
window.socket.send(
|
||||
|
@ -480,7 +501,11 @@ hide_user_menu=true) }}
|
|||
const msg = JSON.parse(event.data);
|
||||
const [channel_id, data] = JSON.parse(msg.data);
|
||||
|
||||
if (msg.method === "Message" && window.CURRENT_PAGE === 0) {
|
||||
if (
|
||||
msg.method === "Message" &&
|
||||
window.CURRENT_PAGE === 0 &&
|
||||
window.VIEWING_SINGLE
|
||||
) {
|
||||
if (channel_id !== window.CHAT_PROPS.selected_channel) {
|
||||
// message not for us... maybe send notification later
|
||||
// something like /api/v1/messages/{id}/mark_unread
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue