:gem: [Feature] ChatHistoryStorer: render sidebar items
Browse files- index.html +1 -11
- networks/chat_history_storer.js +23 -3
index.html
CHANGED
@@ -34,17 +34,7 @@
|
|
34 |
</button>
|
35 |
</div>
|
36 |
<div class="offcanvas-body">
|
37 |
-
|
38 |
-
<input class="form-control" type="search" placeholder="Search chats">
|
39 |
-
<button class="btn btn-success" type="submit">Search</button>
|
40 |
-
</form> -->
|
41 |
-
<ul class="navbar-nav justify-content-end flex-grow-1">
|
42 |
-
<li class="nav-item">
|
43 |
-
<a class="nav-link active" href="#chat-session-example-1">Chat-Session-Example-1</a>
|
44 |
-
</li>
|
45 |
-
<li class="nav-item">
|
46 |
-
<a class="nav-link" href="#chat-session-example-2">Chat-Session-Example-2</a>
|
47 |
-
</li>
|
48 |
</ul>
|
49 |
</div>
|
50 |
</div>
|
|
|
34 |
</button>
|
35 |
</div>
|
36 |
<div class="offcanvas-body">
|
37 |
+
<ul id="chat-history-sidebar-items" class="navbar-nav justify-content-end flex-grow-1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
</ul>
|
39 |
</div>
|
40 |
</div>
|
networks/chat_history_storer.js
CHANGED
@@ -1,20 +1,38 @@
|
|
1 |
class ChatHistoryStorer {
|
2 |
constructor() {
|
3 |
this.init_database();
|
|
|
4 |
}
|
5 |
init_database() {
|
6 |
this.db = new Dexie("chat_history");
|
7 |
this.db.version(1).stores({
|
8 |
-
chat_history: "index, html, saved_datetime"
|
9 |
});
|
10 |
this.db.chat_history.count((count) => {
|
11 |
console.log(`${count} records loaded from chat_history.`);
|
12 |
});
|
13 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
get_current_datetime_string() {
|
15 |
-
return moment().format("YYYY-MM-DD_HH
|
16 |
}
|
17 |
-
|
18 |
get_chat_container_html() {
|
19 |
let messagers_container = $("#messagers-container");
|
20 |
if (messagers_container.children().length > 0) {
|
@@ -39,9 +57,11 @@ class ChatHistoryStorer {
|
|
39 |
let chat_saved_datetime = this.get_current_datetime_string();
|
40 |
this.db.chat_history.put({
|
41 |
index: chat_index,
|
|
|
42 |
html: chat_container_html,
|
43 |
saved_datetime: chat_saved_datetime,
|
44 |
});
|
|
|
45 |
console.log(
|
46 |
`${messagers_container.children().length} messages saved at ${chat_saved_datetime}.`
|
47 |
);
|
|
|
1 |
class ChatHistoryStorer {
|
2 |
constructor() {
|
3 |
this.init_database();
|
4 |
+
this.render_chat_history_sidebar_items();
|
5 |
}
|
6 |
init_database() {
|
7 |
this.db = new Dexie("chat_history");
|
8 |
this.db.version(1).stores({
|
9 |
+
chat_history: "index, display_title, html, saved_datetime"
|
10 |
});
|
11 |
this.db.chat_history.count((count) => {
|
12 |
console.log(`${count} records loaded from chat_history.`);
|
13 |
});
|
14 |
}
|
15 |
+
clear_database() {
|
16 |
+
this.db.chat_history.clear();
|
17 |
+
this.render_chat_history_sidebar_items();
|
18 |
+
console.log("chat_history cleared.");
|
19 |
+
}
|
20 |
+
render_chat_history_sidebar_items() {
|
21 |
+
let chat_history_sidebar_items = $("#chat-history-sidebar-items");
|
22 |
+
let chat_history = this.db.chat_history;
|
23 |
+
chat_history_sidebar_items.empty();
|
24 |
+
chat_history.each((chat_history_item) => {
|
25 |
+
let chat_history_item_html = `
|
26 |
+
<li class="nav-item">
|
27 |
+
<a class="nav-link" href="#${chat_history_item.index}">${chat_history_item.display_title}</a>
|
28 |
+
</li>
|
29 |
+
`;
|
30 |
+
chat_history_sidebar_items.append(chat_history_item_html);
|
31 |
+
});
|
32 |
+
}
|
33 |
get_current_datetime_string() {
|
34 |
+
return moment().format("YYYY-MM-DD_HH-mm-ss.SSS");
|
35 |
}
|
|
|
36 |
get_chat_container_html() {
|
37 |
let messagers_container = $("#messagers-container");
|
38 |
if (messagers_container.children().length > 0) {
|
|
|
57 |
let chat_saved_datetime = this.get_current_datetime_string();
|
58 |
this.db.chat_history.put({
|
59 |
index: chat_index,
|
60 |
+
display_title: chat_index,
|
61 |
html: chat_container_html,
|
62 |
saved_datetime: chat_saved_datetime,
|
63 |
});
|
64 |
+
this.render_chat_history_sidebar_items();
|
65 |
console.log(
|
66 |
`${messagers_container.children().length} messages saved at ${chat_saved_datetime}.`
|
67 |
);
|