Keldos commited on
Commit
9983c9f
·
1 Parent(s): 785acc6

fix: 修复chatbot内容变化后头像留存问题

Browse files
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -253,6 +253,7 @@ function clearChatbot() {
253
  function chatbotContentChanged(attempt = 1) {
254
  for (var i = 0; i < attempt; i++) {
255
  setTimeout(() => {
 
256
  saveHistoryHtml();
257
  disableSendBtn();
258
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.user').forEach((userElement) => {addAvatars(userElement, 'user')});
 
253
  function chatbotContentChanged(attempt = 1) {
254
  for (var i = 0; i < attempt; i++) {
255
  setTimeout(() => {
256
+ clearMessageRows();
257
  saveHistoryHtml();
258
  disableSendBtn();
259
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.user').forEach((userElement) => {addAvatars(userElement, 'user')});
web_assets/javascript/avatar.js CHANGED
@@ -1,5 +1,8 @@
1
 
2
  function addAvatars(messageElement, role='user'||'bot') {
 
 
 
3
  if (messageElement.classList.contains('avatar-added') || messageElement.classList.contains('hide')) {
4
  return;
5
  }
@@ -43,6 +46,8 @@ function addAvatars(messageElement, role='user'||'bot') {
43
  function clearMessageRows() {
44
  const messageRows = chatbotWrap.querySelectorAll('.message-row');
45
  messageRows.forEach((messageRow) => {
46
- messageRow.parentNode.removeChild(messageRow);
 
 
47
  });
48
  }
 
1
 
2
  function addAvatars(messageElement, role='user'||'bot') {
3
+ if(messageElement.innerHTML === '') {
4
+ return;
5
+ }
6
  if (messageElement.classList.contains('avatar-added') || messageElement.classList.contains('hide')) {
7
  return;
8
  }
 
46
  function clearMessageRows() {
47
  const messageRows = chatbotWrap.querySelectorAll('.message-row');
48
  messageRows.forEach((messageRow) => {
49
+ if (messageRow.innerText === '') {
50
+ messageRow.parentNode.removeChild(messageRow);
51
+ }
52
  });
53
  }