Чат: закрытые ЛС прячем по настройкам Mattermost, а не по delete_at
ЛС/групповые в Mattermost не архивируются (delete_at=0) — «закрытие» это пользовательская preference (direct_channel_show/group_channel_show = "false"). Тянем /users/me/preferences и скрываем именно закрытые пользователем разговоры по умолчанию; галочка «Показувати закриті розмови» их показывает. Архивные каналы (delete_at>0) по-прежнему учитываются. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -29,11 +29,43 @@ var chatDmOtherUserId = {}; // channelId -> id співрозмовник
|
||||
var chatUnread = {}; // channelId -> к-сть непрочитаних
|
||||
var chatLastActivity = {}; // channelId -> час останнього поста (мс)
|
||||
var chatShowArchived = false; // показувати закриті/архівні розмови
|
||||
var chatPrefDirectShow = {}; // otherUserId -> "true"/"false" (видимість ЛС)
|
||||
var chatPrefGroupShow = {}; // channelId -> "true"/"false" (видимість групового)
|
||||
|
||||
function chatIsArchived(ch) {
|
||||
return !!(ch && ch.delete_at && ch.delete_at > 0);
|
||||
}
|
||||
|
||||
// Співрозмовник у ЛС (навіть до resolve — з імені каналу user1__user2).
|
||||
function chatDmOther(ch) {
|
||||
if (!ch || ch.type !== 'D') return null;
|
||||
if (chatDmOtherUserId[ch.id]) return chatDmOtherUserId[ch.id];
|
||||
if (!ch.name || !chatConfig) return null;
|
||||
return ch.name.split('__').filter(function (id) { return id !== chatConfig.currentUserId; })[0] || null;
|
||||
}
|
||||
|
||||
// «Закрита» розмова = архівний канал АБО ЛС/груповий, який користувач сховав у
|
||||
// Mattermost (preference *_show = "false"). Саме тому вони не видно в клієнті MM.
|
||||
function chatIsClosed(ch) {
|
||||
if (chatIsArchived(ch)) return true;
|
||||
if (ch.type === 'D') {
|
||||
var other = chatDmOther(ch);
|
||||
return !!other && chatPrefDirectShow[other] === 'false';
|
||||
}
|
||||
if (ch.type === 'G') return chatPrefGroupShow[ch.id] === 'false';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Налаштування видимості ЛС/групових із Mattermost.
|
||||
function chatLoadPreferences() {
|
||||
return chatApiFetch('/users/me/preferences').then(function (prefs) {
|
||||
(prefs || []).forEach(function (p) {
|
||||
if (p.category === 'direct_channel_show') chatPrefDirectShow[p.name] = p.value;
|
||||
else if (p.category === 'group_channel_show') chatPrefGroupShow[p.name] = p.value;
|
||||
});
|
||||
}).catch(function () { /* без префів показуємо все */ });
|
||||
}
|
||||
|
||||
function chatToggleArchived(show) {
|
||||
chatShowArchived = !!show;
|
||||
chatRenderChannelList();
|
||||
@@ -93,8 +125,10 @@ function chatInit() {
|
||||
chatUnread = {};
|
||||
chatLastActivity = {};
|
||||
chatShowArchived = false;
|
||||
chatPrefDirectShow = {};
|
||||
chatPrefGroupShow = {};
|
||||
|
||||
chatLoadTeams().then(chatLoadChannels).then(chatOpenPendingDm);
|
||||
chatLoadTeams().then(chatLoadPreferences).then(chatLoadChannels).then(chatOpenPendingDm);
|
||||
chatConnectSocket();
|
||||
|
||||
// Дозвіл на браузерні сповіщення про нові повідомлення (не обов'язково).
|
||||
@@ -244,9 +278,9 @@ function chatChannelActivity(ch) {
|
||||
}
|
||||
|
||||
function chatByRecent(a, b) {
|
||||
var aArch = !!(a.delete_at && a.delete_at > 0);
|
||||
var bArch = !!(b.delete_at && b.delete_at > 0);
|
||||
if (aArch !== bArch) return aArch ? 1 : -1; // архівні — завжди вниз
|
||||
var aArch = chatIsClosed(a);
|
||||
var bArch = chatIsClosed(b);
|
||||
if (aArch !== bArch) return aArch ? 1 : -1; // закриті/архівні — завжди вниз
|
||||
var diff = chatChannelActivity(b) - chatChannelActivity(a);
|
||||
if (diff !== 0) return diff; // найсвіжіші зверху
|
||||
return (a.display_name || '').localeCompare(b.display_name || '');
|
||||
@@ -278,9 +312,8 @@ function chatAutoSelectRecent() {
|
||||
// повідомлення (а не порожній екран). Лише якщо користувач ще нічого не обрав.
|
||||
if (chatCurrentChannelId) return;
|
||||
var candidates = chatChannels.filter(function (ch) {
|
||||
return (!chatCurrentTeamId || ch.team_id === chatCurrentTeamId)
|
||||
&& !(ch.delete_at && ch.delete_at > 0);
|
||||
}).concat(chatDmChannels.filter(function (ch) { return !(ch.delete_at && ch.delete_at > 0); }));
|
||||
return (!chatCurrentTeamId || ch.team_id === chatCurrentTeamId) && !chatIsClosed(ch);
|
||||
}).concat(chatDmChannels.filter(function (ch) { return !chatIsClosed(ch); }));
|
||||
if (!candidates.length) return;
|
||||
var best = candidates.reduce(function (a, b) {
|
||||
return chatChannelActivity(b) > chatChannelActivity(a) ? b : a;
|
||||
@@ -358,7 +391,7 @@ function chatRenderChannelList() {
|
||||
|
||||
var list = chatChannels.filter(function (ch) {
|
||||
return (!chatCurrentTeamId || ch.team_id === chatCurrentTeamId)
|
||||
&& (chatShowArchived || !chatIsArchived(ch));
|
||||
&& (chatShowArchived || !chatIsClosed(ch));
|
||||
});
|
||||
|
||||
if (!list.length) {
|
||||
@@ -379,7 +412,7 @@ function chatRenderDmList() {
|
||||
if (!el) return;
|
||||
|
||||
var list = chatDmChannels.filter(function (ch) {
|
||||
return chatShowArchived || !chatIsArchived(ch);
|
||||
return chatShowArchived || !chatIsClosed(ch);
|
||||
});
|
||||
|
||||
if (!list.length) {
|
||||
|
||||
Reference in New Issue
Block a user