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

Update chat.js

Browse files
Files changed (1) hide show
  1. static/js/ui/chat.js +19 -3
static/js/ui/chat.js CHANGED
@@ -4,7 +4,7 @@
4
  import * as state from '../state.js';
5
  import * as db from '../db.js';
6
  import { dom } from './dom.js';
7
- import { toggleHtmlPreviewModal, toggleSidebar, showHistoryMenu, showMessageMenu } from './modals.js'; // *** تغییر مهم: ایمپورت مستقیم ***
8
  import { createDeepThinkPanel, createReasoningPanel, hideDeepThinkPanel, hideReasoningPanel, updateDeepThinkPanel, updateReasoningPanel } from './tools.js';
9
 
10
  export const PREMIUM_URL = '#/nav/online/news/getSingle/1149636/eyJpdiI6InZSVUdlLzBlR0FzOHZJdXFZeWhER0E9PSIsInZhbHVlIjoiWFhqRXBLc29vSFpHdk9nYmRjZGVuWHRHRHVSZHRlTG1BUENLaE5mNXBNVVRGWFg3ZWN0djJ5K1dIY1RqTHJGaCIsIm1hYyI6IjIzYzFlZTMwYmVmMTdkYjQ0YTQ4YWMxNmFhN2RmNWQ2OTc1NDIyNGVlZGI3ZjJjMjhkNmQxNjM4MDFlZTIxNmUiLCJ0YWciOiIifQ==/20934991';
@@ -184,7 +184,6 @@ export function setupCodeBlockActions(container) {
184
  });
185
  }
186
 
187
- // *** تابع رندر لیست تاریخچه (اصلاح شده برای عملکرد صحیح دکمه منو) ***
188
  export function renderHistoryList() {
189
  dom.historyList.innerHTML = '';
190
  const chatsToDisplay = state.chatSessions.filter(session => session.messages.length > 0 || session.id === state.activeChatId);
@@ -209,7 +208,6 @@ export function renderHistoryList() {
209
  menuButton.className = 'history-item-button p-2 ml-1 text-slate-500 dark:text-slate-400 hover:bg-slate-200/80 dark:hover:bg-slate-700/80 rounded-full flex-shrink-0';
210
  menuButton.innerHTML = '<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM12.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM18.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0z" /></svg>';
211
 
212
- // *** تغییر اصلی: فراخوانی مستقیم تابع منو ***
213
  menuButton.onclick = (e) => {
214
  e.preventDefault();
215
  e.stopPropagation();
@@ -363,6 +361,24 @@ export async function addMessageToUI(message, index, options = {}, existingEleme
363
 
364
  let finalElement = existingElement;
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  if (!finalElement) {
367
  finalElement = document.createElement('div');
368
  const roleClass = isUser ? 'user' : 'model';
 
4
  import * as state from '../state.js';
5
  import * as db from '../db.js';
6
  import { dom } from './dom.js';
7
+ import { toggleHtmlPreviewModal, toggleSidebar, showHistoryMenu, showMessageMenu } from './modals.js';
8
  import { createDeepThinkPanel, createReasoningPanel, hideDeepThinkPanel, hideReasoningPanel, updateDeepThinkPanel, updateReasoningPanel } from './tools.js';
9
 
10
  export const PREMIUM_URL = '#/nav/online/news/getSingle/1149636/eyJpdiI6InZSVUdlLzBlR0FzOHZJdXFZeWhER0E9PSIsInZhbHVlIjoiWFhqRXBLc29vSFpHdk9nYmRjZGVuWHRHRHVSZHRlTG1BUENLaE5mNXBNVVRGWFg3ZWN0djJ5K1dIY1RqTHJGaCIsIm1hYyI6IjIzYzFlZTMwYmVmMTdkYjQ0YTQ4YWMxNmFhN2RmNWQ2OTc1NDIyNGVlZGI3ZjJjMjhkNmQxNjM4MDFlZTIxNmUiLCJ0YWciOiIifQ==/20934991';
 
184
  });
185
  }
186
 
 
187
  export function renderHistoryList() {
188
  dom.historyList.innerHTML = '';
189
  const chatsToDisplay = state.chatSessions.filter(session => session.messages.length > 0 || session.id === state.activeChatId);
 
208
  menuButton.className = 'history-item-button p-2 ml-1 text-slate-500 dark:text-slate-400 hover:bg-slate-200/80 dark:hover:bg-slate-700/80 rounded-full flex-shrink-0';
209
  menuButton.innerHTML = '<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM12.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM18.75 12a.75.75 0 11-1.5 0 .75.75 0 011.5 0z" /></svg>';
210
 
 
211
  menuButton.onclick = (e) => {
212
  e.preventDefault();
213
  e.stopPropagation();
 
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
+
382
  if (!finalElement) {
383
  finalElement = document.createElement('div');
384
  const roleClass = isUser ? 'user' : 'model';