86 lines
3.1 KiB
HTML
86 lines
3.1 KiB
HTML
{# includes/chat_detail_scripts.html #}
|
|
{# Скрипты только для страницы chat_detail.html #}
|
|
{% load static %}
|
|
|
|
<script type="module">
|
|
import { initChatMarkRead } from "{% static 'js/components/chatMarkRead.js' %}";
|
|
import { initChatComposer } from "{% static 'js/components/chatComposer.js' %}";
|
|
import { initChatHistoryLoader } from "{% static 'js/components/chatHistoryLoader.js' %}";
|
|
import { initChatFormManager } from "{% static 'js/components/chatFormManager.js' %}";
|
|
|
|
// Ждём готовности chat-системы
|
|
window.addEventListener('chat:system-ready', (e) => {
|
|
console.log('[ChatDetailScripts] chat:system-ready event received!', e.detail);
|
|
const { userWs, avatarMap, badgeManager } = e.detail;
|
|
|
|
// ========== FORM MANAGER ==========
|
|
// Управление режимами формы (send/edit/reply)
|
|
console.log('[ChatDetailScripts] Initializing FormManager...');
|
|
const formManager = initChatFormManager({
|
|
formId: 'chatForm',
|
|
textareaId: 'id_content',
|
|
chatId: {{ chat.id }},
|
|
uploadUrl: "{% url 'api:v1:upload_message' %}",
|
|
editUrlTemplate: "/api/v1/communications/messages/{id}/edit/"
|
|
});
|
|
|
|
// ========== MARK READ ==========
|
|
const markReadApi = initChatMarkRead({
|
|
chatId: {{ chat.id }},
|
|
meId: {{ user.id|default:"0" }},
|
|
scrollContainerId: 'chatScroll',
|
|
textareaId: 'id_content',
|
|
formId: 'chatForm',
|
|
scrollBtnId: 'scrollBtn',
|
|
markReadUrl: "{% url 'communications:chat_mark_read' chat.pk %}",
|
|
initialLastReadTs: {{ chat.last_read_timestamp|default:"null" }}
|
|
});
|
|
|
|
// ========== COMPOSER ==========
|
|
console.log('[ChatDetailScripts] Initializing Composer...');
|
|
const composer = initChatComposer({
|
|
chatId: {{ chat.id }},
|
|
formId: 'chatForm',
|
|
textareaId: 'id_content',
|
|
uploadUrl: "{% url 'api:v1:upload_message' %}",
|
|
userWs: userWs
|
|
});
|
|
console.log('[ChatDetailScripts] Composer initialized:', composer);
|
|
|
|
// ========== HISTORY LOADER ==========
|
|
const historyLoader = initChatHistoryLoader({
|
|
chatId: {{ chat.id }},
|
|
scrollContainerId: 'chatScroll',
|
|
fetchUrl: "{% url 'api:v1:chat_messages' chat.pk %}",
|
|
avatarMap: avatarMap.getAll(),
|
|
meId: {{ user.id }}
|
|
});
|
|
|
|
// Расширяем userWebSocket chat-специфичной конфигурацией
|
|
if (userWs.configure) {
|
|
userWs.configure({
|
|
scrollContainerId: 'chatScroll',
|
|
formId: 'chatForm',
|
|
textareaId: 'id_content',
|
|
typingIndicatorId: 'typing',
|
|
avatarMap: avatarMap.getAll(),
|
|
markReadApi: markReadApi
|
|
});
|
|
}
|
|
|
|
// Открываем чат в WebSocket
|
|
if (userWs.openChat) {
|
|
userWs.openChat({{ chat.id }}, false);
|
|
}
|
|
|
|
// Экспортируем API
|
|
window.chatComposer = composer;
|
|
window.chatHistoryLoader = historyLoader;
|
|
window.markReadApi = markReadApi;
|
|
window.chatFormManager = formManager;
|
|
});
|
|
</script>
|
|
|
|
{# UI Components #}
|
|
<script type="module" src="{% static 'js/chat-detail-enhanced.js' %}"></script>
|