Keldos commited on
Commit
1a233c9
1 Parent(s): 147f60b

WIP BREAKING: 只有未登录&hide_history_when_...时使用只读历史记录

Browse files
ChuanhuChatbot.py CHANGED
@@ -44,7 +44,6 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
44
  status_display = gr.Markdown(get_geoip(), elem_id="status-display")
45
  with gr.Row(elem_id="float-display"):
46
  user_info = gr.Markdown(value="getting user info...", elem_id="user-info")
47
- config_info = gr.HTML(get_html("config_info.html").format(), visible=False, elem_id="config-info")
48
  update_info = gr.HTML(get_html("update.html").format(
49
  current_version=repo_tag_html(),
50
  version_time=version_time(),
@@ -403,6 +402,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
403
 
404
  with gr.Box(elem_id="web-config", visible=False):
405
  gr.HTML(get_html('web_config.html').format(
 
406
  forView_i18n=i18n("仅供查看"),
407
  deleteConfirm_i18n_pref=i18n("你真的要删除 "),
408
  deleteConfirm_i18n_suff=i18n(" 吗?"),
 
44
  status_display = gr.Markdown(get_geoip(), elem_id="status-display")
45
  with gr.Row(elem_id="float-display"):
46
  user_info = gr.Markdown(value="getting user info...", elem_id="user-info")
 
47
  update_info = gr.HTML(get_html("update.html").format(
48
  current_version=repo_tag_html(),
49
  version_time=version_time(),
 
402
 
403
  with gr.Box(elem_id="web-config", visible=False):
404
  gr.HTML(get_html('web_config.html').format(
405
+ hideHistoryWhenNotLoggedIn_config=hide_history_when_not_logged_in,
406
  forView_i18n=i18n("仅供查看"),
407
  deleteConfirm_i18n_pref=i18n("你真的要删除 "),
408
  deleteConfirm_i18n_suff=i18n(" 吗?"),
web_assets/html/web_config.html CHANGED
@@ -1,4 +1,8 @@
1
  <div aria-label="config-div" style="display:none;">
 
 
 
 
2
  <!-- i18n config -->
3
  <div id="config_i18n">
4
  <span id="forView_i18n">{forView_i18n}</span>
 
1
  <div aria-label="config-div" style="display:none;">
2
+ <!-- app config -->
3
+ <div id="app_config">
4
+ <span id="hideHistoryWhenNotLoggedIn_config">{hideHistoryWhenNotLoggedIn_config}</span>
5
+ </div>
6
  <!-- i18n config -->
7
  <div id="config_i18n">
8
  <span id="forView_i18n">{forView_i18n}</span>
web_assets/javascript/chat-history.js CHANGED
@@ -20,10 +20,13 @@ function loadHistoryHtml() {
20
  return; // no history, do nothing
21
  }
22
  userLogged = localStorage.getItem('userLogged');
23
- if (userLogged){
 
24
  historyLoaded = true;
25
- return; // logged in, do nothing
26
  }
 
 
27
  if (!historyLoaded) {
28
  // preprocess, gradio buttons in history lost their event listeners
29
  var gradioCopyButtons = tempDiv.querySelectorAll('button.copy_code_button');
@@ -51,7 +54,7 @@ function loadHistoryHtml() {
51
  // fakeHistory.innerHTML = historyHtml;
52
  // chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
53
  historyLoaded = true;
54
- console.log("History Loaded");
55
  loadhistorytime += 1; // for debugging
56
  } else {
57
  historyLoaded = false;
 
20
  return; // no history, do nothing
21
  }
22
  userLogged = localStorage.getItem('userLogged');
23
+ hideHistoryWhenNotLoggedIn = gradioApp().querySelector('#hideHistoryWhenNotLoggedIn_config').innerText === "True";
24
+ if (userLogged || (!userLogged && !hideHistoryWhenNotLoggedIn)){
25
  historyLoaded = true;
26
+ return; // logged in, do nothing. OR, not logged in but not hide history list, do nothing.
27
  }
28
+
29
+ // 只有用户未登录,还隐藏历史记录列表时,才选用只读历史记录
30
  if (!historyLoaded) {
31
  // preprocess, gradio buttons in history lost their event listeners
32
  var gradioCopyButtons = tempDiv.querySelectorAll('button.copy_code_button');
 
54
  // fakeHistory.innerHTML = historyHtml;
55
  // chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
56
  historyLoaded = true;
57
+ // console.log("History Loaded");
58
  loadhistorytime += 1; // for debugging
59
  } else {
60
  historyLoaded = false;