Keldos commited on
Commit
21d7bfc
·
1 Parent(s): 38abe30

fix: 修复远程服务删除消息时可能不能生成新按钮的问题

Browse files
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -57,7 +57,7 @@ function addInit() {
57
  }
58
  }
59
 
60
- chatbotObserver.observe(chatbotIndicator, { attributes: true });
61
  chatListObserver.observe(chatListIndicator, { attributes: true });
62
  setUploader();
63
 
@@ -340,19 +340,32 @@ function clearChatbot() {
340
  // clearMessageRows();
341
  }
342
 
343
- function chatbotContentChanged(attempt = 1) {
344
  for (var i = 0; i < attempt; i++) {
345
  setTimeout(() => {
346
  // clearMessageRows();
347
  saveHistoryHtml();
348
  disableSendBtn();
349
- // gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.user').forEach((userElement) => {addAvatars(userElement, 'user')});
350
- // gradioApp().querySelectorAll('#chuanhu-chatbot > .wrapper > .wrap > .message-wrap .message-row.bot-row').forEach(addChuanhuButton);
351
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
352
- if (chatbotIndicator.classList.contains('hide')) {
 
353
  setLatestMessage();
354
  setChatList();
355
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  }, i === 0 ? 0 : 200);
357
  }
358
  // 理论上是不需要多次尝试执行的,可惜gradio的bug导致message可能没有渲染完毕,所以尝试500ms后再次执行
@@ -364,6 +377,10 @@ var chatbotObserver = new MutationObserver(() => {
364
  // setLatestMessage();
365
  chatbotContentChanged(2);
366
  }
 
 
 
 
367
  });
368
 
369
  var chatListObserver = new MutationObserver(() => {
 
57
  }
58
  }
59
 
60
+ chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
61
  chatListObserver.observe(chatListIndicator, { attributes: true });
62
  setUploader();
63
 
 
340
  // clearMessageRows();
341
  }
342
 
343
+ function chatbotContentChanged(attempt = 1, force = false) {
344
  for (var i = 0; i < attempt; i++) {
345
  setTimeout(() => {
346
  // clearMessageRows();
347
  saveHistoryHtml();
348
  disableSendBtn();
349
+
 
350
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
351
+
352
+ if (chatbotIndicator.classList.contains('hide')) { // generation finished
353
  setLatestMessage();
354
  setChatList();
355
  }
356
+
357
+ if (!chatbotIndicator.classList.contains('translucent')) { // message deleted
358
+ var checkLatestAdded = setInterval(() => {
359
+ var latestMessageNow = gradioApp().querySelector('#chuanhu-chatbot > .wrapper > .wrap > .message-wrap .message.bot.latest');
360
+ if (latestMessageNow && latestMessageNow.querySelector('.message-btn-row')) {
361
+ clearInterval(checkLatestAdded);
362
+ } else {
363
+ setLatestMessage();
364
+ }
365
+ }, 200);
366
+ }
367
+
368
+
369
  }, i === 0 ? 0 : 200);
370
  }
371
  // 理论上是不需要多次尝试执行的,可惜gradio的bug导致message可能没有渲染完毕,所以尝试500ms后再次执行
 
377
  // setLatestMessage();
378
  chatbotContentChanged(2);
379
  }
380
+ if (!chatbotIndicator.classList.contains('translucent')) {
381
+ chatbotContentChanged(2);
382
+ }
383
+
384
  });
385
 
386
  var chatListObserver = new MutationObserver(() => {
web_assets/javascript/message-button.js CHANGED
@@ -144,7 +144,6 @@ function addLatestMessageButtons(botElement) {
144
  var gradioDelLastBtn = gradioApp().querySelector('#gr-dellast-btn');
145
  deleteButton.addEventListener('click', () => {
146
  gradioDelLastBtn.click();
147
- chatbotContentChanged(2);
148
  });
149
 
150
  messageBtnRowLeading.appendChild(regenerateButton);
 
144
  var gradioDelLastBtn = gradioApp().querySelector('#gr-dellast-btn');
145
  deleteButton.addEventListener('click', () => {
146
  gradioDelLastBtn.click();
 
147
  });
148
 
149
  messageBtnRowLeading.appendChild(regenerateButton);