Fix missing names in chat
This commit is contained in:
1 parent
bace4b7136
commit
3e06a59f85
1 file changed
+24
-2
@@ -15,6 +15,7 @@
|
||||
});
|
||||
|
||||
let chatId = null;
|
||||
let agentNames = {};
|
||||
|
||||
// Chat State
|
||||
const chat = ref({});
|
||||
@@ -42,11 +43,21 @@
|
||||
|
||||
async function loadChatState (newId) {
|
||||
chatId = parseInt(newId);
|
||||
if (chatId == null) {
|
||||
if (chatId == null || isNaN(chatId)) {
|
||||
console.error("Invalid chat id", chatId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create an agent name dictionary
|
||||
const _agents = await backend.getAgents();
|
||||
for (let agent of _agents) {
|
||||
agentNames[agent.id] = agent.name;
|
||||
}
|
||||
|
||||
backend.getChat(chatId).then(info => {
|
||||
chat.value = Object.assign({}, info);
|
||||
});
|
||||
|
||||
unsubscribeChat = backend.onChatMessages(chatId, it => {
|
||||
if (it.sender == 'user') return;
|
||||
|
||||
@@ -180,6 +191,15 @@
|
||||
let entries = [];
|
||||
let threadGroups = {}; // Map<int, message[]>
|
||||
|
||||
function senderName (sender) {
|
||||
let isInt = !isNaN(parseInt(sender));
|
||||
if (isInt) {
|
||||
return agentNames[sender] || `<agent-${sender}>`;
|
||||
} else {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
||||
function addThreadHeader (threadId, group) {
|
||||
entries.push({
|
||||
type: 'thread-header',
|
||||
@@ -199,7 +219,9 @@
|
||||
}
|
||||
|
||||
// Second pass: Build the display list with correct ordering
|
||||
for (let message of messages) {
|
||||
for (let _msg of messages) {
|
||||
// New message object with updated name
|
||||
const message = Object.assign({}, _msg, {sender: senderName(_msg.sender)});
|
||||
|
||||
// Non-threaded messages and notes go directly to the entry list
|
||||
if (message.threadId == null || message.type == 'note') {
|
||||
|
||||
Reference in new issue
Block a user