diff --git a/static/assets/js/chat.js b/static/assets/js/chat.js index 7dd9ef5..0a270e6 100644 --- a/static/assets/js/chat.js +++ b/static/assets/js/chat.js @@ -28,6 +28,17 @@ var chatCurrentTeamId = null; // обрана «кімната» (кома var chatDmOtherUserId = {}; // channelId -> id співрозмовника (для аватара ЛС) var chatUnread = {}; // channelId -> к-сть непрочитаних var chatLastActivity = {}; // channelId -> час останнього поста (мс) +var chatShowArchived = false; // показувати закриті/архівні розмови + +function chatIsArchived(ch) { + return !!(ch && ch.delete_at && ch.delete_at > 0); +} + +function chatToggleArchived(show) { + chatShowArchived = !!show; + chatRenderChannelList(); + chatRenderDmList(); +} function chatPanelOpen(id) { var panel = document.getElementById(id); @@ -81,6 +92,7 @@ function chatInit() { chatDmOtherUserId = {}; chatUnread = {}; chatLastActivity = {}; + chatShowArchived = false; chatLoadTeams().then(chatLoadChannels).then(chatOpenPendingDm); chatConnectSocket(); @@ -241,7 +253,8 @@ function chatByRecent(a, b) { } function chatLoadChannels() { - return chatApiFetch('/users/me/channels').then(function (channels) { + // include_deleted=true — щоб мати закриті/архівні розмови (ховаємо їх за галочкою). + return chatApiFetch('/users/me/channels?include_deleted=true').then(function (channels) { chatChannels = channels .filter(function (ch) { return ch.type === 'O' || ch.type === 'P'; }) .sort(chatByRecent); @@ -326,6 +339,16 @@ function chatResolveDmLabel(channel) { if (otherId) chatApplyAvatar(avEl, otherId); // фото — лише для особистих (не групових) } if (chatCurrentChannelId === channel.id) chatUpdateHeader(channel); + // Позначка «бот» у списку ЛС, якщо співрозмовник — бот (стало відомо після resolve). + if (otherId && chatUserIsBot[otherId] && !document.getElementById('chat-dm-bot-' + channel.id)) { + var row = document.getElementById('chat-channel-row-' + channel.id); + if (row) { + var b = chatBotBadge(); + b.id = 'chat-dm-bot-' + channel.id; + b.style.flexShrink = '0'; + row.appendChild(b); + } + } }).catch(function (e) { console.error(e); }); } @@ -334,7 +357,8 @@ function chatRenderChannelList() { if (!el) return; var list = chatChannels.filter(function (ch) { - return !chatCurrentTeamId || ch.team_id === chatCurrentTeamId; + return (!chatCurrentTeamId || ch.team_id === chatCurrentTeamId) + && (chatShowArchived || !chatIsArchived(ch)); }); if (!list.length) { @@ -354,19 +378,25 @@ function chatRenderDmList() { var el = document.getElementById('chat-dm-list'); if (!el) return; - if (!chatDmChannels.length) { + var list = chatDmChannels.filter(function (ch) { + return chatShowArchived || !chatIsArchived(ch); + }); + + if (!list.length) { el.innerHTML = '
Немає повідомлень
'; return; } el.innerHTML = ''; - chatDmChannels.forEach(function (ch) { + list.forEach(function (ch) { + var otherId = chatDmOtherUserId[ch.id]; + var isBot = ch.type === 'D' && otherId && chatUserIsBot[otherId]; var row = chatBuildChannelRow(ch.id, chatDmLabels[ch.id] || '…', - ch.type === 'G' ? 'Групова розмова' : '', {avatar: true}); + ch.type === 'G' ? 'Групова розмова' : '', {avatar: true, bot: isBot}); el.appendChild(row); // Якщо співрозмовник ЛС уже відомий — одразу показати його аватар. - if (ch.type === 'D' && chatDmOtherUserId[ch.id]) { - chatApplyAvatar(document.getElementById('chat-dm-avatar-' + ch.id), chatDmOtherUserId[ch.id]); + if (ch.type === 'D' && otherId) { + chatApplyAvatar(document.getElementById('chat-dm-avatar-' + ch.id), otherId); } }); } @@ -408,6 +438,13 @@ function chatBuildChannelRow(channelId, label, subLabel, opts) { row.appendChild(textCol); + if (opts.bot) { + var botMark = chatBotBadge(); + botMark.id = 'chat-dm-bot-' + channelId; + botMark.style.flexShrink = '0'; + row.appendChild(botMark); + } + var unread = chatUnread[channelId] || 0; if (unread > 0) { name.style.fontWeight = '700'; diff --git a/templates/pages/chat.html b/templates/pages/chat.html index 524c6a0..917d0ed 100644 --- a/templates/pages/chat.html +++ b/templates/pages/chat.html @@ -8,6 +8,17 @@ {% if chat_state == 'ready' %} {{ chat_config|json_script:"chat-config-data" }} {{ chat_colleagues|json_script:"chat-colleagues-data" }} + + +
+ + +
+
@@ -33,6 +44,12 @@
+
+ +
@@ -41,15 +58,6 @@ Оберіть канал зліва
-
- - -
-