Jan2000 commited on
Commit
e650d8e
·
unverified ·
1 Parent(s): 4b399f1

Update chat.js

Browse files
Files changed (1) hide show
  1. static/js/ui/chat.js +26 -18
static/js/ui/chat.js CHANGED
@@ -361,26 +361,34 @@ export async function addMessageToUI(message, index, options = {}, existingEleme
361
 
362
  let finalElement = existingElement;
363
 
364
- // *** منطق جدید و دقیق برای پاکسازی دکمه‌های پیام‌های قبلی ***
365
  if (!existingElement) {
366
- // 1. حذف دکمه ویرایش از آخرین پیام کاربر (اگر وجود دارد)
367
- const lastUserMsg = dom.chatWindow.querySelector('.message-entry.user:last-of-type');
368
- if (lastUserMsg) {
369
- const idx = parseInt(lastUserMsg.dataset.index, 10);
370
- const chat = state.getActiveChat();
371
- if(chat && chat.messages[idx]) {
372
- updateMessageActions(lastUserMsg, chat.messages[idx], false, false);
373
- }
374
- }
 
375
 
376
- // 2. حذف دکمه تلاش مجدد از آخرین پیام مدل (اگر وجود دارد)
377
- const lastModelMsg = dom.chatWindow.querySelector('.message-entry.model:last-of-type');
378
- if (lastModelMsg) {
379
- const idx = parseInt(lastModelMsg.dataset.index, 10);
380
- const chat = state.getActiveChat();
381
- if(chat && chat.messages[idx]) {
382
- updateMessageActions(lastModelMsg, chat.messages[idx], false, false);
383
- }
 
 
 
 
 
 
 
384
  }
385
  }
386
 
 
361
 
362
  let finalElement = existingElement;
363
 
364
+ // *** منطق جدید و دقیق برای پاکسازی دکمه‌ها ***
365
  if (!existingElement) {
366
+ const activeChat = state.getActiveChat();
367
+
368
+ if (isUser) {
369
+ // وقتی کاربر پیام جدید میده:
370
+ // 1. دکمه ویرایش از تمام پیام‌های قبلی کاربر حذف بشه
371
+ const prevUserMsgs = dom.chatWindow.querySelectorAll('.message-entry.user');
372
+ prevUserMsgs.forEach(el => {
373
+ const idx = parseInt(el.dataset.index, 10);
374
+ if (activeChat.messages[idx]) updateMessageActions(el, activeChat.messages[idx], false, false);
375
+ });
376
 
377
+ // 2. دکمه تلاش مجدد از تمام پیام‌های قبلی هوش مصنوعی حذف بشه (چون بحث ادامه پیدا کرده)
378
+ const prevModelMsgs = dom.chatWindow.querySelectorAll('.message-entry.model');
379
+ prevModelMsgs.forEach(el => {
380
+ const idx = parseInt(el.dataset.index, 10);
381
+ if (activeChat.messages[idx]) updateMessageActions(el, activeChat.messages[idx], false, false);
382
+ });
383
+ }
384
+ else {
385
+ // وقتی هوش مصنوعی پیام جدید میده:
386
+ // 1. دکمه تلاش مجدد از پیام‌های قبلی هوش مصنوعی حذف بشه
387
+ const prevModelMsgs = dom.chatWindow.querySelectorAll('.message-entry.model');
388
+ prevModelMsgs.forEach(el => {
389
+ const idx = parseInt(el.dataset.index, 10);
390
+ if (activeChat.messages[idx]) updateMessageActions(el, activeChat.messages[idx], false, false);
391
+ });
392
  }
393
  }
394