Чат: метка «бот» у сообщений от ботов
Захватываем is_bot при резолве пользователей (/users/ids), рядом с именем отправителя показываем компактную подпись «бот». Также распознаём вебхуки (props.from_bot / from_webhook). Свои сообщения и обычных юзеров не помечаем. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ var chatDmChannels = [];
|
||||
var chatDmLabels = {};
|
||||
var chatTeamsById = {};
|
||||
var chatUserNames = {};
|
||||
var chatUserIsBot = {}; // userId -> чи це бот (Mattermost is_bot)
|
||||
var chatPostsById = {};
|
||||
var chatCurrentChannelId = null;
|
||||
var chatCurrentThreadRootId = null;
|
||||
@@ -67,6 +68,7 @@ function chatInit() {
|
||||
chatDmLabels = {};
|
||||
chatTeamsById = {};
|
||||
chatUserNames = {};
|
||||
chatUserIsBot = {};
|
||||
chatPostsById = {};
|
||||
chatCurrentChannelId = null;
|
||||
chatCurrentThreadRootId = null;
|
||||
@@ -172,6 +174,7 @@ function chatResolveUserIds(ids) {
|
||||
chatUserNames[u.id] = (u.first_name || u.last_name)
|
||||
? (u.first_name + ' ' + u.last_name).trim()
|
||||
: u.username;
|
||||
chatUserIsBot[u.id] = !!u.is_bot;
|
||||
});
|
||||
}).catch(function (e) { console.error(e); });
|
||||
}
|
||||
@@ -618,6 +621,19 @@ function chatRenderSearchResults(posts) {
|
||||
});
|
||||
}
|
||||
|
||||
function chatPostIsBot(post) {
|
||||
if (chatUserIsBot[post.user_id]) return true;
|
||||
var p = post.props || {};
|
||||
return p.from_bot === 'true' || p.from_webhook === 'true';
|
||||
}
|
||||
|
||||
function chatBotBadge() {
|
||||
var b = document.createElement('span');
|
||||
b.textContent = 'бот';
|
||||
b.style.cssText = 'font-size:0.5625rem; font-weight:700; letter-spacing:0.03em; text-transform:uppercase; color:var(--color-muted-foreground); background:var(--color-muted); border:1px solid var(--color-border); border-radius:0.25rem; padding:0.0625rem 0.25rem; line-height:1.2;';
|
||||
return b;
|
||||
}
|
||||
|
||||
function chatBuildMessageEl(post, context) {
|
||||
var isMine = post.user_id === chatConfig.currentUserId;
|
||||
var wrap = document.createElement('div');
|
||||
@@ -643,6 +659,7 @@ function chatBuildMessageEl(post, context) {
|
||||
timeEl.style.cssText = 'font-size:0.6875rem; color:var(--color-muted-foreground);';
|
||||
timeEl.textContent = post.create_at ? new Date(post.create_at).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) : '';
|
||||
meta.appendChild(nameEl);
|
||||
if (!isMine && chatPostIsBot(post)) meta.appendChild(chatBotBadge());
|
||||
meta.appendChild(timeEl);
|
||||
body.appendChild(meta);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user