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

Update chat.js

Browse files
Files changed (1) hide show
  1. static/js/ui/chat.js +20 -15
static/js/ui/chat.js CHANGED
@@ -361,21 +361,26 @@ export async function addMessageToUI(message, index, options = {}, existingEleme
361
 
362
  let finalElement = existingElement;
363
 
364
- // *** منطق جدید: پاک کردن دکمه‌های پیام قبلی ***
365
- // اگر این پیام جدید، "آخرین" پیام کاربر یا مدل است، دکمه‌های پیام‌های قبلی همین نقش را حذف کن
366
- if (!existingElement && (isLastUser || isLastModel)) {
367
- const roleClass = isUser ? 'user' : 'model';
368
- const allMessagesOfRole = dom.chatWindow.querySelectorAll(`.message-entry.${roleClass}`);
369
- if (allMessagesOfRole.length > 0) {
370
- const lastMsgElement = allMessagesOfRole[allMessagesOfRole.length - 1];
371
- const lastMsgIndex = parseInt(lastMsgElement.dataset.index, 10);
372
- const activeChat = state.getActiveChat();
373
-
374
- // مطمئن شویم پیام معتبر است
375
- if (activeChat && activeChat.messages[lastMsgIndex]) {
376
- // بروزرسانی پیام قبلی با flagهای false برای حذف دکمه‌ها
377
- updateMessageActions(lastMsgElement, activeChat.messages[lastMsgIndex], false, false);
378
- }
 
 
 
 
 
379
  }
380
  }
381
 
 
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