2025-06-01 12:25:33 -04:00
|
|
|
(text "{% extends \"root.html\" %} {% block head %}")
|
|
|
|
(title
|
|
|
|
(text "Chats - {{ config.name }}"))
|
|
|
|
|
|
|
|
(text "{% endblock %} {% block body %} {{ macros::nav(selected=\"chats\", hide_user_menu=true) }}")
|
|
|
|
(nav
|
|
|
|
("class" "chats_nav")
|
|
|
|
(button
|
|
|
|
("class" "flex gap-2 items-center active")
|
|
|
|
("onclick" "toggle_sidebars(event)")
|
|
|
|
(text "{{ icon \"panel-left\" }} {% if community -%}")
|
|
|
|
(b
|
|
|
|
("class" "name shorter")
|
|
|
|
(text "{% if community.context.display_name -%} {{ community.context.display_name }} {% else %} {{ community.title }} {%- endif %}"))
|
|
|
|
(text "{% else %}")
|
|
|
|
(b
|
|
|
|
(text "{{ text \"chats:label.my_chats\" }}"))
|
|
|
|
(text "{%- endif %}")))
|
|
|
|
|
|
|
|
(div
|
|
|
|
("class" "flex")
|
|
|
|
(div
|
|
|
|
("class" "sidebar flex flex-col items-center gap-2")
|
|
|
|
("id" "community_list")
|
|
|
|
("style" "width: var(--list-bar-width)")
|
|
|
|
(a
|
|
|
|
("href" "/chats/0/0")
|
|
|
|
("class" "button quaternary channel_icon {% if selected_community == 0 -%}selected{%- endif %}")
|
|
|
|
("data-turbo" "false")
|
|
|
|
(text "{{ icon \"message-circle\" }}"))
|
|
|
|
(text "{% for community in communities %} {% if community.id != 0 -%}")
|
|
|
|
(a
|
|
|
|
("href" "/chats/{{ community.id }}/0")
|
|
|
|
("class" "button quaternary channel_icon {% if selected_community == community.id -%}selected{%- endif %}")
|
|
|
|
("data-turbo" "false")
|
|
|
|
(text "{{ components::community_avatar(id=community.id, community=community, size=\"48px\") }}"))
|
|
|
|
(text "{%- endif %} {% endfor %}"))
|
|
|
|
(div
|
|
|
|
("class" "sidebar flex flex-col gap-2 justify-between")
|
|
|
|
("id" "channels_list")
|
|
|
|
(div
|
|
|
|
("class" "flex flex-col gap-2 w-full")
|
|
|
|
(div
|
|
|
|
("class" "title flex items-center justify-between channel_header")
|
|
|
|
(text "{% if community -%}")
|
|
|
|
(b
|
|
|
|
("class" "name shorter")
|
|
|
|
(text "{% if community.context.display_name -%} {{ community.context.display_name }} {% else %} {{ community.title }} {%- endif %}"))
|
|
|
|
(text "{% else %}")
|
|
|
|
(b
|
|
|
|
(text "{{ text \"chats:label.my_chats\" }}"))
|
|
|
|
(text "{%- endif %} {% if selected_community != 0 -%}")
|
|
|
|
(div
|
|
|
|
("class" "dropdown")
|
|
|
|
(button
|
|
|
|
("class" "camo small")
|
|
|
|
("onclick" "trigger('atto::hooks::dropdown', [event])")
|
|
|
|
("exclude" "dropdown")
|
|
|
|
(text "{{ icon \"ellipsis\" }}"))
|
|
|
|
(div
|
|
|
|
("class" "inner")
|
|
|
|
(a
|
|
|
|
("href" "/community/{{ selected_community }}")
|
|
|
|
(text "{{ icon \"book-heart\" }}")
|
|
|
|
(span
|
|
|
|
(text "{{ text \"communities:label.show_community\" }}")))
|
|
|
|
(text "{% if can_manage_channels -%}")
|
|
|
|
(a
|
|
|
|
("href" "/community/{{ selected_community }}/manage")
|
|
|
|
(text "{{ icon \"settings\" }}")
|
|
|
|
(span
|
|
|
|
(text "{{ text \"general:action.manage\" }}")))
|
|
|
|
(text "{%- endif %}")))
|
|
|
|
(text "{%- endif %}"))
|
|
|
|
(text "{% if can_manage_channels -%}")
|
|
|
|
(a
|
|
|
|
("class" "button w-full justify-start quaternary")
|
|
|
|
("href" "/community/{{ selected_community }}/manage#/channels")
|
|
|
|
(text "{{ icon \"plus\" }}")
|
|
|
|
(span
|
|
|
|
(text "{{ text \"communities:action.create_channel\" }}")))
|
|
|
|
(text "{%- endif %}")
|
|
|
|
(turbo-frame
|
|
|
|
("id" "channels_list_frame")
|
|
|
|
("src" "/chats/{{ selected_community }}/{{ selected_channel }}/_channels")
|
|
|
|
("target" "_top")))
|
|
|
|
(text "{{ components::user_plate(user=user, show_menu=true) }}"))
|
|
|
|
(text "{% if channel -%}")
|
|
|
|
(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 }}&message={{ message }}"))
|
|
|
|
(form
|
|
|
|
("class" "card flex flex-row gap-2")
|
|
|
|
("onsubmit" "create_message_from_form(event)")
|
|
|
|
(textarea
|
|
|
|
("type" "text")
|
|
|
|
("name" "content")
|
|
|
|
("id" "content")
|
|
|
|
("placeholder" "message {{ channel.title }}")
|
|
|
|
("required" "")
|
|
|
|
("minlength" "2")
|
|
|
|
("maxlength" "2048")
|
|
|
|
("style" "min-height: 48px !important; height: 48px"))
|
|
|
|
(button
|
|
|
|
("class" "camo send_button")
|
|
|
|
("title" "Send")
|
|
|
|
(text "{{ icon \"send-horizontal\" }}"))))
|
|
|
|
(text "{%- endif %}")
|
|
|
|
(style
|
|
|
|
(text ":root {
|
2025-04-27 23:11:37 -04:00
|
|
|
--list-bar-width: 64px;
|
|
|
|
--channels-bar-width: 256px;
|
2025-05-06 21:30:02 -04:00
|
|
|
--sidebar-height: calc(100dvh - 42px);
|
|
|
|
--channel-header-height: 48px;
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
html,
|
|
|
|
body {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
2025-04-27 23:28:23 -04:00
|
|
|
.name.shortest {
|
|
|
|
max-width: 165px;
|
|
|
|
overflow-wrap: normal;
|
|
|
|
}
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
.send_button {
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.send_button .icon {
|
|
|
|
width: 2em;
|
|
|
|
height: 2em;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon {
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
2025-04-27 23:28:23 -04:00
|
|
|
min-height: 48px;
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon .icon {
|
|
|
|
min-width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon.small {
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
2025-04-27 23:28:23 -04:00
|
|
|
min-height: 24px;
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon.small .icon {
|
|
|
|
min-width: 12px;
|
|
|
|
height: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon:has(img) {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon img {
|
|
|
|
min-width: 48px;
|
|
|
|
min-height: 48px;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon img,
|
|
|
|
a.channel_icon:has(.icon) {
|
|
|
|
transition:
|
|
|
|
outline 0.25s,
|
|
|
|
background 0.15s !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.channel_icon:not(.selected):hover img,
|
|
|
|
a.channel_icon:not(.selected):hover:has(.icon) {
|
|
|
|
outline: solid 1px var(--color-text);
|
|
|
|
}
|
|
|
|
a.channel_icon.selected img,
|
|
|
|
a.channel_icon.selected:has(.icon) {
|
|
|
|
outline: solid 2px var(--color-text);
|
|
|
|
}
|
|
|
|
|
|
|
|
nav {
|
|
|
|
background: var(--color-raised);
|
|
|
|
color: var(--color-text-raised) !important;
|
|
|
|
height: 42px;
|
|
|
|
position: sticky !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
nav::after {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
background: var(--color-super-lowered);
|
|
|
|
height: 1px;
|
|
|
|
width: calc(100% - var(--list-bar-width));
|
|
|
|
bottom: 0;
|
|
|
|
left: var(--list-bar-width);
|
2025-06-01 12:25:33 -04:00
|
|
|
content: \"\";
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
nav .content_container {
|
|
|
|
max-width: 100% !important;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chats_nav {
|
|
|
|
display: none;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chats_nav button {
|
|
|
|
justify-content: flex-start;
|
|
|
|
width: 100% !important;
|
|
|
|
flex-direction: row !important;
|
|
|
|
font-size: 16px !important;
|
|
|
|
margin-top: -4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chats_nav button svg {
|
|
|
|
margin-right: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.sidebar {
|
|
|
|
background: var(--color-raised);
|
|
|
|
color: var(--color-text-raised);
|
|
|
|
border-right: solid 1px var(--color-super-lowered);
|
|
|
|
padding: 0.4rem;
|
|
|
|
width: max-content;
|
2025-05-06 21:30:02 -04:00
|
|
|
height: var(--sidebar-height);
|
2025-04-27 23:11:37 -04:00
|
|
|
overflow: auto;
|
|
|
|
transition: left 0.15s;
|
2025-05-01 23:35:40 -04:00
|
|
|
z-index: 1;
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
2025-05-03 11:29:31 -04:00
|
|
|
.sidebar .title:not(.dropdown *) {
|
2025-04-27 23:11:37 -04:00
|
|
|
padding: 1rem;
|
|
|
|
border-bottom: solid 1px var(--color-super-lowered);
|
|
|
|
}
|
|
|
|
|
|
|
|
.sidebar#channels_list {
|
|
|
|
width: var(--channels-bar-width);
|
|
|
|
background: var(--color-surface);
|
|
|
|
color: var(--color-text);
|
|
|
|
}
|
|
|
|
|
|
|
|
#stream {
|
|
|
|
width: calc(
|
|
|
|
100dvw - var(--list-bar-width) - var(--channels-bar-width)
|
|
|
|
) !important;
|
2025-05-06 21:30:02 -04:00
|
|
|
height: var(--sidebar-height);
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.message {
|
|
|
|
transition: background 0.15s;
|
|
|
|
box-shadow: none;
|
2025-05-01 16:43:58 -04:00
|
|
|
position: relative;
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.message:hover {
|
|
|
|
background: var(--color-raised);
|
|
|
|
}
|
|
|
|
|
|
|
|
.message:hover .hidden,
|
|
|
|
.message:focus .hidden,
|
|
|
|
.message:active .hidden {
|
|
|
|
display: flex !important;
|
|
|
|
}
|
|
|
|
|
2025-05-01 16:43:58 -04:00
|
|
|
.message.grouped {
|
2025-05-06 21:30:02 -04:00
|
|
|
padding: 0.25rem 1rem 0.25rem calc(1rem + 0.5rem + 42px);
|
2025-05-01 16:43:58 -04:00
|
|
|
}
|
2025-05-06 21:30:02 -04:00
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
turbo-frame {
|
|
|
|
display: contents;
|
|
|
|
}
|
|
|
|
|
2025-05-06 21:30:02 -04:00
|
|
|
.channel_header {
|
|
|
|
height: var(--channel-header-height);
|
|
|
|
}
|
|
|
|
|
|
|
|
.members_list_half {
|
|
|
|
padding-top: 1rem;
|
|
|
|
border-top: solid 1px var(--color-super-lowered);
|
|
|
|
}
|
|
|
|
|
|
|
|
.channels_list_half:not(.no_members),
|
|
|
|
.members_list_half {
|
|
|
|
overflow: auto;
|
|
|
|
height: calc(
|
|
|
|
(var(--sidebar-height) - var(--channel-header-height) - 8rem) /
|
|
|
|
2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
@media screen and (max-width: 900px) {
|
2025-05-06 21:30:02 -04:00
|
|
|
:root {
|
|
|
|
--sidebar-height: calc(100dvh - 42px * 2);
|
|
|
|
}
|
|
|
|
|
2025-05-01 16:43:58 -04:00
|
|
|
.message.grouped {
|
2025-05-10 21:58:02 -04:00
|
|
|
padding: 0.25rem 1rem 0.25rem calc(1rem + 0.5rem + 31px);
|
2025-05-01 16:43:58 -04:00
|
|
|
}
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
body:not(.sidebars_shown) .sidebar {
|
|
|
|
position: absolute;
|
|
|
|
left: -200%;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.sidebars_shown .sidebar {
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
#stream {
|
|
|
|
width: 100dvw !important;
|
2025-05-06 21:30:02 -04:00
|
|
|
height: var(--sidebar-height);
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
nav::after {
|
|
|
|
width: 100dvw;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chats_nav {
|
|
|
|
display: flex;
|
|
|
|
}
|
2025-06-01 12:25:33 -04:00
|
|
|
}"))
|
|
|
|
(script
|
|
|
|
(text "window.CURRENT_PAGE = Number.parseInt(\"{{ page }}\");
|
|
|
|
window.VIEWING_SINGLE = \"{{ message }}\".length > 0;
|
2025-04-27 23:11:37 -04:00
|
|
|
window.CHAT_PROPS = {
|
2025-06-01 12:25:33 -04:00
|
|
|
selected_community: \"{{ selected_community }}\",
|
|
|
|
selected_channel: \"{{ selected_channel }}\",
|
|
|
|
membership_role: Number.parseInt(\"{{ membership_role }}\"),
|
2025-04-27 23:11:37 -04:00
|
|
|
};
|
|
|
|
|
2025-04-30 16:45:31 -04:00
|
|
|
window.SIDEBARS_OPEN = false;
|
2025-06-01 12:25:33 -04:00
|
|
|
if (new URLSearchParams(window.location.search).get(\"nav\") === \"true\") {
|
2025-04-30 16:45:31 -04:00
|
|
|
window.SIDEBARS_OPEN = true;
|
|
|
|
}
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
if (
|
|
|
|
window.SIDEBARS_OPEN &&
|
2025-06-01 12:25:33 -04:00
|
|
|
!document.body.classList.contains(\"sidebars_shown\")
|
2025-04-27 23:11:37 -04:00
|
|
|
) {
|
|
|
|
toggle_sidebars();
|
|
|
|
window.SIDEBARS_OPEN = true;
|
|
|
|
}
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
for (const anchor of document.querySelectorAll(\"[data-turbo=false]\")) {
|
2025-04-30 16:45:31 -04:00
|
|
|
anchor.href += `?nav=${window.SIDEBARS_OPEN}`;
|
|
|
|
}
|
|
|
|
|
2025-05-06 21:30:02 -04:00
|
|
|
function mention_user(username) {
|
2025-06-01 12:25:33 -04:00
|
|
|
document.getElementById(\"content\").value += ` @${username} `;
|
2025-05-06 21:30:02 -04:00
|
|
|
}
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
function toggle_sidebars() {
|
|
|
|
window.SIDEBARS_OPEN = !window.SIDEBARS_OPEN;
|
2025-04-30 16:45:31 -04:00
|
|
|
|
|
|
|
for (const anchor of document.querySelectorAll(
|
2025-06-01 12:25:33 -04:00
|
|
|
\"[data-turbo=false]\",
|
2025-04-30 16:45:31 -04:00
|
|
|
)) {
|
|
|
|
anchor.href = anchor.href.replace(
|
|
|
|
`?nav=${!window.SIDEBARS_OPEN}`,
|
|
|
|
`?nav=${window.SIDEBARS_OPEN}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
const community_list = document.getElementById(\"community_list\");
|
|
|
|
const channels_list = document.getElementById(\"channels_list\");
|
2025-04-27 23:11:37 -04:00
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
if (document.body.classList.contains(\"sidebars_shown\")) {
|
2025-04-27 23:11:37 -04:00
|
|
|
// hide
|
2025-06-01 12:25:33 -04:00
|
|
|
document.body.classList.remove(\"sidebars_shown\");
|
|
|
|
community_list.style.left = \"-200%\";
|
|
|
|
channels_list.style.left = \"-200%\";
|
2025-04-27 23:11:37 -04:00
|
|
|
} else {
|
|
|
|
// show
|
2025-06-01 12:25:33 -04:00
|
|
|
document.body.classList.add(\"sidebars_shown\");
|
|
|
|
community_list.style.left = \"0\";
|
|
|
|
channels_list.style.left = \"var(--list-bar-width)\";
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-05-06 21:30:02 -04:00
|
|
|
globalThis.add_member = async (id) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
await trigger(\"atto::debounce\", [\"channels::add_member\"]);
|
|
|
|
const member = await trigger(\"atto::prompt\", [\"Member username:\"]);
|
2025-05-06 21:30:02 -04:00
|
|
|
|
|
|
|
if (!member) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/channels/${id}/add`, {
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"POST\",
|
2025-05-06 21:30:02 -04:00
|
|
|
headers: {
|
2025-06-01 12:25:33 -04:00
|
|
|
\"Content-Type\": \"application/json\",
|
2025-05-06 21:30:02 -04:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
member,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [
|
|
|
|
res.ok ? \"success\" : \"error\",
|
2025-05-06 21:30:02 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
globalThis.update_channel_title = async (id) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
await trigger(\"atto::debounce\", [\"channels::update_title\"]);
|
|
|
|
const title = await trigger(\"atto::prompt\", [\"New channel title:\"]);
|
2025-05-06 21:30:02 -04:00
|
|
|
|
|
|
|
if (!title) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/channels/${id}/title`, {
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"POST\",
|
2025-05-06 21:30:02 -04:00
|
|
|
headers: {
|
2025-06-01 12:25:33 -04:00
|
|
|
\"Content-Type\": \"application/json\",
|
2025-05-06 21:30:02 -04:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
title,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [
|
|
|
|
res.ok ? \"success\" : \"error\",
|
2025-05-06 21:30:02 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2025-04-27 23:11:37 -04:00
|
|
|
globalThis.kick_member = async (cid, uid) => {
|
|
|
|
if (
|
2025-06-01 12:25:33 -04:00
|
|
|
!(await trigger(\"atto::confirm\", [
|
|
|
|
\"Are you sure you would like to do this?\",
|
2025-04-27 23:11:37 -04:00
|
|
|
]))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/channels/${cid}/kick`, {
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"POST\",
|
2025-04-27 23:11:37 -04:00
|
|
|
headers: {
|
2025-06-01 12:25:33 -04:00
|
|
|
\"Content-Type\": \"application/json\",
|
2025-04-27 23:11:37 -04:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
member: uid,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [
|
|
|
|
res.ok ? \"success\" : \"error\",
|
2025-04-27 23:11:37 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
globalThis.delete_channel = async (id) => {
|
|
|
|
if (
|
2025-06-01 12:25:33 -04:00
|
|
|
!(await trigger(\"atto::confirm\", [
|
|
|
|
\"Are you sure you would like to do this?\",
|
2025-04-27 23:11:37 -04:00
|
|
|
]))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/channels/${id}`, {
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"DELETE\",
|
2025-04-27 23:11:37 -04:00
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [
|
|
|
|
res.ok ? \"success\" : \"error\",
|
2025-04-27 23:11:37 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
2025-06-01 12:25:33 -04:00
|
|
|
};"))
|
|
|
|
(script
|
|
|
|
("id" "socket_init")
|
|
|
|
("data-turbo-permanent" "true")
|
|
|
|
(text "globalThis.socket_init = () => {
|
2025-04-27 23:11:37 -04:00
|
|
|
if (window.socket) {
|
2025-06-01 12:25:33 -04:00
|
|
|
window.socket.send(\"Close\");
|
2025-04-29 16:53:34 -04:00
|
|
|
window.socket.close();
|
|
|
|
window.socket = undefined;
|
2025-06-01 12:25:33 -04:00
|
|
|
console.log(\"closed lingering\");
|
2025-04-27 23:11:37 -04:00
|
|
|
}
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
if (window.CHAT_PROPS.selected_community !== \"0\") {
|
|
|
|
const endpoint = `${window.location.origin.replace(\"http\", \"ws\")}/api/v1/_connect/${window.CHAT_PROPS.selected_community}`;
|
2025-04-29 16:53:34 -04:00
|
|
|
const socket = new WebSocket(endpoint);
|
|
|
|
window.socket = socket;
|
2025-04-30 16:45:31 -04:00
|
|
|
window.socket_id = window.CHAT_PROPS.selected_community;
|
2025-04-29 16:53:34 -04:00
|
|
|
} else {
|
2025-06-01 12:25:33 -04:00
|
|
|
const endpoint = `${window.location.origin.replace(\"http\", \"ws\")}/api/v1/_connect/${window.CHAT_PROPS.selected_channel}`;
|
2025-04-29 16:53:34 -04:00
|
|
|
const socket = new WebSocket(endpoint);
|
|
|
|
window.socket = socket;
|
2025-04-30 16:45:31 -04:00
|
|
|
window.socket_id = window.CHAT_PROPS.selected_channel;
|
2025-04-28 01:30:03 -04:00
|
|
|
}
|
|
|
|
|
2025-05-03 17:51:36 -04:00
|
|
|
if (window.CHANNEL_NOTIFS_INTERVAL) {
|
|
|
|
window.clearInterval(window.CHANNEL_NOTIFS_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
window.CHANNEL_NOTIFS_INTERVAL = setInterval(() => {
|
|
|
|
if (!window.CHAT_PROPS.selected_channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
if (!window.location.href.includes(\"{{ selected_channel }}\")) {
|
2025-05-03 17:51:36 -04:00
|
|
|
window.clearInterval(window.CHANNEL_NOTIFS_INTERVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(
|
|
|
|
`/api/v1/notifications/tag/chats/${window.CHAT_PROPS.selected_channel}`,
|
2025-06-01 12:25:33 -04:00
|
|
|
{ method: \"DELETE\" },
|
2025-05-03 17:51:36 -04:00
|
|
|
);
|
|
|
|
}, 10000);
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
window.socket.addEventListener(\"open\", () => {
|
2025-04-27 23:11:37 -04:00
|
|
|
// auth
|
2025-04-29 16:53:34 -04:00
|
|
|
window.socket.send(
|
2025-04-27 23:11:37 -04:00
|
|
|
JSON.stringify({
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"Headers\",
|
2025-04-27 23:11:37 -04:00
|
|
|
data: JSON.stringify({
|
|
|
|
// SocketHeaders
|
2025-06-01 12:25:33 -04:00
|
|
|
user: \"{{ user.id }}\",
|
2025-04-29 16:53:34 -04:00
|
|
|
is_channel: window.SUBSCRIBE_CHANNEL,
|
2025-04-27 23:11:37 -04:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2025-04-30 16:45:31 -04:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2025-05-06 21:30:02 -04:00
|
|
|
window.LAST_MESSAGE_AUTHOR_ID = null;
|
2025-06-01 12:25:33 -04:00
|
|
|
window.socket.addEventListener(\"message\", async (event) => {
|
|
|
|
if (event.data === \"Ping\") {
|
|
|
|
return socket.send(\"Pong\");
|
2025-04-30 16:45:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const msg = JSON.parse(event.data);
|
|
|
|
|
2025-05-03 17:51:36 -04:00
|
|
|
if (
|
2025-06-01 12:25:33 -04:00
|
|
|
msg.method === \"Message\" &&
|
2025-05-03 17:51:36 -04:00
|
|
|
window.CURRENT_PAGE === 0 &&
|
|
|
|
window.VIEWING_SINGLE
|
|
|
|
) {
|
2025-05-12 18:46:24 -04:00
|
|
|
const [channel_id, data] = JSON.parse(msg.data);
|
2025-04-30 16:45:31 -04:00
|
|
|
if (channel_id !== window.CHAT_PROPS.selected_channel) {
|
|
|
|
// message not for us... maybe send notification later
|
|
|
|
// something like /api/v1/messages/{id}/mark_unread
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
if (document.getElementById(\"stream_body\")) {
|
|
|
|
const element = document.createElement(\"div\");
|
|
|
|
element.style.display = \"contents\";
|
2025-05-06 21:30:02 -04:00
|
|
|
|
|
|
|
const message_owner = JSON.parse(msg.data)[1].owner;
|
2025-04-30 16:45:31 -04:00
|
|
|
element.innerHTML = await (
|
|
|
|
await fetch(
|
|
|
|
`/chats/${window.CHAT_PROPS.selected_community}/${window.CHAT_PROPS.selected_channel}/_render`,
|
|
|
|
{
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"POST\",
|
2025-04-30 16:45:31 -04:00
|
|
|
headers: {
|
2025-06-01 12:25:33 -04:00
|
|
|
\"Content-Type\": \"application/json\",
|
2025-04-30 16:45:31 -04:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
data: msg.data,
|
2025-05-06 21:30:02 -04:00
|
|
|
grouped:
|
|
|
|
message_owner ===
|
|
|
|
window.LAST_MESSAGE_AUTHOR_ID,
|
2025-04-30 16:45:31 -04:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
).text();
|
|
|
|
|
|
|
|
document
|
2025-06-01 12:25:33 -04:00
|
|
|
.getElementById(\"stream_body\")
|
2025-04-30 16:45:31 -04:00
|
|
|
.prepend(element);
|
|
|
|
clean_text();
|
2025-05-06 21:30:02 -04:00
|
|
|
|
|
|
|
window.LAST_MESSAGE_AUTHOR_ID = message_owner;
|
2025-04-30 16:45:31 -04:00
|
|
|
} else {
|
2025-06-01 12:25:33 -04:00
|
|
|
console.log(\"abandoned remote\");
|
2025-04-30 16:45:31 -04:00
|
|
|
socket.close();
|
|
|
|
}
|
2025-06-01 12:25:33 -04:00
|
|
|
} else if (msg.method === \"Delete\") {
|
2025-05-12 18:46:24 -04:00
|
|
|
const data = JSON.parse(msg.data);
|
2025-04-30 16:45:31 -04:00
|
|
|
if (document.getElementById(`message-${data.id}`)) {
|
|
|
|
document
|
|
|
|
.getElementById(`message-${data.id}`)
|
|
|
|
.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
globalThis.create_message_from_form = async (e) => {
|
|
|
|
e.preventDefault();
|
2025-06-01 12:25:33 -04:00
|
|
|
await trigger(\"atto::debounce\", [\"messages::create\"]);
|
2025-04-30 16:45:31 -04:00
|
|
|
|
2025-06-01 12:25:33 -04:00
|
|
|
fetch(\"/api/v1/messages\", {
|
|
|
|
method: \"POST\",
|
2025-04-30 16:45:31 -04:00
|
|
|
headers: {
|
2025-06-01 12:25:33 -04:00
|
|
|
\"Content-Type\": \"application/json\",
|
2025-04-30 16:45:31 -04:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
2025-05-06 21:30:02 -04:00
|
|
|
content: e.target.content.value.trim(),
|
2025-04-30 16:45:31 -04:00
|
|
|
channel: window.CHAT_PROPS.selected_channel,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [\"error\", res.message]);
|
2025-04-30 16:45:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
e.target.reset();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
globalThis.delete_message = async (id) => {
|
|
|
|
if (
|
2025-06-01 12:25:33 -04:00
|
|
|
!(await trigger(\"atto::confirm\", [
|
|
|
|
\"Are you sure you would like to do this?\",
|
2025-04-30 16:45:31 -04:00
|
|
|
]))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`/api/v1/messages/${id}`, {
|
2025-06-01 12:25:33 -04:00
|
|
|
method: \"DELETE\",
|
2025-04-30 16:45:31 -04:00
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::toast\", [
|
|
|
|
res.ok ? \"success\" : \"error\",
|
2025-04-30 16:45:31 -04:00
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const clean_text = () => {
|
2025-06-01 12:25:33 -04:00
|
|
|
trigger(\"atto::clean_date_codes\");
|
|
|
|
trigger(\"atto::hooks::online_indicator\");
|
2025-04-30 16:45:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener(
|
2025-06-01 12:25:33 -04:00
|
|
|
\"turbo:before-frame-render\",
|
2025-04-30 16:45:31 -04:00
|
|
|
(event) => {
|
|
|
|
setTimeout(clean_text, 50);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
setTimeout(clean_text, 150);
|
|
|
|
}, 250);
|
2025-06-01 12:25:33 -04:00
|
|
|
};"))
|
|
|
|
(text "{% if selected_channel -%}")
|
|
|
|
(script
|
|
|
|
(text "window.SUBSCRIBE_CHANNEL = \"{{ selected_community }}\" === \"0\";
|
2025-04-29 16:58:42 -04:00
|
|
|
|
2025-04-29 16:53:34 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
if (!window.SUBSCRIBE_CHANNEL) {
|
|
|
|
// sub community
|
2025-06-01 12:25:33 -04:00
|
|
|
if (window.socket_id !== \"{{ selected_community }}\") {
|
2025-04-29 16:53:34 -04:00
|
|
|
socket_init();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// sub channel
|
2025-06-01 12:25:33 -04:00
|
|
|
if (window.socket_id !== \"{{ selected_channel }}\") {
|
2025-04-29 16:53:34 -04:00
|
|
|
socket_init();
|
|
|
|
}
|
|
|
|
}
|
2025-06-01 12:25:33 -04:00
|
|
|
}, 100);"))
|
|
|
|
(text "{%- endif %}"))
|
|
|
|
|
|
|
|
(text "{% endblock %}")
|