';
+ }
+
+ msg = msgItem['message'].replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(new RegExp("\n",'g'), "
'
+ + '
' + t_formatted + ' '
+
+ // Author to receiver
+ + '' + msgItem['author'] + ''
+ + ' ';
+
+ if (msgItem['repto'] != "" ) {
+ html += '' + msgItem['to'] + '
';
+ } else {
+ html += msgItem['to'] + '';
+ }
+
+ // Header
+ html += '
'
+ + ''
+ + '
'
+ + '
' + msg.autoLink()
+ + '
';
+
+ // Answers
+ html += '[' + total + ']';
+
+ // Msgid
+ html += '' + msgItem['msgid'] + '';
+
+ // End message
block
+ html += '
';
+
+ return html;
+}
diff --git a/js/script.js b/js/script.js
index 586e9f4..afa0f2e 100644
--- a/js/script.js
+++ b/js/script.js
@@ -163,7 +163,7 @@ function ajaxRequest(data) {
type:"POST",
data: data,
contentType: "application/json",
- success:function(messages){
+ success: function(messages) {
callback(messages);
$("#mes").html(html);
}
@@ -283,11 +283,23 @@ function searchRequest(data) {
})
}
+function answersRequest(msgid) {
+ $.ajax({
+ url:"https://dynamic.lessmore.pw/search",
+ type:"POST",
+ data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["msgid"], "query" :"' + msgid + '"}}, "size": 0 }',
+ contentType: "application/json",
+ success: function(messages){
+ answers[msgid] = messages["hits"]["total"];
+ }
+ })
+}
+
//show messages
function callbackHS(messages) {
var msgArray = messages["hits"]["hits"];
// console.log(msgArray);
-
+
for (hit in msgArray) {
hash = parseLocationHash();
var msgItem = msgArray[hit]['_source'];
@@ -343,11 +355,65 @@ function callbackHS(messages) {
}
}
+function threadMessage(msgItem) {
+ $.ajax({
+ url:"https://dynamic.lessmore.pw/search",
+ type:"POST",
+ data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["repto"], "query": "' + msgItem["_source"]["msgid"] + '"}}, "size": 0 }',
+ contentType: "application/json",
+ success: function(answer) {
+ total = 0;
+ total = answer["hits"]["total"];
+ msgItem["total"] = total;
+ threadsCallback(false, msgItem);
+ $("#mes").html(html);
+ }
+ })
+}
+
//show messages
-function callback(messages) {
+function threadsCallback(messages) {
+ var getAnswers = function(msgItem, callback) {
+ $.when(
+ $.ajax({
+ url:"https://dynamic.lessmore.pw/search",
+ type:"POST",
+ data: '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["repto"], "query": "' + msgItem["_source"]["msgid"] + '"}}, "size": 0 }',
+ contentType: "application/json",
+ success: function(answer) { callback(answer, msgItem); }
+ })).then(function(data) {
+ console.log(data);
+ })
+ };
+
+ var getTotal = function(answer, msgItem) {
+ var total = answer["hits"]["total"];
+ msg = makeThreadMessage(msgItem["_source"], total);
+ console.log(msgItem["_source"]["msgid"])
+ Cookies.set(msgItem["_source"]["msgid"], total);
+ };
+
var msgArray = messages["hits"]["hits"];
- // console.log(msgArray);
-
+ for (hit in msgArray) {
+ getAnswers(msgArray[hit], getTotal);
+ }
+
+ for (hit in msgArray) {
+ count = Cookies.get(msgArray[hit]["_source"]["msgid"]);
+ msg = makeThreadMessage(msgArray[hit]["_source"], count);
+ html += msg;
+ }
+}
+
+//show messages
+function callback(messages) {
+ var msgArray = messages["hits"]["hits"];
+
+ // if (checkViewMode() && !parseLocation().matched) {
+ // threadsCallback(messages);
+ // return;
+ // }
+
for (hit in msgArray) {
hash = parseLocationHash();
var msgItem = msgArray[hit]['_source'];
@@ -383,10 +449,10 @@ function callback(messages) {
+ '
'
+ '
' + msg.autoLink()
- + '
'
+ + '
';
// Msgid
- + '' + msgItem['msgid'] + '';
+ html += '' + msgItem['msgid'] + '';
// End message
block
html += '
';
diff --git a/js/threads.js b/js/threads.js
index 8220fd2..ac7159a 100644
--- a/js/threads.js
+++ b/js/threads.js
@@ -68,15 +68,10 @@ function proccessThreadRequest(data, msgid) {
})
}
-function answersRequest()
-
function proccessThread(msgid, callback) {
data = '{"sort": [ { "date": { "order": "asc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["repto"], "query" :"' + msgid + '"}}, "size": 100 }';
if (callback) {
for (hit in callback["hits"]["hits"]) {
- if (top_id == callback["hits"]["hits"][hit]["_source"]) {
- answersRequest(top_id);
- }
msg = callback["hits"]["hits"][hit]["_source"];
thread_html += makeMessageHTML(callback["hits"]["hits"][0]["_source"]);
proccessThread(msg["msgid"], false);
@@ -97,42 +92,4 @@ function parseLocation() {
}
}
-// Make message HTML
-function makeMessageHTML(msgItem) {
- var t = new Date(msgItem['date'] * 1000);
- // console.log(msgItem['date']);
- // console.log(t);
- var t_formatted = t.getFullYear() + "/" + (t.getMonth() + 1) + "/" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
-
- var msg = msgItem['message'].replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(new RegExp("\n",'g'), "
\n");
-
- var html = '
'
- + '
' + t_formatted + ' '
- // Author to receiver
- + '' + msgItem['author'] + ''
- + ' ';
-
- if (msgItem['repto'] != "" ) {
- html += '' + msgItem['to'] + '
';
- } else {
- html += msgItem['to'] + '';
- }
-
- // Header
- html += '
'
- + ''
- + '
'
- + '
' + msg.autoLink()
- + '
'
-
- // Msgid
- + '' + msgItem['msgid'] + '';
-
- // End message
block
- html += '
';
-
- return html
-}