Threads view

This commit is contained in:
Denis Zheleztsov 2018-01-02 12:07:59 +03:00
parent 2dc1c55a4c
commit 5234c5f9f9
3 changed files with 158 additions and 18 deletions

View File

@ -9,12 +9,16 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- <script src="js/jquery-1.8.min.js"></script> -->
<script src="js/multiple-select.js"></script>
<script src="js/threads.js"></script>
<script src="js/script.js"></script>
<script src="js/autolink.js"></Script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="threadView" id="thread"></div>
<div class="lessmore">
<a id="searchButton" href="javascript:void(0)" onclick="showSearch()"><i class="fa fa-search"></i></a>
<!-- <div class="logo"><a href="/" style="text-decoration: none; color: #c9c9c9;">dynamic | less</a></div> -->
@ -32,7 +36,7 @@
<!-- <form><select id="echoSelector" multiple size="5"></select></form> -->
<!-- <a href="/" id="logo" style="text-decoration: none; color: #c9c9c9;">dynamic | less</a> -->
</div>
<div class="content">
<div id="mes"></div>
</div>

View File

@ -256,14 +256,14 @@ function callbackHS(messages) {
+ ' <i class="fa fa-mail-forward"></i> ';
if (msgItem['repto'] != "" ) {
html += '<a href="/?' + msgItem['to'] + '">' + msgItem['to'] + '</a></p>';
html += '<a href="/?' + msgItem['repto'] + '">' + msgItem['to'] + '</a></p>';
} else {
html += msgItem['to'] + '</p>';
}
// Header
html += ' <p style="color:#0099cc;font: 1.5em Open Sans, sans-serif;">'
+ '<a class="headerLink" href="javascript:void(0)" onclick="requestBuildThread(\'' + msgItem['msgid'] + '\', true)">'
+ '<a class="headerLink" href="/?j=' + msgItem['msgid'] + '">'
+ msgItem['subg'] + '</a>'
+ ' <i class="fa fa-at"></i> <i><a class="headerLink" href="javascript:void(0)" onclick="requestTmpEcho(\'' + msgItem['echo'] + '\')">' + msgItem['echo']
+ '</a></i></p></p>'
@ -307,14 +307,14 @@ function callback(messages) {
+ ' <i class="fa fa-mail-forward"></i> ';
if (msgItem['repto'] != "" ) {
html += '<a href="/?' + msgItem['to'] + '">' + msgItem['to'] + '</a></p>';
html += '<a href="/?' + msgItem['repto'] + '">' + msgItem['to'] + '</a></p>';
} else {
html += msgItem['to'] + '</p>';
}
// Header
html += ' <p style="color:#0099cc;font: 1.5em Open Sans, sans-serif;">'
+ '<a class="headerLink" href="javascript:void(0)" onclick="requestBuildThread(\'' + msgItem['msgid'] + '\', true)">'
+ '<a class="headerLink" href="/?j=' + msgItem['msgid'] + '">'
+ msgItem['subg'] + '</a>'
+ ' <i class="fa fa-at"></i> <i><a class="headerLink" href="javascript:void(0)" onclick="requestTmpEcho(\'' + msgItem['echo'] + '\')">' + msgItem['echo']
+ '</a></i></p></p>'
@ -334,18 +334,21 @@ function callback(messages) {
}
//show more messages
function showMore(){
console.log("Show more messages, please.");
console.log("Selected echo: " + echo);
console.log("Selected author: " + author);
this_page += 1;
from += show_rows;
if (author != '') {
requestAuthorOffset();
} else if (echo != '') {
requestEchoOffset();
} else {
requestEmptyEchoOffset();
function showMore() {
if (!parseLocationHash().matched && !parseLocation().matched) {
console.log("Show more messages, please.");
console.log("Selected echo: " + echo);
console.log("Selected author: " + author);
this_page += 1;
from += show_rows;
if (author != '') {
requestAuthorOffset();
} else if (echo != '') {
requestEchoOffset();
} else {
requestEmptyEchoOffset();
}
}
}
@ -417,7 +420,7 @@ function showSearch() {
function parseLocationHash() {
var hash = window.location.search.replace(/\?/, "");
if (hash) {
if (hash.match(/(.{20})/)) {
if (hash.match(/(.{20})/) && !hash.match(/.*=.*/)) {
console.log("Matched! " + hash);
return {matched: true, hash: hash};
} else {

133
js/threads.js Normal file
View File

@ -0,0 +1,133 @@
var thread_html = "";
var top_id = "";
$(function() {
var jumpLocation = parseLocation();
// Cleanup content
if (jumpLocation['matched']) {
// Cleanup content
$("#mes").html('');
findTopMessage(jumpLocation["hash"], false);
}
})
function topMessageRequest(data, id) {
$.ajax({
url:"https://dynamic.lessmore.pw/search",
type:"POST",
data: data,
contentType: "application/json",
success: function(messages) {
findTopMessage(id, messages);
// $("#mes").html(thread_html);
// $("#preloader").remove();
}
})
}
function makeDataString(id) {
console.log("ID " + id)
var str = '{"sort": [ { "date": { "order": "desc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["msgid"], "query" :"' + id + '"}}, "size": 1 }';
return str
}
function findTopMessage(id, callback) {
data = makeDataString(id);
if (!callback) {
thread_html = "";
topMessageRequest(data, id);
} else {
if (callback["hits"]["hits"].length > 0) {
repto = callback["hits"]["hits"][0]["_source"]["repto"];
msgid = callback["hits"]["hits"][0]["_source"]["msgid"];
if (repto) {
topMessageRequest(makeDataString(repto));
} else {
thread_html += makeMessageHTML(callback["hits"]["hits"][0]["_source"]);
top_id = msgid;
console.log("Top id found! " + top_id);
proccessThread(msgid);
}
}
}
}
function proccessThreadRequest(data, msgid) {
$.ajax({
url:"https://dynamic.lessmore.pw/search",
type:"POST",
data: data,
contentType: "application/json",
success: function(messages) {
proccessThread(msgid, messages);
$("#mes").html(thread_html);
$("#preloader").remove();
}
})
}
function proccessThread(msgid, callback) {
data = '{"sort": [ { "date": { "order": "asc" }}, { "_score": { "order": "desc" }}], "query": {"query_string" : {"fields" : ["repto"], "query" :"' + msgid + '"}}, "size": 100 }';
if (callback) {
console.log(callback);
for (hit in callback["hits"]["hits"]) {
msg = callback["hits"]["hits"][hit]["_source"];
thread_html += makeMessageHTML(callback["hits"]["hits"][0]["_source"]);
proccessThread(msg["msgid"], false);
}
} else {
console.log(data);
proccessThreadRequest(data, msgid);
}
}
// Parsing functions
function parseLocation() {
var h = location.search.replace(/\?j=/, "");
if (h) {
console.log("Matched jump to " + h);
return {matched: true, hash: h};
} else {
return {matched: false};
}
}
// 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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(new RegExp("\n",'g'), "<br>\n");
var html = '<div class="msg">'
+ '<p align="left"><i class="fa fa-hourglass-half"></i> ' + t_formatted + '<i class="fa fa-angle-right"></i> <!--/p-->'
// Author to receiver
+ '<a name="' + msgItem["msgid"] + '" style="text-decoration:underline; text-decoration-style:dotted;" title="' + msgItem["address"] + '" "href="javascript:void(0)" onclick="requestAuthorMessages(\'' + msgItem['author'] + '\');">' + msgItem['author'] + '</a>'
+ ' <i class="fa fa-mail-forward"></i> ';
if (msgItem['repto'] != "" ) {
html += '<a href="#' + msgItem['repto'] + '">' + msgItem['to'] + '</a></p>';
} else {
html += msgItem['to'] + '</p>';
}
// Header
html += ' <p style="color:#0099cc;font: 1.5em Open Sans, sans-serif;">'
+ '<a class="headerLink" href="/?j=' + msgItem['msgid'] + '">'
+ msgItem['subg'] + '</a>'
+ ' <i class="fa fa-at"></i> <i><a class="headerLink" href="javascript:void(0)" onclick="requestTmpEcho(\'' + msgItem['echo'] + '\')">' + msgItem['echo']
+ '</a></i></p></p>'
+ '<p>' + msg.autoLink()
+ '</p><p align="right">'
// Msgid
+ '<a href="?' + msgItem['msgid'] +'" onclick="requestMessage(\'' + msgItem['msgid'] + '\');"><i class="fa fa-link"></i>' + msgItem['msgid'] + '</a>';
// End message <div> block
html += '</p></div>';
return html
}